2013-03-31 33 views
-2

我創建了一個表&當填寫表單後,提交按鈕被擊中時,這些細節應該被插入到數據庫表中。但IDK的什麼是錯的代碼,它呼應「無法選擇表」。我的代碼如下:無法選擇表.. php&mysql

<?php 

if (isset ($_POST['submit'])) 
{ 
mysql_connect("localhost","root","1234"); 
mysql_select_db("my_db")or die("Unable to select database</span></p>"); 

$name1 = $_POST['name1']; 
$email = $_POST['email']; 
$password = $_POST['password']; 
$confirmpassword = $_POST['confirmpassword']; 
$gender = $_POST['gender']; 
$place = $_POST['place']; 
$college = $_POST['college']; 



$result=MYSQL_QUERY("INSERT INTO USERS3 (id,name1,email,password,confirmpassword,gender,college,place)". 
"VALUES ('NULL', '$name1', '$email', '$password', '$confirmpassword', '$gender', '$place', '$college')")or die("<p><span style=\"color: red;\">Unable to select table</span></p>"); 
mysql_close(); 

echo "<p><span style=\"color: red;\">Thank You;</span></p>"; 
} 

else 
{ 
// close php so we can put in our code 
?> 

<form id="form1" action="" method="post"> 
Name: 
<input type="text" name="name1" /><br/> 
E-mail: 
<input type="text" name="email" /><br/> 
Password: 
<input type="password" name="password" /><br/> 
Confirm Password: 
<input type="password" name="confirmpassword" /><br/> 
Gender: 
<input type="radio" name="gender" /> 
Male 
<input type="radio" name="gender" /> 
Female 
<br/> 
Location: 
<input type="text" name="place" /><br/> 
College: 
<input type="text" name="college" /><br/> 
<input id="submit1" class="submit" type="submit" name="submit" value="Submit"/><br/> 
<input type="reset" value="reset" /> 
</form> 

<?php 
} //close the else statement 
?> 
+2

一般建議:使用mysqli或PDO代替棄用的mysql擴展! –

回答

0

PHP無法識別功能以大寫字母。使用小大小寫字符:

mysql_query("INSERT INTO USERS3 (id, name1, email, 
     `password`, confirmpassword, gender, college, place) 
    VALUES ('NULL', '$name1', '$email', 
     '$password', '$confirmpassword', '$gender', '$place', 
     '$college')") or die("<p><span style=\"color: red;\">Unable to select table</span></p>"); 
mysql_close(); 
0

如果「身份證」是一個自動增量字段,你不應該傳遞任何價值了 - 數據庫將面對這一切。

0

一切看起來fine.Only問題(S)可以是:

表名可能是incorrect.Especially,我懷疑你的正確表名是users3而不是USERS3

理想的檢查方法是:以前$結果=

添加以下語句.....

echo "INSERT INTO USERS3 (id,name1,email,password,confirmpassword,gender,college,place)". 
"VALUES ('NULL', '$name1', '$email', '$password', '$confirmpassword', '$gender', '$place', '$college')"; 

運行/負載的頁面。

無論打印 - 複製它

轉到phpMyAdmin的並選擇SQL Tab.Paste您在上一步中複製什麼,並運行它。

phpmyadmin將顯示確切的錯誤。