user6538098 user6538098 - 1 year ago 61
PHP Question

How do I update the database values using update statement?

I am trying to update

'company_name', 'company_add', 'price'
as primary key
but it shows me a
'something went wrong'
message along with an
'undefined id'
error. please help me!



$query ="UPDATE login SET company_name=$comname,company_add=$comadd,price=$pri WHERE id=$id";
$result = mysql_query($query);
echo $result;
echo '<script language="javascript">';
echo 'alert("something went Wrong...:("); location.href="edit.php"';
echo '</script>';
echo '<script language="javascript">';
echo 'alert("successfully updated!!!"); location.href="edit.php"';
echo '</script>';

Answer Source

You have to put the character values in single quotes:

$query ="UPDATE login SET company_name='$comname',company_add='$comadd',price=$pri WHERE id=$id";

Stop using deprecated mysql_* API. Use mysqli_* or PDO with prepared Statements. Atleast use the error function, to get the error message.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download