无法更新表中的值

发布于 2024-12-20 02:16:30 字数 861 浏览 0 评论 0原文

我可以请求您帮助解决我的代码中的问题吗?我有这个 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";
}

?>

Can i ask for your help with my problem in my code. i have this update_client.php as my function to update the details in my edit.php page.

but as i click on save it doesn't change the value. I wonder where did i go wrong. can somebody please help me with it. I would really appreciate it. Thank

here is the code for my 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";
}

?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

相守太难 2024-12-27 02:16:30
$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 变量的值

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

By the looks of it, you forgot to set value for $id variable

﹉夏雨初晴づ 2024-12-27 02:16:30

您似乎尚未设置 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'";

Seems you haven't set value for 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'";
咋地 2024-12-27 02:16:30

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

You need set value for $id

$name = $_POST['name'];
...
$id = //you need set value for id, ex: $_GET['id'] or $_POST['id'];

If field id in your table is type number, you need do this:

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

Just $id not '$id'.

在巴黎塔顶看东京樱花 2024-12-27 02:16:30

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

Always you have to read your error message. in this script you given Undefined variable id.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文