I am trying to create a page where users can edit information.
I can can populate the form with values from an array and update them, however, when it is saved and visited again with different array info it displays the previous form data. I have looked at clearing the cache and setting the array to NULL after the page has been submitted but neither of these have worked!
Here is what i have:
$id = ($_GET['id']);
function get_edit_event_details() {
global $connection;
$query = 'SELECT *
FROM events
WHERE id = "$id"';
$event_details = mysql_query($query, $connection);
confirm_query($event_details);
return $event_details;
echo $query;
}
$event_details = get_event_details();
$details = mysql_fetch_array($event_details);
and to populate the form values (I have also tried autocomplete=”off” which has not worked either)
<input type="text" name="event_date" id="event_date" size="27" value="<?php echo $details["date"];?>" autocomplete="off" />
I am relatively new to PHP and have been able to solve every problem I have come across apart from this one!
I know that maybe this is not a real answer, but I’d like to point out some things:
So, it should be
$id = intval($_GET['id']);How is your ID passing to the function? it’s outside, and not passed as a parameter, nor made global. I believe this could be the issue, as your query will always be without and ID to use as a condition. Try with:
get_edit_event_details($id){}
Personal taste maybe, but using 2 functions and and external call to the return value, just to fetch results it’s a bit smelly. I’d rewrite the whole thing as:
Keep in mind that this is still not perfect code, I know, kinda smell mine too :). You might want to check if $_GET[‘id’] is set also, inside or outside the function.