gpt4 book ai didi

php - 更新多个字段时更新未推送到数据库

转载 作者:行者123 更新时间:2023-11-30 01:26:14 24 4
gpt4 key购买 nike

这与我的上一个程序相同,但我使用了更多的表和信息,但它是相同的想法,但是当我尝试在这里运行它时,数据不会进入数据库,而是会重新加载旧信息我尝试发送的信息。

<?php
$page = "login";
$title = "LatinSoft - Login";

include "header.php";
include "config.php";


if (isset($_POST['submit']) && $_POST['submit'] == 'Update') {

$updateQuery = ("UPDATE `users` SET email = '$_POST[email]', f_name = '$_POST[f_name]',
l_name = '$_POST[l_name]', m_name = '$_POST[m_name]', phone = '$_POST[phone]',
address = '$_POST[address]', city = '$_POST[city]', state = '$_POST[state]',
zip = '$_POST[zip]', rights = '$_POST[rights]', comp_name = '$_POST[comp_name]',
comp_tel = '$_POST[comp_tel]', comp_add = '$_POST[comp_add]',
comp_city = '$_POST[comp_city]', comp_state = '$_POST[comp_state]',
WHERE id = '$_POST[id]'");
//$link defined in config.php
mysqli_query($link, $updateQuery);


};

$query = ("SELECT `ID`, `email`, `f_name`, `l_name`, `m_name`, `phone`, `address`, `city`, `state`, `zip`, `rights`, `comp_name`, `comp_tel`, `comp_add`, `comp_city`, `comp_state` FROM `users`");
$result = mysqli_query($link, $query);

echo "<table width=10% border=0 cellpadding=0 cellspacing=1>

<tr>
<th>Email</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Middle Name</th>
<th>Phone</th>
<th>Address</th>
<th>City</th>
<th>State</th>
<th>Zip</th>
<th>Rights</th>
<th>Company Name</th>
<th>Company Telephone</th>
<th>Company Address</th>
<th>Company City</th>
<th>Company State</th>
</tr>";

while($row = mysqli_fetch_array($result)) {
?>

<form method="post" action="updateuser.php">
<tr>
<td><input type="text" name="email" value="<?php echo $row['email']; ?>"></td>
<td><input type="text" name="f_name" value="<?php echo $row['f_name']; ?>" ></td>
<td><input type="text" name="l_name" value="<?php echo $row['l_name']; ?>" ></td>
<td><input type="text" name="m_name" value="<?php echo $row['m_name']; ?>"></td>
<td><input type="text" name="phone" value="<?php echo $row['phone']; ?>" ></td>
<td><input type="text" name="address" value="<?php echo $row['address']; ?>" ></td>
<td><input type="text" name="city" value="<?php echo $row['city']; ?>" ></td>
<td><input type="text" name="state" value="<?php echo $row['state']; ?>" ></td>
<td><input type="text" name="zip" value="<?php echo $row['zip']; ?>" ></td>
<td><input type="text" name="rights" value="<?php echo $row['rights']; ?>" ></td>
<td><input type="text" name="comp_name" value="<?php echo $row['comp_name']; ?>" ></td>
<td><input type="text" name="comp_tel" value="<?php echo $row['comp_tel']; ?>" ></td>
<td><input type="text" name="comp_add" value="<?php echo $row['comp_add']; ?>" ></td>
<td><input type="text" name="comp_city" value="<?php echo $row['comp_city']; ?>" ></td>
<td><input type="text" name="comp_state" value="<?php echo $row['comp_state']; ?>" ></td>
<td><input type="hidden" name="id" value="<?php echo $row['id']; ?>"></td>
<td><input type="submit" name="submit" value="Update" ></td>
</tr>
</form>

<?php
}
include "footer.php";
?>

最佳答案

查看您的更新查询。

删除 WHERE 之前的 ,

$updateQuery = ("UPDATE `users` SET email = '$_POST[email]', f_name = '$_POST[f_name]', 
l_name = '$_POST[l_name]', m_name = '$_POST[m_name]', phone = '$_POST[phone]',
address = '$_POST[address]', city = '$_POST[city]', state = '$_POST[state]',
zip = '$_POST[zip]', rights = '$_POST[rights]', comp_name = '$_POST[comp_name]',
comp_tel = '$_POST[comp_tel]', comp_add = '$_POST[comp_add]',
comp_city = '$_POST[comp_city]', comp_state = '$_POST[comp_state]'
WHERE id = '$_POST[id]'");

关于php - 更新多个字段时更新未推送到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17957607/

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