我寫了一個HTML表單填充頁面(sample.html),並且還編寫了一個用於從HTML頁面插入數據的PHP(sample.php)代碼,但我無法收到正確的給我的消息,請解釋其他人!在mySQL數據庫中插入HTML數據
這裏是PHP代碼: -
<?php
$connection = mysql_connect('localhost', 'root','');
if (!$connection){
die("Database Connection Failed" . mysql_error());
}
$select_db = mysql_select_db("selva",$connection);
if (!$select_db){
die("Database Selection Failed" . mysql_error());
}
error_reporting(0);
session_start();
$first_name = $_POST['first_name'];
$father_name = $_POST['father_name'];
$gender = $_POST['gender'];
$date_of_birth = $_POST['date_of_birth'];
$sports = $_POST['sports'];
$mobile = $_POST['mobile'];
$email = $_POST['email'];
if($first_name!='' and $father_name!='' and $gender!='' and $date_of_birth!='' and $sports!='' and $mobile!='' and $email!='') {
$query = mysql_query("insert into register(first_name, father_name, gender, date_of_birth, sports, mobile, email) values('$first_name', '$father_name', '$gender', '$date_of_birth','$sports','$mobile','$email')");
echo "<br/><br/><span>Data Inserted successfully...!!</span>";
} else {
echo "<p>Failed to Insert data <br/> Some Fields are Blank....!!</p>";
}
mysql_close($connection);
?>
請告訴如何從HTML頁面的數據插入到數據庫?
能否請您提供任何錯誤?出了什麼問題。 並提示,請使用MySQLi(如果可能)並清理您的查詢,這是可以注入的地獄;) –
你不應該使用'mysql_'函數。決不。 [這就是爲什麼](http://stackoverflow.com/a/12860046)。 – roberto06
是你在'