I'm trying to update a MySQL database with PHP.
Here is my code:
$tableName = "Licenses";
$searchVariable = "used";
$selectVariable = "verCode";
$verTime = date('Y-m-d H:i:s');
$userUUID = "test_string";
$verID = "79A4D";
mysql_connect("localhost", "my_user", "my_pass") or die(mysql_error());
mysql_select_db("licenses_db") or die(mysql_error());
$data = mysql_query("SELECT * FROM `{$tableName}` WHERE `{$searchVariable}`='{$verID}'") or die(mysql_error());
while($info = mysql_fetch_array($data)) {
//Verification ID unused, so verify the user
foreach($info as $key => $value) {
echo "$key: $value</br>";
}
if ($info['used'] == 0) {
echo "<br/>UPDATE `{$tableName}` SET '{$selectVariable}'=1,'time'=`{$verTime}`,'UUID'=`{$userUUID}`; WHERE `{$searchVariable}`='{$verID}'<br/>";
// the above is to see what command is used
mysql_query("UPDATE `{$tableName}` SET '{$selectVariable}'=1,'time'=`{$verTime}`,'UUID'=`{$userUUID}`; WHERE `{$searchVariable}`='{$verID}'");
echo "data updated";
return 'Success';
}
//Verification ID was used already
else {
echo "found but used";
return 'Error Message';
}
}
echo "not found";
return 'Error Message';
However, the database doesn't update. I have the table Licenses created in license_db. In addition, I have one row with the following values:
verCode = 79A4D
used = 0
UUID = NULL
time = NULL
If I run the program the first time, it should update the database. This is printed out:
0: 79A4D
verCode: 79A4D
1:
used:
2:
UUID:
3:
time:
UPDATE `Licenses` SET 'used'=1,'time'=`2014-02-15 19:14:13`,'UUID'=`test_string`; WHERE `verCode`='79A4D'
data updated
When I run it the second time, used is now 1, and so it should print out found but used. However, the data updated section (with the UPDATE ...) is printed out.
So, the database is not updating. How can I solve this? Thanks!
;delimiter ? try removing it any see what is gonna happen..or die(mysql_error());after everymysql_queryyou got, and run so we could see the errors ?