Jump to content


Photo

Updating a SQL row


  • Please log in to reply
4 replies to this topic

#1 DaveLinger

DaveLinger
  • Members
  • PipPipPip
  • Advanced Member
  • 268 posts
  • LocationWV, USA

Posted 12 April 2006 - 12:45 AM

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

$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;
}

http://www.DaveLinger.com
dave at linger dot com

#2 earl_dc10

earl_dc10
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts

Posted 12 April 2006 - 12:49 AM

try this
$sql = "UPDATE $table SET $field_name ='$new_entry' WHERE post_id = '$post_id'

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]
got a problem? Google helps many of those in need

#3 DaveLinger

DaveLinger
  • Members
  • PipPipPip
  • Advanced Member
  • 268 posts
  • LocationWV, USA

Posted 12 April 2006 - 12:58 AM

[!--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) View Post[/div][div class=\'quotemain\'][!--quotec--]
try this
$sql = "UPDATE $table SET $field_name ='$new_entry' WHERE post_id = '$post_id'

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

$query="DROP * FROM areview_news WHERE post_id = '$post_id'";

Need to drop the whole row. Correct syntax?
http://www.DaveLinger.com
dave at linger dot com

#4 earl_dc10

earl_dc10
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts

Posted 12 April 2006 - 01:14 AM

if you are deleting a row do this :
$query = "DELETE FROM $table WHERE $column = '$field_value'";

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 ;)
got a problem? Google helps many of those in need

#5 DaveLinger

DaveLinger
  • Members
  • PipPipPip
  • Advanced Member
  • 268 posts
  • LocationWV, USA

Posted 12 April 2006 - 01:49 AM

[!--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) View Post[/div][div class=\'quotemain\'][!--quotec--]
if you are deleting a row do this :
$query = "DELETE FROM $table WHERE $column = '$field_value'";

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.
http://www.DaveLinger.com
dave at linger dot com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users