-6ren">
gpt4 book ai didi

php - mysql/php : Update multiple rows

转载 作者:行者123 更新时间:2023-11-29 21:12:33 27 4
gpt4 key购买 nike

我尝试使用下面的代码来更新多行,下面的代码可以查看行的结果但是无法更新,错误的地方在哪里?如何修改呢?

<?php

$host="localhost"; // Host name
$username="abc"; // Mysql username
$password="abc123"; // Mysql password
$db_name="abc"; // Database name
$tbl_name="BRAddress"; // Table name


// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("Cannot connect");
mysql_select_db("$db_name")or die("Cannot select Database");

$sql="SELECT * FROM $tbl_name WHERE br_no='62779457'";
$result=mysql_query($sql);

// Count table rows
$count=mysql_num_rows($result);
?>

<table width="100%" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<tr>
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">

<tr>
<td align="center"><strong>BR No.</strong></td>
<td align="center"><strong>Date of Register</strong></td>
<td align="center"><strong>Address</strong></td>
</tr>

<?php
while($rows=mysql_fetch_array($result)){
?>

<tr>
<td align="center">
<? $br_no[]=$rows['br_no']; ?><? echo $rows['br_no']; ?>
</td>
<td align="center">
<input name="br_date_of_register[]" type="date" id="br_date_of_register" value="<? echo $rows['br_date_of_register']; ?>">
</td>
<td align="center">
<input name="br_address[]" type="text" size="60" id="br_address" value="<? echo $rows['br_address']; ?>">
</td>
</tr>

<?php
}
?>

<tr>
<td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>

<?php

// Check if button name "Submit" is active, do this
if($Submit){
for($i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET
br_date_of_register='$br_date_of_register[$i]',
br_address='$br_address[$i]'
WHERE br_no='$br_no[$i]'";
$result1=mysql_query($sql1);
}
}

if($result1){
header("location:update_sample.php");
}
mysql_close();
?>

非常感谢您的帮助和支持!

最佳答案

我认为你需要更改这部分

if($Submit){

if($_POST('Submit')){

我还没有运行整个代码或查看整个代码,但从我看来,你没有任何定义 $Submit 变量的内容。

或者你可以输入

$Submit = $_POST('Submit'); 

在 if 语句之前。让我知道你怎么去。干杯

关于php - mysql/php : Update multiple rows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36245371/

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