Jump to content

mySQL query to UPDATE table


XJTRy

Recommended Posts

I am trying to use the below query to update a value in the table. Essentially, I'm asking if the user submitted the correct answer to a question (in this case, "b"). If the user submitted the correct answer he is awarded a point value ($pointValue) in his row's total column.

 

Here is the query:

$data = mysql_query("SELECT choice1 FROM members WHERE user = '$user'");
$info = mysql_fetch_array($data);
if ($info[0] == "b"){
"UPDATE members SET total = '$pointValue' WHERE user = '$user'";
}

 

 

I have used the same query and if statement, but made the conditionals:

 

print "You have chosen the correct answer"

else

print "You have chosen the incorrect answer"

 

and that worked just fine. The data is being added to the array correctly, but the if statement above is not updating the table.

 

Thanks for any help!

Link to comment
https://forums.phpfreaks.com/topic/143856-mysql-query-to-update-table/
Share on other sites

if ($info[0] == "b"){

  "UPDATE members SET total = '$pointValue' WHERE user = '$user'";

  }

 

doesn't do anything, you need to run the query;

 

$query = "UPDATE members SET total = '$pointValue' WHERE user = '$user'";
$result = mysql_query($query) or die(mysql_error());

I have tried that as well.

 

The following still doesn't do the trick:

 

$data = mysql_query("SELECT choice1 FROM members WHERE user = '$user'");
$info = mysql_fetch_row($data);
if ($info[0] == "b"){
$query = "UPDATE members SET total = '$pointValue' WHERE user = '$user'";
$result = mysql_query($query) or die(mysql_error());
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.