当我手动将sql查询运行到像Navicat这样的sql客户端时,一切都在工作。
当我在PHP中实现它时,有些地方不工作。
update users
set cardnumber=(select number from cards where used='0' LIMIT 1)
where username='whatever'
My PHP Code:
<?php
$con = mysql_connect("localhost","root","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
header('Location: ../error.php');
}
$sql = "update users".
"set cardnumber=(select number from cards where used='0' LIMIT 1)".
"where username='".($_SESSION['username'])."'";
mysql_select_db("bluecard");
mysql_query($sql,$con);
mysql_close($con);
header('Location: nextpage.php');
?>
出什么事了?我找不到它。
[其他工作文件]
<?php
if(! get_magic_quotes_gpc() )
{
$firstname = addslashes ($_POST['first_name']);
$lastname = addslashes ($_POST['last_name']);
$birthday = addslashes ($_POST['datepicker']);
$sex = addslashes ($_POST['sex']);
$region = addslashes ($_POST['region']);
}
else
{
$firstname = $_POST['first_name'];
$lastname = $_POST['last_name'];
$birthday = $_POST['datepicker'];
$sex = $_POST['sex'];
$region = $_POST['region'];
}
$con = mysql_connect("localhost","root","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
header('Location: ../error.php');
}
$curruser1 = $_POST['curruser1'];
$sql = "UPDATE users SET firstname='$firstname', lastname='$lastname', birthday='$birthday', sex='$sex', region='$region', order_date = Now() WHERE username='".($_REQUEST['curruser1'])."'";
mysql_SELECT_db("bluecard");
mysql_query($sql,$con);
mysql_close($con);
header('Location: ../-/order/create_account.php');
?>
您的SQL正在启动:update usersset cardnumber . . .
。你需要一个额外的空间:
$sql = "update users ".
"set cardnumber=(select number from cards where used='0' LIMIT 1) ".
"where username='".($_SESSION['username'])."'";