2012-09-11 138 views
0

當我運行的代碼我得到的MySQL錯誤(),我得到的錯誤在查詢Execution.Error:問題在執行查詢:PHP/MySQL的登錄系統會給出錯誤的MySQL錯誤:()

insert into kyaami_user_logins set `user_id` = '32', `email` = '[email protected]', `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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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>&nbsp;</td> 
    <td>&nbsp;&nbsp;<strong><a href="index.php?page=forgot_pwd" >Forgot your password?</a></strong></td> 
</tr> 
<tr> 
    <td>&nbsp;</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" />-->&nbsp;&nbsp;<a href="fbconnect.php"><img src="images/fconnect-but.gif" width="89" height="21" border="0"></a> &nbsp;&nbsp;<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> 
+3

'IP =「」' - 你忘了把'''' –

回答

0

應當IP = ''

insert into kyaami_user_logins set `user_id` = '32', `email` = '[email protected]', `ip` = '', `timestamp` = NOW(), `state` = 'success', `active`=1 

ip = ,導致錯誤。如果值爲空,則將其更正爲ip = ''

0

要插入一個空白:

insert into kyaami_user_logins 
    set `user_id` = '32', 
    `email` = '[email protected]', 
    `ip` = , 
    `timestamp` = NOW(), 
    `state` = 'success', 
    `active`=1 

如果要插入一個空值使用此:

insert into kyaami_user_logins 
    set `user_id` = '32', 
    `email` = '[email protected]', 
    `ip` = null, 
    `timestamp` = NOW(), 
    `state` = 'success', 
    `active`=1 

而且,通常插入的語法如下:

insert into kyaami_user_logins 
    (`user_id`, `email`, `ip`, `timestamp`, `state`, `active`) 
    values ('32', '[email protected]', null, NOW(), 'success', 1) 

這個方法將會在對錶進行更改後存活下來,並且實際上可以通過命名該列完全跳過IP部分NS(如果默認設置爲無論如何空)是這樣的:

insert into kyaami_user_logins 
    (`user_id`, `email`, `timestamp`, `state`, `active`) 
    values ('32', '[email protected]', NOW(), 'success', 1) 
+0

我應該在我的桌子上添加一個ip字段? – Daniel

+0

ofcourse ...還沒有添加它......:O – AlphaMale

+1

@Daniel現在我很困惑 - 如果你沒有一個名爲IP的字段,你爲什麼試圖插入它?您只能插入表中存在的列。 – Fluffeh

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' => '[email protected]', ':state' => 'success', ':ip'=>''));