DaveLinger Posted April 12, 2006 Share Posted April 12, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/7157-updating-a-sql-row/ Share on other sites More sharing options...
earl_dc10 Posted April 12, 2006 Share Posted April 12, 2006 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 Link to comment https://forums.phpfreaks.com/topic/7157-updating-a-sql-row/#findComment-26049 Share on other sites More sharing options...
DaveLinger Posted April 12, 2006 Author Share Posted April 12, 2006 [!--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? Quote Link to comment https://forums.phpfreaks.com/topic/7157-updating-a-sql-row/#findComment-26051 Share on other sites More sharing options...
earl_dc10 Posted April 12, 2006 Share Posted April 12, 2006 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 databasesP.S. double check your row values before deleting, this saved me alot of grief ;) Quote Link to comment https://forums.phpfreaks.com/topic/7157-updating-a-sql-row/#findComment-26059 Share on other sites More sharing options...
DaveLinger Posted April 12, 2006 Author Share Posted April 12, 2006 [!--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 databasesP.S. double check your row values before deleting, this saved me alot of grief ;)[/quote]Thanks a lot Earl. Quote Link to comment https://forums.phpfreaks.com/topic/7157-updating-a-sql-row/#findComment-26061 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.