简体   繁体   English

SQL更新说成功,但不更新数据库中的表

[英]SQL update saying successful but doesn't update table in database

I'm having an issue with a SQL update query, it says successful but doesn't actually update the database record. 我在使用SQL更新查询时遇到问题,它说成功,但实际上并没有更新数据库记录。

<?php

    require_once('auth.php');

    $host="localhost"; // Host name 
    $username="root"; // Mysql username
    $password="sysadmin"; // Mysql password 
    $db_name="Elite"; // Database name 
    $tbl_name="Triage"; // Table name 

    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");

    $sql="UPDATE Triage SET directly='$directly', psychologically='$psychologically' WHERE Reference='$Reference'";
    $result=mysql_query($sql);
$sql="UPDATE Triage SET directly='$directly', psychologically='$psychologically' WHERE Reference='$Reference'";

none of the variables used in that query have been defined in the code above. 上面的代码中没有定义该查询中使用的变量。 $directly,$psychologically,$Reference : none have a value. $directly,$psychologically,$Reference :没有值。 Define values for those and that's it. 定义这些值就可以了。

That $Reference is a must, even If others aren't. $Reference是必须的,即使其他人不是必须的。

$refrence="1";
$sql="UPDATE Triage SET directly='$directly' AND psychologically='$psychologically' WHERE Reference='$Reference'";

replace $refrence with your MySQL ref 用您的MySQL ref替换$ refrence

Use this syntax 使用此语法

 $sql=  UPDATE Triage SET directly=?, psychologically=? WHERE Reference=?";
 $param->execute(array($directly,$psychologically,$Reference));
 $result=mysql_query($param);

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

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