I am working on a web app and am having trouble with a trivial issue. I have a table in a database, persons, which consists of the following fields: id, position (in company), username, firstname, lastname. I am working on an edit_user page. I have a main page listing the first+last names of all the users. I can then click on the names and this takes me to the edit_user page corresponding to that user. However, the updates that I make on the website do not get sent to the database (see code below).
//Inserting updates into database
$query = "UPDATE person SET
privilege = '{$privilege}',
nexus = '{$nexus}',
firstname ='{$firstname}',
lastname = '{$lastname}'";
$query .=" WHERE id={$personid}";
$result = mysql_query($query,$connection);
if (mysql_affected_rows() == 1) {
$message = "User was successfully updated";
} else {
$message = "User was not updated";
$message .= "<br/>" .mysql_error();
}
My premonition is that something is wrong with the {$personid}, which was defined by:
function find_selected_user() {
global $user;
if (isset($_GET['personid'])) {
$personid = $_GET['personid'];
return $personid
} else {
$user = NULL;
}
}
(the above function is supposed to return an array of $user's information) Please help -- I am so stuck! I am sure it is so simple but I've been thinking about it too long
You forgot the ending ; character here:
return $personid
Should be:
return $personid;
Can you echo the complete $query
variable to the screen or save it in a log?
Copy this output and try to use mysql command line or phpmyadmin to test the sql query.
Or maybe echo mysql_error();
to see if there is an error being reported.
Maybe your {$personid}
variable isn't being populated how you think it is.