我有一个问题,我想编辑客户信息,但我只想一次更新一位客户的记录。我尝试添加 _SESSION['customerCode'] 但似乎不起作用。
<?php
$connection =
mysql_connect("com-db-02.student-cit.local", "team16", "DbSLzU")
or die (mysql_error());
$db = mysql_select_db("team16") or die(mysql_error());
$FName = $_POST['fname'];
$LName = $_POST['lname'];
$Email = $_POST['custemail'];
$Address = $_POST['address'];
$Town = $_POST['town'];
$County = $_POST['county'];
$Eircode = $_POST['eircode'];
$Phone = $_POST['phone'];
$query = mysql_query("UPDATE CUSTOMER set custFName = '$FName', custLName = '$LName', custemail = '$Email' where customerCode = "$_SESSION['customerCode']"") or die(mysql_error());
?>
我收到意外错误“$_SESSION”(T_VARIABLE)
还可以添加而不更新那些空白字段,因此如果客户只想更改其地址,其他字段不会被清除
最佳答案
您的连接有误。让它像这样 .$_SESSION['customerCode']
尝试下面的代码。
session_start();
$custCode = $_SESSION['customerCode'];
$query = mysql_query("UPDATE CUSTOMER set custFName = '$FName', custLName = '$LName', custemail = '$Email' where customerCode = ".$custCode) or die(mysql_error())
Also is it possible to add not update those fields that are blank, so if customer wants to change their address only, other fields won't get wiped out
这个问题之前已经在这里得到了回答。搜索 MySQL COALESCE
您可以检查以下内容:
关于php - 仅更新一条记录的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35881601/