Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 更新多个字段时更新不推送到数据库_Php_Html_Mysql_Database_Mysqli - Fatal编程技术网

Php 更新多个字段时更新不推送到数据库

Php 更新多个字段时更新不推送到数据库,php,html,mysql,database,mysqli,Php,Html,Mysql,Database,Mysqli,这与我的上一个程序相同,但我使用了更多的表和信息,但这是相同的想法,但当我尝试在这里运行它时,数据不会进入数据库,它会重新加载旧信息,而不是我尝试发送的信息 <?php $page = "login"; $title = "LatinSoft - Login"; include "header.php"; include "config.php"; if (isset($_POST['submit']) && $_POST['submit'] == 'Update')

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

<?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]'");

这里有一个
错误:

.... comp_state = '$_POST[comp_state]', WHERE ....
请删除
,然后重试

.... comp_state = '$_POST[comp_state]' WHERE ....
这就是错误,但不要直接放入$\u POST[xxxx],因为SQL注入等

像这样:

    $email = mysqli_real_escape_string($link, trim($_POST['email']));
    $f_name = mysqli_real_escape_string($link, trim($_POST['f_name']));

    $updateQuery = ("UPDATE `users` SET email = '$email', f_name = '$f_name'.... // and so on...

也许第一个查询失败了?这需要进行基本的调试。您需要使用(还要注意,您的查询容易受到SQL注入的攻击)捕获错误。我知道这是可攻击的,它不用于任何合法的东西,所以我只是测试一下。但是查询并没有失败,因为我在phpmyadmin中运行了相同的sql,并且它工作正常(显然没有使用变量)。永远不要信任查询,因为您在phpmyadmin中运行它。这将是99%的病例的根本原因。进行适当的调试,捕获错误消息。