-1
中給出。幫助..每當我提交數據時都會出現錯誤。警告:mysqli_query()預計參數1是mysqli的,在C指定的字符串:\ XAMPP \ htdocs中\上線44 電子商務\ server.php這是我的代碼警告:mysqli_query()期望參數1爲mysqli,字符串在C: xampp htdocs ecommerce server.php中的44行
<?php
$email = "";
$firstname = "";
$contact= "";
$errors = array();
// connect to the database
$db = mysqli_connect('localhost', 'root', '','registration');
// if the register button is clicked
if (isset($_POST['register'])) {
$email = mysql_real_escape_string($_POST['email']);
$password_1 = mysql_real_escape_string($_POST['password_1']);
$password_2 = mysql_real_escape_string($_POST['password_2']);
$firstname = mysql_real_escape_string($_POST['firstname']);
$lastname = mysql_real_escape_string($_POST['lastname']);
$contact = mysql_real_escape_string($_POST['contact']);
// ensure that form field is filled properly
if (empty($email)) {
array_push($errors, "Email is required");
}
if (empty($firstname)) {
array_push($errors, "Firstname is required");
}
if (empty($contact)) {
array_push($errors, "Contact number is required");
}
if (empty($password_1)) {
array_push($errors, "Password is required");
}
if ($password_1 != $password_2) {
array_push($errors, "The two passwords do not match");
}
// if there is no errors, save user to database
if (count($errors) == 0) {
$password = md5($password_1); //encrypt password before storing in database
$sql = "INSERT INTO users (email, password, firstname, lastname, contact)
VALUES ('$email', '$password', '$firstname', '$lastname', '$contact')";
mysqli_query($sql, $db);
}
}
?>
混合'mysqli_ *'和'mysql_ *'真的是個壞主意。不要使用'mysql_ *'。'使用'mysqli_ *'''準備好的語句'並且從'SQL注入'保存自己。 –
md5也是可怕的練習 – rtfm
[mysqli \ _fetch \ _array()/ mysqli \ _fetch \ _assoc()/ mysqli \ _fetch \ _row()期望參數1是資源或mysqli \ _result,布爾給定](https://stackoverflow.com/questions/2973202/mysqli-fetch-array-mysqli-fetch-assoc- mysqli-fetch-row-expect-parameter-1) – mkaatman