Jump to content

Archived

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

DaveLinger

Updating a SQL row

Recommended Posts

I do not know the syntax to update an existing SQL row... here's what I have now that's not working...

[code]$sql = "UPDATE WHERE post_id = '$post_id' INTO areview_news
(`Headline`, `Name`, `category`, `Datetime`, `ip`, `Article`)
values
('{$_POST['HeadlineHTML']}', '{$_POST['NameHTML']}', '{$_POST['CategoryHTML']}', '{$_POST['DateHTML']}', '{$_SERVER['REMOTE_ADDR']}', '$Articlenew')";
$result = mysql_query($sql, $link);

if (!$result) {
   echo "DB Error, could not query the database\n";
   echo 'MySQL Error: ' . mysql_error();
   exit;
}[/code]

Share this post


Link to post
Share on other sites
try this
[code]
$sql = "UPDATE $table SET $field_name ='$new_entry' WHERE post_id = '$post_id'
[/code]

more on this at
[a href=\"http://www.w3schools.com/sql/sql_update.asp\" target=\"_blank\"]http://www.w3schools.com/sql/sql_update.asp[/a]

Share this post


Link to post
Share on other sites
[!--quoteo(post=363861:date=Apr 11 2006, 08:49 PM:name=earl_dc10)--][div class=\'quotetop\']QUOTE(earl_dc10 @ Apr 11 2006, 08:49 PM) [snapback]363861[/snapback][/div][div class=\'quotemain\'][!--quotec--]
try this
[code]
$sql = "UPDATE $table SET $field_name ='$new_entry' WHERE post_id = '$post_id'
[/code]

more on this at
[a href=\"http://www.w3schools.com/sql/sql_update.asp\" target=\"_blank\"]http://www.w3schools.com/sql/sql_update.asp[/a]
[/quote]

Thanks!

One more question...

[code]$query="DROP * FROM areview_news WHERE post_id = '$post_id'";[/code]

Need to drop the whole row. Correct syntax?

Share this post


Link to post
Share on other sites
if you are deleting a row do this :
[code]
$query = "DELETE FROM $table WHERE $column = '$field_value'";
[/code]

I believe DROP is used for removing Indexes, and deleting tables and databases

P.S. double check your row values before deleting, this saved me alot of grief ;)

Share this post


Link to post
Share on other sites
[!--quoteo(post=363871:date=Apr 11 2006, 09:14 PM:name=earl_dc10)--][div class=\'quotetop\']QUOTE(earl_dc10 @ Apr 11 2006, 09:14 PM) [snapback]363871[/snapback][/div][div class=\'quotemain\'][!--quotec--]
if you are deleting a row do this :
[code]
$query = "DELETE FROM $table WHERE $column = '$field_value'";
[/code]

I believe DROP is used for removing Indexes, and deleting tables and databases

P.S. double check your row values before deleting, this saved me alot of grief ;)
[/quote]

Thanks a lot Earl.

Share this post


Link to post
Share on other sites

×

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.