我是新來的PHP,我試圖創建一個註冊表單。我不知道爲什麼我的代碼沒有將新用戶添加到數據庫,它不會給任何錯誤消息只是進入白屏。我不知道它是否連接到數據庫,但我相信這是否會給我一個錯誤信息,對不對?我的php代碼沒有添加到我的數據庫
這是我的PHP代碼:
<?php
define('DB_HOST', 'localhost');
define('DB_NAME', 'class_rate');
define('DB_USER', 'root');
define('DB_PASSWORD', 'password');
$con = mysqli_connect(DB_HOST, DB_USER,DB_PASSWORD) or die("Failed to connect" . mysqli_error());
$db = mysqli_select_db($con, DB_NAME) or die("Failed to connect" . mysqli_error());
function NewUser(){
$name = $_POST['nome'];
$email = $_POST['email'];
$password = $_POST['password'];
$query = "INSERT INTO users (nome_user,email_user,passw_user) VALUES ('$name','$email','$password')";
$data = mysqli_query($query)or die(mysql_error());
if($data) {
echo "YOUR REGISTRATION IS COMPLETED...";
}
}
function SignUp(){
if (!empty($_POST['email'])) {
$query = mysqli_query("SELECT * FROM users WHERE email_user = $_POST[email]' AND passw_user = '$_POST[password]'") or die(mysqli_error());
}
if(!$row = mysqli_fetch_array($query) or die(mysqli_error())){
NewUser();
}
else{
echo "Email already registered!";
}
}
if (isset($_POST['submit'])) {
SignUp();
}
?>
提交變量存在於調用此代碼的窗體中?我認爲函數Signup中的查詢會失敗,你傳遞的是電子郵件並且傳遞錯誤。 – iubema
瞭解功能參數 – metalbox
https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php?rq=1 –