我目前正在運行使用PHP HTML表單數據提交到MySQL數據庫基本插入查詢。 不幸的是插入過程沒有運行。 在我的插入語法中,我嘗試過包括$ _POST [fieldname],我嘗試過包括下面的變量,並且我甚至用不同的apostrphes玩過,但似乎沒有任何工作。的MySQL插入到PHP不工作
爲WAMP deprication錯誤的小菜,即時通訊也越來越卡車裝載這是壓倒性的,在php.ini和PHP的apache.ini等文件,還來了香港專業教育學院禁用。
如果任何人都可以建議有什麼不對我的插入和別的ID是多少心存感激。
虐待保持這種介紹straightfoward。 人登錄,如果他們嘗試不登錄就進入登錄頁面登錄。 我連接到數據庫使用外部配置文件,以保存我在50個地方更新時託管其他地方。 配置文件工作正常,所以不顯示在下面。 數據庫被稱爲mydb。 Im將文本字段項存儲到變量中,然後使用插入查詢中的變量。 unitID是一個自動增量字段,所以在運行插入時我留下空白。 不幸的是沒有任何進入mysql數據庫。 在此先感謝。 PS文本字段名都正確地匹配了
<?php
//Start the session
session_start();
//check the user is logged in
if (!(isset($_SESSION['Username']))) {
header ("Location: LoginPage.php?i=1");
exit();
}
//Connect to the database
include 'config.php';
$UserName = $_SESSION['Username'];
$UserIdentification = $_SESSION['UserID'];
if(isset($_GET['i'])){
if($_GET['i'] == '1'){
$tblName="sightings";
//Form Values into store
$loco =$_POST['txtloco'];
$where =$_POST['txtwhere'];
$when =$_POST['txtdate'];
$time =$_POST['txttime'];
$origin =$_POST['txtorigin'];
$dest =$_POST['txtdest'];
$headcode =$_POST['txtheadcode'];
$sql= "INSERT INTO sightings (unitID, Class, Sighted, Date, Time, Origin, Destination, Headcode, UserID) VALUES ('','$loco', '$where', '$when', '$time', '$origin', '$dest', '$headcode', '$UserIdentification')";
mysql_select_db('mydb');
$result=mysql_query($sql, $db);
if($result){
$allocationsuccess = "Save Successful";
header ('Refresh: 2; url= create.php');
}
else {
$allocationsuccess = "The submission failed :(";
}
}
}
?>
[小博](http://bobby-tables.com/)說** [你可能會在對SQL注入攻擊的風險(https://stackoverflow.com/q/60174/)**。通過[參數化查詢](https://stackoverflow.com/a/4712113/5827005)瞭解[準備好的陳述](https://en.wikipedia.org/wiki/Prepared_statement)。我推薦'PDO',我[寫了一個函數](http://paragoncds.com/grumpy/pdoquery/#function),使它非常容易,乾淨,並且比使用非參數化查詢更安全。此外,[本文](http://php.net/manual/en/mysqlinfo.api.choosing.php)可以幫助你MySQLi'和'PDO' – GrumpyCrouton
** **請不要使用之間選擇'新代碼的'mysql_ *'函數。他們不再被維護,社區已經開始[棄用過程](http://news.php.net/php.internals/53799),並且'mysql_ *'函數已經在PHP 7中被正式刪除。相反,你應該瞭解[已準備好的語句](https://en.wikipedia.org/wiki/Prepared_statement)並使用「PDO」或「mysqli_ *」。如果你不能決定,[這篇文章將有助於選擇你最好的選擇](http://php.net/manual/en/mysqlinfo.api.choosing.php)。 – GrumpyCrouton
'depecication錯誤是壓倒性的,ive禁用php.ini和php的apache.ini文件,並仍然出現。嗯我想知道爲什麼這是?也許停止使用折舊功能?你爲什麼會試圖忽略這些錯誤?這是不負責任的。 – GrumpyCrouton