" readonly/> "/> "/> "/> "/> "/> "/> 然后我有以下代-6ren">
gpt4 book ai didi

PHP表单更新多个mysql行

转载 作者:行者123 更新时间:2023-11-29 18:13:37 25 4
gpt4 key购买 nike

我有一个用 PHP 创建的表,其中包含需要填充的字段。

这是我的 PHP 表单:

<td><input type="text" name="reg" value="<? echo $rows['reg']; ?>" readonly/></td>
<td><input type="text" name="driver" value="<? echo $rows['driver']; ?>" readonly/></td>
<td><input type="text" name="departure" value="<? echo $rows['departure']; ?>"/></td>
<th><input type="text" name="destination" /></th>
<th><input type="text" name="sleep" /></th>
<th><input type="text" name="date_loaded" value="<? echo $rows['date_loaded']; ?>"/></th>
<th><input type="text" name="arrival_date" value="<? echo $rows['arrival_date']; ?>"/></th>
<th><input type="text" name="client" value="<? echo $rows['client']; ?>"/></th>
<th><input type="text" name="status" value="<? echo $rows['status']; ?>"/></th>
<th><input type="text" name="notes" value="<? echo $rows['notes']; ?>"/></th>

然后我有以下代码将信息更新到MySQL DB

/Post reply drawn 
$client = $_POST['client'];
$reg = $_POST['reg'];
$driver = $_POST['driver'];
$departure = $_POST['departure'];
$destination = $_POST['destination'];
$sleep = $_POST['sleep'];
$date_loaded = $_POST['date_loaded'];
$arrival_date = $_POST['arrival_date'];
$status = $_POST['status'];
$notes = $_POST['notes'];

// Record to MySQL
// database settings

date_default_timezone_set('Africa/Johannesburg');
$today = date("Y-m-d H:i:s");
$date = date("Y-m-d") ;
$time = date("H:i:s");

// Create connection
$conn = new mysqli($host, $username, $password, $db_name);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO verification_hx SET
client = '".$client."',
reg = '".$reg."',
driver = '".$driver."',
departure = '".$departure."',
destination = '".$destination."',
sleep = '".$sleep."',
date_loaded = '".$date_loaded."',
arrival_date = '".$arrival_date."',
status = '".$status."',
notes = '".$notes."'";

if ($conn->query($sql) === TRUE) {
echo "Vehicles has been Updated. ";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
echo("Error description: " . mysqli_error($con));
echo "Error in Case Management Table";
}

$sql1 = "UPDATE verification SET
client = '".$client."',
reg = '".$reg."',
driver = '".$driver."',
departure = '".$departure."',
destination = '".$destination."',
sleep = '".$sleep."',
date_loaded = '".$date_loaded."',
arrival_date = '".$arrival_date."',
status = '".$status."',
notes = '".$notes."'
WHERE reg = .$reg.";

if ($conn->query($sql1) === TRUE) {
echo "";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
echo "Error in Bureau Case File Table";
}

$conn->close();

现在我的问题是它根本不更新表单,并且数据库中记录的新记录只有注册表和驱动程序详细信息,所有其他详细信息均留空

最佳答案

你的问题出在 PHP 方面

"WHERE reg = .$reg.";

应该是

"WHERE reg=\'{$reg}\'";

正如您在 PHP 文档中可能找到的那样,尝试使用 DateTime类而不是日期函数。您还应该在发布项目之前查找 SQL 注入(inject),因为一旦您接受他们不加处理地插入的任何字符串,用户就可以在您的代码中执行此操作。

关于PHP表单更新多个mysql行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47207870/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com