php - 仅更新一条记录的表

标签 php mysql

我有一个问题,我想编辑客户信息,但我只想一次更新一位客户的记录。我尝试添加 _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

您可以检查以下内容:

https://dba.stackexchange.com/a/36748

https://stackoverflow.com/a/15525287/4672534

关于php - 仅更新一条记录的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35881601/

相关文章:

php - "Array_combine"与关联数组

java - Android 使用 UrlConnection 从数据库中删除行

php - 通过表单数据更新mysql保留旧值

使用 GROUP BY 和 ORDER BY 时间戳 DESC 的 MySQL 查询

mysql - 获取 CASE 语句以使用子查询/连接

php - aws.push 到多个环境

php - mysql_query() 期望参数 2 是资源, bool 值给出

mysql - AUTO_INCRMENT 有什么意义?

php - 如何在 PHP 中打印到 Excel 电子表格时替换从 MySQL DB 中提取的某些值?

php - 将mysql数据导出到csv文件