Page 1 of 1

PHP MySQL update problem

Posted: Mon Mar 03, 2008 1:23 pm
by silverball
I have 2 tables in a MySQL database which are

'users' and
'tasks'

The 'users' table has 15 coloumns named 'task_name1' to 'task_name15'.

In the below PHP code, i need to update the information in the 'users' table for each of the columns
but the sql query for update (in the below code) is not working in PHP. Updates are not being inserted to the MySQL database table.


Can anyone help please to fix this problem.

Code: Select all

 
# If the value for a task is equal to "00001", then update the relevant column in the users table to $this_id (which i get from the user)
 
if($task1 == "00001") { mysql_query("UPDATE users SET task_name1 = '$this_id' WHERE id='$id'"); }
 
else if($task2 == "00001") { mysql_query("UPDATE users SET task_name2 = '$this_id' WHERE id='$id'"); }
 
else if($task3 == "00001") { mysql_query("UPDATE users SET task_name3 = '$this_id' WHERE id='$id'"); }
 
else if($task4 == "00001") { mysql_query("UPDATE users SET task_name4 = '$this_id' WHERE id='$id'"); }
 
else if($task5 == "00001") { mysql_query("UPDATE users SET task_name5 = '$this_id' WHERE id='$id'"); }
 
else if($task6 == "00001") { mysql_query("UPDATE users SET task_name6 = '$this_id' WHERE id='$id'"); }
 
else if($task7 == "00001") { mysql_query("UPDATE users SET task_name7 = '$this_id' WHERE id='$id'"); }
 
else if($task8 == "00001") { mysql_query("UPDATE users SET task_name8 = '$this_id' WHERE id='$id'"); }
 
else if($task9 == "00001") { mysql_query("UPDATE users SET task_name9 = '$this_id' WHERE id='$id'"); }
 
else if($task10 == "00001") { mysql_query("UPDATE users SET task_name10 = '$this_id' WHERE id='$id'"); }
 
else if($task11 == "00001") { mysql_query("UPDATE users SET task_name11 = '$this_id' WHERE id='$id'"); }
 
else if($task12 == "00001") { mysql_query("UPDATE users SET task_name12 = '$this_id' WHERE id='$id'"); }
 
else if($task13 == "00001") { mysql_query("UPDATE users SET task_name13 = '$this_id' WHERE id='$id'"); }
 
else if($task14 == "00001") { mysql_query("UPDATE users SET task_name14 = '$this_id' WHERE id='$id'"); }
 
else if($task15 == "00001") { mysql_query("UPDATE users SET task_name15 = '$this_id' WHERE id='$id'"); }

Re: PHP MySQL update problem

Posted: Mon Mar 03, 2008 1:39 pm
by kryles
try

Code: Select all

 
 
mysql_query("your query") or die(mysql_error());
 
 
to get a description of why it failed....or if it is just a blank screen maybe print out the value of $this_id to make sure you're getting a good/expected value. Also check that $id is set properly, because it may be trying to update WHERE $id is not an existing value (so you wouldn't see any change, but get no error message)

Re: PHP MySQL update problem

Posted: Mon Mar 03, 2008 6:55 pm
by RobertGonzalez
How are you setting your $task variables? There might be a better way to do what you are wanting to do.