我的查询将数据插入到记录中,但它也显示查询失败。它将记录插入到数据库中,但不是重定向到压缩页面,而是显示查询失败。
//Create INSERT query
$qry = "INSERT INTO `customer`(`login_id`,`firstname`, `lastname`, `ad1`, `ad2`, `ad3`, `postcode`, `phone`, `email`) VALUES ('{$_SESSION['SESS_LOGIN_ID']}','{$_SESSION['SESS_FIRST_NAME']}','{$_SESSION['SESS_LAST_NAME']}', '$ad1', '$ad2', '$ad3', '$postcode', '$phone', '{$_SESSION['email']}');";
$result = @mysql_query($qry);
//Check whether the query was successful or not
if($result) {
//Create query
$qry="SELECT user.login_id, customer.customer_id, customer.email FROM user, customer
WHERE user.login_id = customer.login_id AND customer.login_id= .'{$_SESSION['SESS_LOGIN_ID']}'.";
$result=mysql_query($qry);
//Check whether the query was successful or not
if($result) {
if(mysql_num_rows($result) == 1) {
//Login Successful
session_regenerate_id();
$login = mysql_fetch_assoc($result);
$_SESSION['SESS_CUSTOMER_ID']= $login['customer_id'];
$_SESSION['SESS_CUSTOMER_EMAIL']= $login['email'];
session_write_close();
header("location: calendar.php");
exit();
}
} else {
die("Query failed");
}
}
答案 0 :(得分:1)
您的INSERT查询成功但后续的SELECT失败,因为它有语法错误。在字符串中使用{}
语法时,请勿使用串联.
字符。
更改为
$qry="SELECT user.login_id, customer.customer_id, customer.email FROM user, customer WHERE user.login_id = customer.login_id AND customer.login_id= '{$_SESSION['SESS_LOGIN_ID']}'";
或者在没有{}
语法的情况下连接:
$qry="SELECT user.login_id, customer.customer_id, customer.email FROM user, customer WHERE user.login_id = customer.login_id AND customer.login_id= '" . $_SESSION['SESS_LOGIN_ID'] . "'";
答案 1 :(得分:0)
如果此查询失败:
$result=mysql_query($qry);
然后是下一行:
if($result) {
将导致使用else
位,即
die("Query failed");
请检查SELECT
声明中的错误。
答案 2 :(得分:0)
你的第二个查询中有一个额外的点:
Here
|
|
v
WHERE user.login_id = customer.login_id AND customer.login_id= .'{$_SESSION['SESS_LOGIN_ID']}'.";
答案 3 :(得分:0)
这里有几点要指出:
mysql_*
函数,因为它们已被弃用。你应该看一下使用mysqli或PDO mysql_insert_id()
$qry="SELECT user.login_id, customer.customer_id, customer.email FROM user, customer WHERE user.login_id = customer.login_id AND customer.login_id= .'{$_SESSION['SESS_LOGIN_ID']}'.";
请注意,您的句点和单引号将字面上包含在字符串中。你应该使用:
$qry="SELECT user.login_id, customer.customer_id, customer.email FROM user, customer
WHERE user.login_id = customer.login_id AND customer.login_id = {$_SESSION['SESS_LOGIN_ID']}";