-4
我看不到問題。我的數據都不會插入到註冊數據庫中。請檢查INSERT INTO部分。我是編碼方面的初學者,所以我不知道這些東西。請幫幫我。爲什麼我的數據沒有插入數據庫表中?
<?php
**my info is here**
//Connect to database
mysql_connect ($dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
?>
<?php
if(isset($_POST['submit'])){
$username = $_POST[user];
$password = $_POST[pass];
// lets check to see if the username already exists
$checkuser = mysql_query("SELECT username FROM register WHERE username='$username'");
$username_exist = mysql_num_rows($checkuser);
if($username_exist > 0){
echo "I'm sorry but the username you specified has already been taken.Please pick another one.";
unset($username);
exit();
}
// lf no errors present with the username
// use a query to insert the data into the database.
$query = ("INSERT INTO register (username, password)
VALUES ('$username', '$password')");
mysql_query($query) or die(mysql_error());
mysql_close($query);
}
?>
你有什麼錯誤? –
您正在將原始密碼存儲在數據庫中,而不是轉義輸入或使用參數化查詢。這已經不是一個好的開始。您應該首先通過使用PDO來解決這個問題! – Ryan
你真的不應該使用任何'mysql_ *'函數,而是使用MySQLi或PDO。 –