close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

PHP session being wiped when AJAX call made?

Thread began 3/20/2020 12:18 pm by Nathon Jones Web Design | Last modified 3/20/2020 1:38 pm by Ray Borduin | 13 views | 1 replies |

Nathon Jones Web Design

PHP session being wiped when AJAX call made?

I've got the following PHP session on a page, the session being created based on a POST from a previous page/form.

<?php
@session_start();
if ("" === "") {
$_SESSION["EDITeventID"] = "".((isset($_POST["eID"]))?$_POST["eID"]:"") ."";
}
?>



This loads an event's record from the database. I'm using AJAX also on this page, which displays records from a database as a user types text into a search field, the idea being that the user can change the venue for this event by selecting a matching record.

AJAX displays the results from the database as expected and I've coded on a "Select" form/button so that the user can select one of the returned values. Clicking select reloads the page, but with the new venue's details.

However when the page reloads it wipes the session value so the event data no longer shows and I can only attribute this to the AJAX call.

This is the form...

<input type="text" class="form-control" name="search" id="search" placeholder="Search for venue..." maxlength="50" required>
<div id="display"></div>



This is the AJAX....

<?php

include "db.php";

if (isset($_POST['search'])) {

$Name = $_POST['search'];

$Query = "SELECT TradVenue.venueID, TradVenue.venueNAME, TradVenue.venueCITY, TradVenue.venueREGION, NJcountries.countryNAME FROM TradVenue INNER JOIN NJcountries ON TradVenue.venueCOUNTRY = NJcountries.countryID WHERE venueName LIKE '%$Name%' OR venueCITY LIKE '%$Name%' LIMIT 15";

$ExecQuery = MySQLi_query($con, $Query);

echo '

<ul class="list-unstyled">

';

while ($Result = MySQLi_fetch_array($ExecQuery)) {

?>

<li>

<ul class="list-inline">
<li class="list-inline-item"><?php echo $Result['venueNAME']; ?>, <?php echo $Result['venueCITY']; ?>, <?php echo $Result['countryNAME']; ?></li>
<li class="list-inline-item"><?php echo "<form action='change_venue.php?v=1' method='post' class='form-inline'>"; ?>
<?php echo "<input type='hidden' value='"; ?><?php echo $Result['venueID']; ?><?php echo "' name='vID'>"; ?>
<?php echo "<button type='submit' class='btn btn-sm btn-success mt-2 mb-2' name='BTNsearchvenue'>Select</button>"; ?>
<?php echo "</form>"; ?></li>
</ul>

</li>

<?php

}}

?>

</ul>



Is there something I can add in the AJAX code that will maintain the PHP session value throughout this process?
Thank you.
NJ

Sign in to reply to this post

Ray BorduinWebAssist

Change this:

php:
<?php

@session_start();
if (
"" === "")     {
  
$_SESSION["EDITeventID"] = "".((isset($_POST["eID"]))?$_POST["eID"]:"")  ."";
}
?>



to this:

php:
<?php

@session_start();
if (isset(
$_POST["eID"]))     {
  
$_SESSION["EDITeventID"] = "".((isset($_POST["eID"]))?$_POST["eID"]:"")  ."";
}
?>
Sign in to reply to this post
Did this help? Tips are appreciated...

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...