我正在嘗試將數據保存到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