我有INSERT SQL语句的问题。它什么都不做! (并没有显示任何错误)。 当我打印$ qry时,它看起来很好。 可能是什么问题? 这是代码:
<?php
include('conn.php');
$result=mysql_query("SET NAMES utf8 COLLATE utf8_general_ci",$mysql_link);
$result=mysql_query("SELECT * FROM users where userID=".$_SESSION['IDENT'],$mysql_link);
if (!$result)
{
echo "ERROR: error occured in MySQL query.";
}
else
{
if(mysql_num_rows($result)==1)
{
//This will be shown only to registered users.
while ($row=mysql_fetch_array($result))
{
if (($row['userRank']==100)||($row['userRank']==10))
{
$qry="INSERT INTO users (NickName, username, userpass, userEmail, userRank, userOOlamR, userPhone, userPhone2, userStr, userCity, userMikud, userOOlamID) VALUES ('" . $_POST['nname'] . "', '" . $_POST['username'] . "', '" . md5($_POST['userpass']) . "', '" . $_POST['email'] . "', 2, 1, '" . $_POST['cellphone1'] . "', '" . $_POST['cellphone2'] . "', '" . $_POST['street'] . "', '" . $_POST['city'] . "', " . $_POST['mikud'] . ", " . $_POST['oolam'] . ")";
$res=mysql_query($qry ,$mysql_link);
?><div align="center">
<table width="50%" height="20%" style="Border-Style:dotted;Border-Width:1px;Border-Color:a01220;background-color: rgba(190, 200, 230, 0.5);">
<td><div align="Center"><font face="Arial" size="2" color="Black"> SUCCESS!<br></div></td>
</table>
</div><div align="left">
<?php
echo $qry; ?>
</div><?php
}
Else
{
//SECURITY
}
}
}
}
include('cconn.php');
?>
问题是我在表中有另一个字段,我根本没有在INSERT语句中处理过。
答案 0 :(得分:2)
在你的查询中,错误排在这里..
$ qry =“INSERT INTO用户(NickName,用户名,userpass,userEmail,userRank,userOOlamR,userPhone,userPhone2,userStr,userCity,userMikud,userOOlamID)VALUES('”。$ _POST ['nname']。“' ,'。$。$ _POST ['username']。“','”。md5($ _ POST ['userpass'])。“','”。$ _POST ['email']。“',2,1, '$。$ _POST ['cellphone1']。“','”。$ _POST ['cellphone2']。“','”。$ _POST ['street']。“','”。$ _POST ['city ']。“',”。$ _POST ['mikud']。“,”。$ _POST ['oolam']。“)”;
使用此
$nickname=mysql_real_escape_string($_POST['nname']);
$username=mysql_real_escape_string($_POST['username']);
$userpass=md5(mysql_real_escape_string($_POST['userpass']));
$useremail=mysql_real_escape_string($_POST['email']);
$userrank=2;
$useroolamR=1;
$userphone=mysql_real_escape_string($_POST['cellphone1']);
$userphone2=mysql_real_escape_string($_POST['cellphone2']);
$userstr=mysql_real_escape_string($_POST['street']);
$usercity=mysql_real_escape_string($_POST['city']);
$usermikud=$_POST['mikud'];
$useroolamid=$_POST['oolam'];
$qry="INSERT INTO users (NickName, username, userpass, userEmail, userRank, userOOlamR, userPhone, userPhone2, userStr, userCity, userMikud, userOOlamID) VALUES ('$nickname','$username','$userpass','$useremail', $userrank, $useroolamR,'$userphone','$userphone2','$userstr','$usercity',$usermikud,$useroolamid)";