Jump to content

Update SQL


Solar

Recommended Posts

SQL PHP UPDATE:

$sql="UPDATE blog (name, title, entry, na, ip) SET ('$_POST[name]','$_POST[title]','$_POST[entry]','$_POST[na]','$_POST[ip]')";

 

I need the SQL to read the users name to detect that the edit is there own blog post.

 

SQL PHP PAGE:

$sql = "SELECT id, name, title, entry, na, ip FROM blog WHERE name = '" . $_SESSION['username'] . "' AND `id` = '" . htmlspecialchars($_GET["id"]) . "'";  

ALSO

<form action="profile_blogs_edit.php" method="post">

 

THE ERROR I AM GETTING:

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(title, entry, na, entry, ip) SET id='', name='Steven', 'Macromedia', '
Remem' at line 1

 

 

So is there a way to make this?:

$sql="UPDATE blog (name, title, entry, na, ip) SET ('$_POST[name]','$_POST[title]','$_POST[entry]','$_POST[na]','$_POST[ip]') WHERE name = '" . $_SESSION['username'] . "'";

 

Thanks!

Link to comment
Share on other sites

The following is the syntax definition for an UPDATE query, with the commonly used parts in bold -

UPDATE [LOW_PRIORITY] [iGNORE] table_reference

    SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...

    [WHERE where_condition]

    [ORDER BY ...]

    [LIMIT row_count]

 

Typical usage would be -

 

UPDATE your_table SET your_column1 = 'some value', your_column2 = 'some value' WHERE your_where_condition_goes_here

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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