简体   繁体   English

它不会更新或更改数据库

[英]It doesn't update or change in database

How can I update multiple columns in the table? 如何更新表格中的多列? It doesnt change the data in the database. 它不会更改数据库中的数据。

<?php
$id = $_GET['user'];
$any = mysql_query("SELECT * FROM function WHERE id='".$id ."'");
if ($edit = mysql_fetch_assoc($any)){
?>

//this is the form for the input type when updating the column

<form action="reserve_event.php" method="POST">
    <input type="text" name="fh" value="<?php echo $edit['fh'];?>">
    <input type="text" name="package" value="<?php echo $edit['package'];?>">
    <input type="text" name="guest" value="<?php echo $edit['guest'];?>">
    <input type="text" name="fee" value="<?php echo $edit['fee'];?>">
    <input type="text" name="status" value="<?php echo $edit['status'];?>">
    <input type="submit" name="submit" value="submit">
</form>

//this part is when i submit the data.
<?php
}
if(isset($_POST['submit'])){
    $fh= $_POST["fh"];
    $package= $_POST["package"];
    $guest= $_POST["guest"];
    $fee = $_POST["fee"];
    $status= $_POST["status"];
    $sql1 = mysql_query("UPDATE function SET fh='".$fh."',package= '".$package."', guest = '".$guest."',fee = '".$fee."',status= '".$status."' WHERE id='".$id."'");
}
?>

You can try with blow given code: 您可以尝试使用给定的打击代码:

<?php
if(isset($_POST['submit']))
{
    $fh= $_POST["fh"];
    $package= $_POST["package"];
    $guest= $_POST["guest"];
    $fee = $_POST["fee"];
    $status= $_POST["status"];
    $sql1 = mysql_query("UPDATE `function` SET `fh`='".$fh."',`package`= '".$package."', `guest` = '".$guest."',`fee` = '".$fee."',`status`= '".$status."' WHERE `id`='".$id."'");
}
?>

You are using a reserved word "function" for mysql for your table name, one or your columns name "status" is a reserved word too. 您正在使用mysql的保留字“ function”作为表名,其中一个或您的列名“ status”也是保留字。 This means that mysql server will read function and will try to execute it instead of choosing the table with that name. 这意味着mysql服务器将读取函数并尝试执行该函数,而不是选择具有该名称的表。 IMHO it is better not to use reserved words in table or column definition but you can use backticks ` to escape the names. 恕我直言,最好不要在表或列定义中使用保留字,但可以使用反引号`来转义名称。

This link will provide you a list of reserved words. 该链接将为您提供保留字列表。 So just adapt your query this way: 因此,只需通过以下方式调整您的查询即可:

$sql1 = mysql_query("UPDATE `function` 
SET fh='$fh',package= '$package', guest = '$guest',fee = '$fee', `status`= '$status' 
WHERE id='$id'");

Check with the link I provided you if you have more reserved words in your query 检查我提供的链接,如果您的查询中还有其他保留字

The same applies to the Select query: 选择查询也是如此:

$any = mysql_query("SELECT * FROM `function` WHERE id='$id'");

Also as I mentioned in my comments: your code is open to SQL injections: use prepared statements to sanitize user inputs. 就像我在评论中提到的那样: 您的代码可以进行SQL注入:使用准备好的语句来清理用户输入。 Mysql_* API is deprecated and removed in PHP 7. Move to mysqli or better PDO Mysql_ * API已在PHP 7中弃用并删除。移至mysqli或更好的PDO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM