user6538098 user6538098 - 3 months ago 4x
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>';


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.