我有一個註冊頁面,它將註冊數據插入數據庫。 它去沿着這行:插入mysqli
if ($_POST['password'] == $_POST['conf_pass']){
$user = $_POST['username'];
$pass = $_POST['password'];
$hash = md5(rand(0,1000));
$accres = mysqli_query($connection, "INSERT INTO accounts (street1, suburb, city, postcode, username) VALUES($address, $suburb, $city, $postcode, $username)");
$account_id = mysqli_insert_id($accres);
$peopleres = mysqli_query($connection, "INSERT INTO people (lastname, firstname, accounts_id, birthdate, phonenumber, username, password, email, hash) VALUES($lastname, $firstname, $account_id, $birthdate, $phonenumber, $username, $password, $email, $hash)");
$peoplerows=mysqli_fetch_assoc($peopleres);
$person_id=$peoplerows[0];
mysqli_query("INSERT INTO PeopleToRole (role_id) VALUES(1)");
$email = $_SESSION['email'];
$p->addContent("User Registered");
}
我原先編程的所有本使用的是Postgres的(而Apache服務器上本地託管),但不得不改變到mysqli的,因爲主機的網站已經與mysqli的工作。
因此,此代碼返回頁面上註冊的用戶,因此if語句正在工作。但由於某些原因,insert語句不會在數據庫中插入任何內容。
我有某種格式錯誤嗎?或者我錯過了一些小東西? 任何和所有的幫助,將不勝感激。 感謝
使用佔位符。你的數據很容易被sql注入!檢查錯誤!它會告訴你到底發生了什麼錯誤(哪些是你的變量沒有被引用。) – Cfreak
「我有某種格式錯誤嗎?或者我錯過了一些小東西?」這裏是一個不重要的問題,請介意。 –
如果代碼與Postgres而不是mySql一起工作,則可能是某種數據庫設置問題。檢查賬戶,權限,錯誤日誌等。 –