Jump to content

[SOLVED] Query wont update 3 records...


SirChick

Recommended Posts

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.

Link to comment
Share on other sites

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(); 
}
}

}

Link to comment
Share on other sites

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(); 
}
}

}

Link to comment
Share on other sites

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());
}

}

Link to comment
Share on other sites

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;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.