无法更新表格中的值

时间:2011-12-07 06:49:06

标签: php mysql

我可以在代码中询问您对我的问题的帮助吗?我有这个update_client.php作为我的函数来更新我的edit.php页面中的细节。

但是当我点击保存它不会改变值。我想知道我哪里出错了。有人可以帮帮我吧。我真的很感激。感谢

这是我的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";
}

?>

4 个答案:

答案 0 :(得分:2)

$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变量的值

答案 1 :(得分:0)

似乎您没有为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'";

答案 2 :(得分:0)

您需要设置$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'

答案 3 :(得分:0)

始终您必须阅读错误消息。在此脚本中,您提供了未定义的变量ID。