Jump to content

Updating a SQL row


DaveLinger
 Share

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]
Link to comment
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?
Link to comment
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 ;)
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

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