我正在尝试使用mySql在php中执行多个查询。但我没有得到结果。请让我知道我在代码中做了什么错。我是php和mySql的新手。这是我的PHP代码:
<?php
//-----------------------------------------------------------------------------------
$host='localhost';
$uname='root';
$pwd='welcome';
$db='database name';
//-----------------------------------------------------------------------------------
$con=mysql_connect($host,$uname,$pwd) or die("Connection Failed");
mysql_select_db($db,$con) or die("database selection failed");
//-----------------------------------------------------------------------------------
$mobile = mysql_real_escape_string($_POST['Mobile']); # Secure the input!
$password = mysql_real_escape_string($_POST['Password']);
$time = date("D M d, Y G:i a");
//-----------------------------------------------------------------------------------
// echo $time;
$flag['code']=0;
$select="select * from Insert1 where Mobile = '$mobile' AND Password = '$password'";
$select . ="update table Insert1 set Time='$time' where Mobile='$mobile',Password='$password',Time is null";
$r=mysql_query($select,$con); # This will always return something "true"
if(mysql_num_rows($r) > 0) { # You want to count rows instead.
$flag['code']=1;
}
print(json_encode($flag));
mysql_close($con);
?>
答案 0 :(得分:2)
mysql_query()向与指定link_identifier关联的服务器上的当前活动数据库发送唯一查询(不支持多个查询)。
mysql_query
一次不支持多个查询,您需要为每个查询分别调用它(或者,因为它已经过时并从PHP中删除,a modern replacement for it) STRONG>。
(即使它确实如此,你需要用分号来分隔字符串中的每个查询。)
答案 1 :(得分:-4)
试试这个
$select="select * from Insert1 where Mobile = '$mobile' AND Password = '$password'";
$select.=";";
$select . ="update table Insert1 set Time='$time' where Mobile='$mobile',Password='$password',Time is null";