UPDATE ALL COLUMNS?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
phpretard
Forum Commoner
Posts: 26
Joined: Wed Aug 01, 2007 8:03 pm
Location: Orlando Florida

UPDATE ALL COLUMNS?

Post by phpretard »

I am trying to update every field in the table.

I don't know what to put after "SET" to indicate all columns.

What you see after "SET <<<<<HERE>>> = " is the replacement info coming from a form.

Code: Select all

mysql_connect("localhost","$username","$password");
@mysql_select_db($database) or die( "Unable to select database");

("update name_list set name='$name' where id='$row[id]'");

$query = "UPDATE wanted  SET    <<<<<HERE>>>    = ('$name','$last','$middle','$dob','$alialses','$race','$age','$sex','$height'
,'$weight','$marks','$street','$city','$state','$zip','$make','$model','$summary','$hair','$eyes','$piclink') WHERE id=1";
mysql_query($query);

User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: UPDATE ALL COLUMNS?

Post by Christopher »

The syntax for UPDATE is:

Code: Select all

$query = "UPDATE wanted  SET name='$name',last='$last',middle='$middle',dob='$dob',aliases='$alialses' WHERE id=1";
mysql_query($query);

(#10850)
phpretard
Forum Commoner
Posts: 26
Joined: Wed Aug 01, 2007 8:03 pm
Location: Orlando Florida

Post by phpretard »

Does it have to go in order?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

The order does not matter because they are individual associations. In this way it is different than the INSERT/REPLACE syntax. Although you can use this SET syntax for INSERT/REPLACE with some databases.
(#10850)
phpretard
Forum Commoner
Posts: 26
Joined: Wed Aug 01, 2007 8:03 pm
Location: Orlando Florida

Post by phpretard »

This doesn't work, but it doesn't give me an error.


Code: Select all

$query = "UPDATE wanted SET name='$name',last='$last',middle='$middle',dob='$dob',aliases='$aliases',race='$race',age='$age',
sex='$sex',height='$height',weight='$weight',marks='$marks',street='$street',city='$city',state='$state',zip='$zip',
make='$make',model='$model',summary='$summary',hair='$hair',eyes='$eyes',picklink='$piclink') WHERE id=1";
mysql_query($query);

Any thoughts?

I populated the table with all the same code. The only thing I have changed is what you see.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

phpretard wrote:This doesn't work, but it doesn't give me an error.

Any thoughts?

I populated the table with all the same code. The only thing I have changed is what you see.

Code: Select all

$query = "UPDATE wanted SET name='$name',last='$last',middle='$middle',dob='$dob',aliases='$aliases',race='$race',age='$age',
sex='$sex',height='$height',weight='$weight',marks='$marks',street='$street',city='$city',state='$state',zip='$zip',
make='$make',model='$model',summary='$summary',hair='$hair',eyes='$eyes',picklink='$piclink') WHERE id=1";
mysql_query($query) or die('Mysql Error : <br>' . $query . '<br>' . mysql_error());

Oh?
phpretard
Forum Commoner
Posts: 26
Joined: Wed Aug 01, 2007 8:03 pm
Location: Orlando Florida

Post by phpretard »

Thank you.

(I do have a name to live up to.)
Post Reply