我希望學生能夠計算一些等式,然後將其發送到members
數據庫中的單元格。將數據從html表格插入到MySQL數據庫中
這是我曾嘗試:
<?php
//connect
mysql_connect("localhost", "root", "");
mysql_select_db("members");
//insert
$val3 = $_POST["result"];
$insert_query = "INSERT INTO users (results) VALUES ('$val3')";
$insertion_result = mysql_query($insert_query);
$query = mysql_query($insert_query) or die(mysql_error());
//check whether the data insertion was successful
if(!$insertion_result)
echo "<p>Sorry! Something went wrong.</p>";
else
echo "<p>Thanks! Your form has been processed.</p>";
?>
問題是? –
[**請不要在新代碼中使用'mysql_ *'函數**](http://bit.ly/phpmsql)。他們不再被維護[並且被正式棄用](http://j.mp/XqV7Lp)。看到[**紅框**](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。如果你選擇PDO,[這裏是一個很好的教程](http://j.mp/PoWehJ)。你的代碼有一個嚴重的SQL注入漏洞! –