Hello,
I want to edit record in mysql and ive got problem with UPDATE command its giving me syntex problem here is the code:

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("dbname", $con);


$sql="UPDATE users SET (userid, firstname, lastname, email, username, password, role) WHERE VALUES('$_POST[userid]','$_POST[firstname]','$_POST[lastname]','$_POST[email]','$_POST[username]','$_POST[password]','$_POST[role]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record edited";
header("Location: wyswietl.php");

mysql_close($con);
?>

Ive got form that i click to edit and when i want to update it ive got the error and here is the submit for if its going to be of any help:

echo $search_results .= "
<tr align=center bgcolor=Silver>
<th><font face=\"Tahoma\" size=\"1\">$row[userid]</b></font></th>
<th><font face=\"Tahoma\" size=\"1\">$row[firstname]</b></font></th>
<th><font face=\"Tahoma\" size=\"1\">$row[lastname]</b></font></th>
<th><font face=\"Tahoma\" size=\"1\">$row[email]</b></font></th>
<th><font face=\"Tahoma\" size=\"1\">$row[username]</b></font></th>
<th><font face=\"Tahoma\" size=\"1\">$row[password]</b></font></th>
<th><font face=\"Tahoma\" size=\"1\">$row[role]</b></font></th>
</font></td>
</tr>";

echo $search_results .= "<form action='update/update_user.php' method='post'>

ID: <input type='text' name='userid' size='50' value='$row[userid]'><br>
Imie: <input type='text' name='firstname' size='50' value='$row[firstname]'><br>
Nazwisko: <input type='text' name='lastname' size='50' value='$row[lastname]'><br>
Email: <input type='text' name='email' size='50' value='$row[email]'><br>
Nazwa Uzytkownika: <input type='text' name='username' size='50' value='$row[username]'><br>
Haslo: <input type='text' name='password' size='50' value='$row[password]'><br>
Uprawnienia: <input type='text' name='role' size='50' value='$row[role]'><br>


<input type='Submit'>

Thanks for help =]

Recommended Answers

All 9 Replies

You UPDATE query is wrong, you wrote:

UPDATE table SET() WHERE VALUES();

Change it to:

UPDATE users
SET userid = '$_POST[userid]',
firstname = '$_POST[firstname]',
lastname = '$_POST[lastname]',
email = '$_POST[email]',
username = '$_POST[username]',
password = '$_POST[password]',
role = '$_POST[role]')
WHERE condition = 'value';

Check this for more info: http://dev.mysql.com/doc/refman/5.5/en/update.html
And remember to sanitize data.

Hello,
I've done it like that:

$sql="UPDATE users SET userid = ('$_POST[userid]',firstname = '$_POST[firstname]',lastname = '$_POST[lastname]',email = '$_POST[email]',username = '$_POST[username]',password = '$_POST[password]',role = '$_POST[role]') WHERE condition = 'value'";

and ive got still problem probobly with ""

Try this:

$sql="UPDATE users SET 
        userid = '$_POST[userid]',
        firstname = '$_POST[firstname]',
        lastname = '$_POST[lastname]',
        email = '$_POST[email]',
        username = '$_POST[username]',
        password = '$_POST[password]',
        role = '$_POST[role]'
        WHERE condition = 'value'";

Remove those parentheses after userid = and before WHERE.

Hello,
got all the time =/

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 'condition = 'value'' at line 9

condition = 'value' is just an example, you have to choose your condition for the WHERE statement, for example, basing on your table write: userid = '$_POST[id]'

Hello,
okay every thing works like a charm thanks for help and sorry for the newbie behavior, have a nice day =]

No problem, change $_GET['userid'] to $_POST['userid'] and it should work. As in my previous post (I edited that post changing $_GET with $_POST after I checked your previous script).

Hello,
yeah i noticed that and change it thanks a lot man you where a gr8 help =]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.