2016-03-01 115 views
0

我做了一個註冊碼電子郵件,用戶,傳遞,當我點擊「zr」在數據庫中插入此信息,但我得到以下錯誤:PHP,MySQL錯誤:列計數與第1行的值計數不匹配

MySQL error: Column count doesn’t match value count at row 1 

代碼:

include ('config.php'); 
include('login_css.php'); 
$error = ""; 
if (isset($_POST['zr'])){ 
$date = date("m d Y"); 
$user_name = strip_tags($_POST['user']); 
$user_pass = strip_tags($_POST['pass']); 
$user_email = strip_tags($_POST['email']); 
$empty = strip_tags($_POST['none']); 
$empty.= strip_tags($_POST['none']); 
$empty.= strip_tags($_POST['none']); 
$day = strip_tags($_POST['day']); 
$month = strip_tags($_POST['month']); 
$year = strip_tags($_POST['year']); 
$dob = "$day/$month/$year"; 

if ($user_name == "") { 
    $error = "Firstname cannot be left empty."; 
    echo $error; 
} 
else if ($user_pass == "") { 
    $error = "Lastname cannot be left empty."; 
    echo $error; 
} 
else if ($user_email == "") { 
    $error = "Email cannot be left empty."; 
    echo $error; 
} 

//Check the username doesn't already exist 
$check_username = mysql_query("SELECT yser FROM users WHERE username='$user_name'"); 
$numrows_username = mysql_num_rows($check_username); 
if ($numrows_username != 0) { 
    $error = 'That username has already been registered.'; 
    echo $error; 
} 
else 
{ 
    $check_email = mysql_query("SELECT email FROM users WHERE email='$user_email'"); 
$numrows_email = mysql_num_rows($check_email); 
if ($numrows_email != 0) { 
    $error = 'That email has already been registered.'; 
    echo $error; 
} 
else 
{ 
//Register the user 
$register = mysql_query("INSERT INTO users(user,pass,email) VALUES('','$user_name','$user_pass','$user_email','$date')") or die(mysql_error()); 
die('Registered successfully!'); 
} 
} 
} 

?> 

<!-- Form Mixin--> 
<!-- Input Mixin--> 
<!-- Button Mixin--> 
<!-- Pen Title--> 
<div class="pen-title"> 
<title>WebooHub - Join</title> 
    <h1>WebooHub - Join</h1> 
</div> 
<!-- Form Module--> 
<div class="module form-module"> 
    <div class="toggle"><i class="fa fa-times fa-pencil"></i> 
    </div> 
    <div class="form"> 
    <h2>Create Your Account</h2> 
    <form action="u_register" method="POST"> 



     <button>Join Now</button> 
    </form> 
    </div> 
    <div class="cta"><a href="login.php">Login?</a></div> 
</div><strong></strong> 
+5

@FakhruddinUjjainwala我最近注意到你發佈了一個答案和評論。 OP將會看到你的答案,不需要評論。 –

+0

同樣的錯誤:@FakhruddinUjjainwala Ujjainwala警告:mysql_num_rows():提供的參數不是第33行中的C:\ AppServ \ www \ Weboo \ WeboHub \ app \ join \ u_register.php中的有效MySQL結果資源 列數不匹配第1行的值計數 –

+0

[您的腳本存在SQL注入攻擊風險。](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) –

回答

4

錯誤消息告訴你到底出了什麼問題。看看你的INSERT聲明:

INSERT INTO users(user,pass,email) VALUES('','$user_name','$user_pass','$user_email','$date') 

您指定3列,但提供5個值。

INSERT INTO users(user,pass,email) VALUES('$user_name','$user_pass','$user_email') 

或指定的5列,你要插入值:

INSERT INTO users(someColumn,user,pass,email,someOtherColumn) VALUES('','$user_name','$user_pass','$user_email','$date') 

而且,和

要麼你要插入只提供3個值很重要,你的代碼是對SQL注入開放。這意味着你盲目地執行用戶在數據庫查詢中發送給你的任何代碼。請看看this以及this。使用查詢參數準備語句,以便您將用戶輸入視爲而不是代碼


此外,你是在純文本存儲用戶密碼。這是嚴重不負責任的密碼處理。請hash user passwords correctly。用戶密碼應該隱藏在單向散列之後,並且從不可以檢索到,即使您不是系統所有者。

0

退房列VS值:

你有3列和5倍的值。這些需要平等。

$register = mysql_query("INSERT INTO users(user,pass,email) VALUES('','$user_name','$user_pass','$user_email','$date')") or die(mysql_error()); 
die('Registered successfully!'); 

也強烈建議您使用mysqli

+0

警告:mysql_num_rows():提供的參數不是C中有效的MySQL結果資源: \ AppServ \ www \ Weboo \ WeboHub \ app \ join \ u_register.php在第33行 第1行的列計數與值計數不匹配 –

+0

@MeralAhmed這是一個'select query'錯誤'列計數與值不匹配在第1行計數'上面的答案將解決這個問題。 –

相關問題