Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Can';t更新我的表中的值_Php_Mysql - Fatal编程技术网

Php Can';t更新我的表中的值

Php Can';t更新我的表中的值,php,mysql,Php,Mysql,我可以请你帮我解决代码中的问题吗。我有这个update_client.php函数来更新edit.php页面中的详细信息 但当我点击save时,它不会改变值。我不知道我哪里出错了。谁能帮我一下吗。我会非常感激的。谢谢 下面是我的update_client.php的代码 <?php session_start(); if (!isset($_SESSION['user'])){ header("location:../efeedback/login2.php"); } requir

我可以请你帮我解决代码中的问题吗。我有这个update_client.php函数来更新edit.php页面中的详细信息

但当我点击save时,它不会改变值。我不知道我哪里出错了。谁能帮我一下吗。我会非常感激的。谢谢

下面是我的update_client.php的代码

<?php
session_start();
if (!isset($_SESSION['user'])){
    header("location:../efeedback/login2.php"); 

}
require_once "connect_to_mysql.php"; 

$name = $_POST['name'];
$company = $_POST['company'];
$email = $_POST['email'];
$client_user = $_POST['client_user'];
$client_pass = $_POST['client_pass'];
$initials = $_POST['initials'];

$sql="UPDATE client_users SET name = '$name', company = '$company', email = '$email', client_user = '$client_user', client_pass = '$client_pass', initials = '$initials' WHERE id = '$id'";
$result=mysql_query($sql);

// if successfully updated.
if($result){

header("location:add_client.php");
}

else {
echo "ERROR";
}

?>


从外观上看,您忘了为$id变量设置值

似乎您还没有为
id

$sql="UPDATE client_users SET name = '$name', company = '$company', email = '$email', client_user = '$client_user', client_pass = '$client_pass', initials = '$initials' WHERE id = '$id'";

您需要为
$id

$name = $_POST['name'];
...
$id = //you need set value for id, ex: $_GET['id'] or $_POST['id'];
如果表中的字段
id
是类型编号,则需要执行以下操作:

$sql="UPDATE client_users SET name = '$name', company = '$company', email = '$email', client_user = '$client_user', client_pass = '$client_pass', initials = '$initials' WHERE id = $id";

只是
$id
而不是
'$id'

您必须始终阅读错误消息。在这个脚本中,您给出了未定义的变量id。

您在哪里给出了id的值??Darvex似乎是正确的,而且您非常容易受到sql注入攻击我为id设置了值,$id=$\u POST['id'];但我仍然没有在保存后更改值。您确定变量
$id
设置了正确的值吗?您可以通过
检查$\u POST值,感谢它现在可以工作,我将“$id”更改为$id。嗯,它确实更改了,但在我返回五月客户列表页面时不会自动更改,我仍然需要刷新页面几次。。你知道这是什么原因吗?嗯。。。我不太确定,但是如果成功地更新了,并且您的代码
标题(“location:add_client.php”)工作很好,我想一切都会好的。
$sql="UPDATE client_users SET name = '$name', company = '$company', email = '$email', client_user = '$client_user', client_pass = '$client_pass', initials = '$initials' WHERE id = $id";