I have a script which runs when a user hits the ‘reject’ button on some terms.
When it runs it should revoke the access rights to the particular area, for some reason the script doesn’t work- as in it doesn’t update the MYSQL DB nor do I get die error.
$username = $_SESSION["USER"]["Username"];
mysql_connect("x", "y", "z") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
mysql_query("UPDATE `users` SET `SeceretArea`='Unauth' WHERE `Username`='$username'") or die(mysql_error());
ANSWER UPDATED TO SUM UP DEBUGGING PROCESS.
If there is no error, then there are three possibilities as to why the database entry isn’t happening:
USERNAMEcolumn is equal to$database.$database.$database, but that value isn’t being replaced into the query.From my personal experience,
mysql_query()doesn’t necessarily substitute variable values in before executing the query. Create the query string first into a variable, then pass it tomysql_query(). Your current setup doesn’t replace$usernamewith its value. What you can do is this:Apart from that, check your table to make sure that there is a row with the value you want in
USERNAME.var_dump()your$usernameto see if it’s the value that you intended.Also, you really should consider switching to either
mysqliorPDO. If you don’t want to migrate to an object module, you can usemysqli‘s procedural functions.