即時通訊新的MySql和PHP和即時通訊嘗試做一個CRUD,但每次我嘗試插入數據到表中稱爲「studenti」我得到的錯誤,我沒有選擇一個數據庫,但我選擇了mysqli_select_db($ con,「d_base」);我GET「沒有數據庫選擇」錯誤,即使選擇了
有人請幫助我,因爲我不明白爲什麼它不幹活的
下面是代碼;
$id = $_POST['ID'];
$nota = $_POST['Nota'];
$emri = $_POST['Emri'];
$mbiemri = $_POST['Mbiemri'];
$servername = "localhost";
$dbname = "d_base";
// 1.Create connection
$con = mysqli_connect("localhost","d_base");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if (!mysqli_query($con,"INSERT INTO studenti (id, nota, emri, mbiemri) VALUES ('$id', '$nota','$emri','$mbiemri')"))
{
echo("Error description: " . mysqli_error($con));
}
// Perform queries
mysqli_select_db($con, "d_base");
mysqli_query($con,"INSERT INTO studenti (id, nota, emri, mbiemri) VALUES ('$id', '$nota','$emri','$mbiemri')");
mysqli_close($con);
你選擇它後* *第一個查詢 –
您的代碼很容易受到SQL注入式攻擊。您應該使用[mysqli](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)或[PDO](http://php.net/manual/en/pdo.prepared- statement.php)按照[本文]中描述的準備語句(http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)。 –
連接後必須選擇它,而不是在連接後選擇的 – clearshot66