SirChick Posted October 21, 2007 Share Posted October 21, 2007 I have a update query in this script below : $get_users = mysql_query("SELECT * FROM userregistration WHERE CountryID='1' AND IllnessType='0'"); if (!$get_users) die("Error: " . mysql_error()); //Loop through all the records while($user = mysql_fetch_array($get_users)) { //Do something which has a 20% chance of succeeding. //Choose a random number between 1 and 5 $rand = rand(1,1); //If the number is 3 (which there is a 20% chance of it being) update the user if($rand == 1) { if (($q = mysql_query("UPDATE userregistration SET IllnessType='Winter Flu' And TimeOfIllness='$Date' WHERE CountryID='1'")) != FALSE) print "update successful...<br>"; else print mysql_error(); } } but it just won't do it for the life of it ...there is deffinately 3 records as the update succesful echo's 3 times but in my database the fields are not updating to the queries input :S why could this be ? before you ask..i put rand to 100% to test it. Quote Link to comment Share on other sites More sharing options...
papaface Posted October 21, 2007 Share Posted October 21, 2007 try: $get_users = mysql_query("SELECT * FROM userregistration WHERE CountryID='1' AND IllnessType='0'"); if (!$get_users) die("Error: " . mysql_error()); //Loop through all the records while($user = mysql_fetch_array($get_users)) { //Do something which has a 20% chance of succeeding. //Choose a random number between 1 and 5 $rand = rand(1,1); //If the number is 3 (which there is a 20% chance of it being) update the user if($rand == 1) { $q = mysql_query("UPDATE userregistration SET IllnessType='Winter Flu' And TimeOfIllness='$Date' WHERE CountryID='1'"); if ($q) { print "update successful...<br>"; } else { print mysql_error(); } } } Quote Link to comment Share on other sites More sharing options...
SirChick Posted October 21, 2007 Author Share Posted October 21, 2007 update successful update successful update successful thats the result.. but in my database IllnessType and TimeOfIllness still are "0" and "0000-00-00 00:00:00" on all 3 records. Quote Link to comment Share on other sites More sharing options...
dbo Posted October 21, 2007 Share Posted October 21, 2007 What are the datatypes for the fields that aren't updating? Quote Link to comment Share on other sites More sharing options...
SirChick Posted October 22, 2007 Author Share Posted October 22, 2007 IllnessType - VarChar i tried Text also but no such luck.. TimeOfIllness - timestamp encase you wondered what $Date is: $Date = date("Y-m-d H:i:s",time()); Quote Link to comment Share on other sites More sharing options...
SirChick Posted October 22, 2007 Author Share Posted October 22, 2007 Just to add.. i found one problem i had AND in my query which i changed to a , symbol..... though it fixed it and worked it then decided to stop working again for different unknown reasons... now the ending echo's neither of them echo so its not succesful or an error: $get_users = mysql_query("SELECT * FROM userregistration WHERE CountryID='1' AND IllnessType='0'"); if (!$get_users) die("Error: " . mysql_error()); //Loop through all the records while($user = mysql_fetch_array($get_users)) { //Do something which has a 20% chance of succeeding. //Choose a random number between 1 and 5 $rand = rand(1,5); //If the number is 3 (which there is a 20% chance of it being) update the user if($rand == 3) { $Date = date("Y-m-d H:i:s",time()); $q = mysql_query("UPDATE userregistration SET IllnessType='Winter Flu', TimeOfIllness='$Date' WHERE CountryID='1'"); if ($q) { print "update successful...<br>"; } else { print mysql_error(); } } } Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted October 22, 2007 Share Posted October 22, 2007 do use if($q) use $r = mysql_query($q) or die(mysql_error()); also try echoing out the queries to see if they look right. Quote Link to comment Share on other sites More sharing options...
SirChick Posted October 22, 2007 Author Share Posted October 22, 2007 the query when echo'd looked fine but i dont get how it did work but now it isn't even though i aint altered it ... Current code: $get_users = mysql_query("SELECT * FROM userregistration WHERE CountryID='1' AND IllnessType='0'"); if (!$get_users) die("Error: " . mysql_error()); //Loop through all the records while($user = mysql_fetch_array($get_users)) { //Do something which has a 20% chance of succeeding. //Choose a random number between 1 and 5 $rand = rand(1,5); //If the number is 3 (which there is a 20% chance of it being) update the user if($rand == 3) { $Date = date("Y-m-d H:i:s",time()); $q = mysql_query("UPDATE userregistration SET IllnessType='Winter Flu', TimeOfIllness='$Date' WHERE CountryID='1'"); $r = mysql_query($q) or die(mysql_error()); } } Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted October 22, 2007 Share Posted October 22, 2007 can I see the outputted queries/ or mysql errors if any Quote Link to comment Share on other sites More sharing options...
SirChick Posted October 22, 2007 Author Share Posted October 22, 2007 Just echo'd it and this came out: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1 This is the script at the moment: $get_users = mysql_query("SELECT * FROM userregistration WHERE CountryID='1' AND IllnessType='0'"); if (!$get_users) die("Error: " . mysql_error()); //Loop through all the records while($user = mysql_fetch_array($get_users)) { //Do something which has a 20% chance of succeeding. //Choose a random number between 1 and 5 $rand = rand(1,5); //If the number is 3 (which there is a 20% chance of it being) update the user if($rand == 3) { $Date = date("Y-m-d H:i:s",time()); $q = mysql_query("UPDATE userregistration SET IllnessType='Winter Flu', TimeOfIllness='$Date' WHERE CountryID='1'"); $r = mysql_query($q) or die(mysql_error()); } echo $q; } Quote Link to comment Share on other sites More sharing options...
only one Posted October 22, 2007 Share Posted October 22, 2007 You are setting two mysql_quers in variables, so it is not actually running any query: mysql_query("UPDATE userregistration SET IllnessType='Winter Flu', TimeOfIllness='$Date' WHERE CountryID='1'") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.