0

这是我的代码。

if(!isset($_SESSION['user'])) header("Location: ../");
$username = $_SESSION["user"];
$id = $_SESSION["id"];

$nume=$_POST["nume"];
$prenume=$_POST["prenume"];
$telefon=$_POST["telefon"];
$email=$_POST["email"];
$adresa=$_POST["adresa"];
$ziNastere=$_POST["ziNastere"];
$poza=$_POST["poza"];

include('../conn2.php');

mysql_query("UPDATE $username SET nume=$nume,prenume=$prenume,telefon=$telefon,email=$email,adresa=$adresa,ziNastere=$ziNastere,poza=$poza
WHERE id=$id");

mysql_select_db($username);
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";

if(isset($_SESSION['id']))  unset($_SESSION['id']);
//header("Location: ../home");
mysql_close($con);
?>

我想用字符串更新数据库“$username”:$nume、$prenume、$telefon...但是当我单击保存时它返回"Error: Query was empty"- 为什么会这样?

4

1 回答 1

2

你还没有定义可验证的 $sql

  $sql = "UPDATE $username SET nume=$nume,prenume=$prenume,telefon=$telefon,email=$email,adresa=$adresa,ziNastere=$ziNastere,poza=$poza
    WHERE id=$id"
mysql_select_db($username);
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";

if(isset($_SESSION['id']))  unset($_SESSION['id']);
//header("Location: ../home");
mysql_close($con);
?>
于 2012-08-05T07:55:07.507 回答