Help updating a database with php?

  • Thread starter Thread starter Useless information
  • Start date Start date
U

Useless information

Guest
when i update a row do i need to include all the columns in that update example: i have a table with columns id name and number can i just use

$values =3,4,5,8;

mysql_query("UPDATE table_name SET values= ".$values." WHERE id= 1")

i keep getting an error and im not sure if its because i have commas in the values or because of the fact im not updating everything.
its not a problem with quotes
 
mysql_query("UPDATE table_name SET values= '".$values."' WHERE id= 1")

It's hard to see, but I've added single quotes around the $values, inside of the double-quotes.
 
your syntax is wrong

$query = mysql_query("UPDATE table_name SET values='$values' WHERE id='1'");
and if you want to update multiple fields
$query = mysql_query("UPDATE table_name SET values='$values' ,something='$something' WHERE id='1'");
 
$values = 3,4,5,8; is NOT a valid PHP assignment statement.

if you want $values to contain a number, you should have:
$values = 3;

if you want $values to contain an array, use
$values=Array(3,4,5,8);

The field 'values' you are trying to updated in your database, what type is it? Is it a string? An integer? Do you want it to have the value "3,4,5,8" as a string containing numbers separated by commas? Do you want it to be a single value?

If you want to update multiple columns then you should specify each column name:
UPDATE table_name SET column1=xxx, column2=xxx WHERE id=1
 
Back
Top