-2

我创建了一个表格,当填写表格后点击提交按钮时,这些详细信息应插入 DB TABLE。但是我知道代码有什么问题,它正在回显“无法选择表”。我的代码如下:

<?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
?>
4

3 回答 3

0

如果 'id' 是一个自动增量字段,你不应该为它传递任何值——数据库会处理它。

于 2013-03-31T17:15:45.463 回答
0

一切看起来都很好。唯一的问题可能是:

表名可能不正确。特别是,我怀疑您正确的表名users3不是 USERS3.

理想的检查方法是:

在$result=之前添加以下语句......

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

运行/加载页面。

无论是打印的 -复制它

转到phpmyadmin并选择SQL Tab。粘贴您在上一步中复制的内容并运行它。

phpmyadmin 将显示确切的错误。

于 2013-03-31T17:17:04.140 回答
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();
于 2013-03-31T17:13:29.780 回答