我正在尝试将数据保存到sql数据库的注册表单。我还没有进行表单验证,因为最让我感到困扰的是将这些东西放到sql上。我会很感激任何建议!PHP SQL注册表格
我有一个form.php文件,应该在努力工作。当我提交我的表单时,在这一点上,我得到一个空白屏幕,并没有加载到数据库中。
<?php
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$password = $_POST['password'];
$email = $_POST['email'];
$cell = $_POST['cell'];
$experience = $_POST['experience'];
$ip = $_POST['ip'];
$password = md5($_POST['password']);
$connection = msql_connect(localhost, USERNAME, PASSWORD);
$db = mysql_select_db(registration,$connection);
mysql_query("INSERT INTO userTable (fname,lname,password,email,cell,experience,ip) VALUES ('$fname', '$lname', '$password', '$email', '$cell', '$experience', '$ip')")
or die (mysql_error());
echo "Thank you for your registration";
?>
而且我有一个包含这个HTML文件:
<form method = "post" action = "form.php">
<h2>User Information</h2>
<div><label>First Name:</label>
<input type = "text" name = "fname"></div>
<div><label>Last Name:</label>
<input type = "text" name = "lname"></div>
<div><label>Password:</label>
<input type = "password" name = "password"></div>
<div><label>Email:</label>
<input type="text" name="email"></div>
<div><label>Cellphone:</label>
<input type="text" name="cell"></div>
<input type="hidden" name="ip" value='<?php echo $IP ?>'/>
<h2>What Is Your Experience Mountain Biking?</h2>
<p><input type="radio" name="experience" value="n00b"
checked>n00b
<input type="radio" name="experience" value="intermediate">Intermediate
<input type="radio" name="experience" value="extreme">Extreme
</p>
<p><input type="submit" name="submit" value="Register"></p>
</form>
最后,我有一个SQL数据库(我在本地运行的XAMPP)被称为“注册” 我创建的表被称为“userTable”,它包含8个字段,包括ID(自动递增)和其他7个我已经包含在顶部的值。任何想法我做错了什么?
为什么这么多的问题仍然指向'mysql_'功能?你为什么不使用'mysqli_'函数?还有'$ connection = msql_connect(localhost,USERNAME,PASSWORD);'是一个错字。没有'msql_connect()'函数。更不用说sql注入攻击了! – 2012-08-03 00:29:32
死亡白屏=错误显示关闭。打开它,看看你得到了什么 – 2012-08-03 00:30:08
我建议添加error_reporting(E_ALL);到脚本的顶部以确保报告所有错误和问题。一旦完成,我们可以进一步了解为什么事情没有起作用。 – 2012-08-03 00:31:56