当我运行代码时,我得到mysql error(),我在Query Execution.Error中遇到错误:执行查询时出现问题:
insert into kyaami_user_logins set `user_id` = '32', `email` = 'test@test2.com', `ip` = , `timestamp` = NOW(), `state` = 'success', `active`=1
MySQL错误:()
<?php
if ( isset( $_GET['msg'] ) )
{
if ( $_GET['msg'] == 1 )
echo "Invalid User. Try Again.";
if ( $_GET['msg'] == 2 )
echo "Account Activated Successfully.";
if ( $_GET['msg'] == 3 )
echo "Your Account is Locked. contact Administrator.";
if ( $_REQUEST['msg'] == 4 )
echo "Mail has been sent to your email address.";
if ( $_REQUEST['msg'] == 5 )
echo "Your Account is already activated, Login Here";
if ( $_REQUEST['msg'] == 6 )
echo "Your Activation link has been expired, please register again";
}
?>
</span></td>
</tr>
<tr>
<td width="70" align="right" valign="top"><p class="form_text" style="color:#FFF;" align="right"><strong> Email</strong></p></td>
<td width="410"><div class="form_input_BG"><input type="text" name="username" id="username" value=""/></div></td>
</tr>
<tr>
<td valign="top"><p class="form_text" style="margin-left:8px; color:#FFF;"><strong>Password</strong></p></td>
<td align="left"><div class="form_input_BG"><input type="password" name="pwd" id="pwd" value=""/></div>
</td>
</tr>
<tr>
<td> </td>
<td> <strong><a href="index.php?page=forgot_pwd" >Forgot your password?</a></strong></td>
</tr>
<tr>
<td> </td>
<td><div class="form_login_signup_btn">
<input title="login Now" type="image" src="images/login_btn.png" name="formSubmit" id="login" width="104" height="33" /> <!--<input type="image" src="images/signup_btn.png" title="Signup Now" name="signup" id="signup" />--> <a href="fbconnect.php"><img src="images/fconnect-but.gif" width="89" height="21" border="0"></a> <a href="twit_redirect.php"><img src="images/sign-in-with-twitter.png" width="151" height="24" alt="Sign in with Twitter" border="0" /></a>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="clr"></div></div>
<div class="clr"></div>
</div>
</form>
答案 0 :(得分:0)
应该 ip =''
insert into kyaami_user_logins set `user_id` = '32', `email` = 'test@test2.com', `ip` = '', `timestamp` = NOW(), `state` = 'success', `active`=1
ip = ,
导致错误。如果值为空,则将其更正为ip = ''
。
答案 1 :(得分:0)
您正在插入空白:
insert into kyaami_user_logins
set `user_id` = '32',
`email` = 'test@test2.com',
`ip` = ,
`timestamp` = NOW(),
`state` = 'success',
`active`=1
如果要插入空值,请使用:
insert into kyaami_user_logins
set `user_id` = '32',
`email` = 'test@test2.com',
`ip` = null,
`timestamp` = NOW(),
`state` = 'success',
`active`=1
此外,通常插入语法具有以下语法:
insert into kyaami_user_logins
(`user_id`, `email`, `ip`, `timestamp`, `state`, `active`)
values ('32', 'test@test2.com', null, NOW(), 'success', 1)
此方法将在更改表后继续存在,您实际上可以通过命名列(如果默认设置为null无论如何)完全跳过IP部分,如下所示:
insert into kyaami_user_logins
(`user_id`, `email`, `timestamp`, `state`, `active`)
values ('32', 'test@test2.com', NOW(), 'success', 1)
答案 2 :(得分:0)
为避免此类错误,请尝试将代码更改为PDO:
$db = new PDO('mysql:host=localhost;dbname=testdb;charset=UTF-8', 'username', 'password', array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$stmt = $db->prepare("INSERT INTO `kyaami_user_logins`(`user_id`, `email`, `timestamp`, `state`, `active`, `ip`) VALUES (:user_id, :email, NOW(), :state, 1, :ip)");
$stmt->execute(array(':user_id' => 32, ':email' => 'test@test2.com', ':state' => 'success', ':ip'=>''));