简体   繁体   中英

update query with php mysql is not updating the database table entries

<?php
include 'dbConfig.php';
$address=mysql_real_escape_string($_POST['address']);
$pincode=mysql_real_escape_string($_POST['pincode']);
$phone=mysql_real_escape_string($_POST['phone']);
$email=mysql_real_escape_string($_POST['contactemail']);
$id=1;
$sql="UPDATE contactus SET address = '$address' , pincode = '$pincode' , phone = '$phone' , email = '$email' WEHER id='$id'";
$result=mysql_query($sql);
if (!$result)
{
    die('Error: '. mysqli_error());

}

it gives answer like this:-

DB initiated
Error:

What is the problem..?

Use a correct mysqli syntax. here an example

<?php
$con=mysqli_connect("example.com","peter","abc123","my_db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

mysqli_query($con,"UPDATE Persons SET Age=36
WHERE FirstName='Peter' AND LastName='Griffin'");

mysqli_close($con);
?>

source: http://www.w3schools.com/php/php_mysql_update.asp

And fix you query

 WEHER id='$id'";

by

WHERE id='$id'"
$sql="UPDATE contactus SET address = '$address' , pincode = '$pincode' , phone = '$phone' , email = '$email' WEHER id='$id'";
$result=mysql_query($sql);
if (!$result)
{
    die('Error: '. mysqli_error());

}

should be

$sql="UPDATE contactus SET address = '$address' , pincode = '$pincode' , phone = '$phone' , email = '$email' WHERE id='$id'";
$result=mysql_query($sql);
if (!$result)
{
    die('Error: '. mysql_error());

}

The WHERE is spelt incorrectly as WEHER :

Try this

$sql="UPDATE contactus SET address = '$address' , pincode = '$pincode' , phone = '$phone' , email = '$email' WHERE id='$id'";

Are you passing the "link identifier" parameter in mysql_query function?

resource mysql_query ( string $query [, resource $link_identifier = NULL ] )

i know is not mandatory, but you are executing query with mysql_query, getting the error with mysqli, dbconfig we cannot see it. So is difficult to guess.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM