session_start();
include('dbconn.php');
if(isset($_POST['registerform']) || isset($_POST['loginform'])) {
if(isset($_POST['registerform']) && $_POST['registerform']){
//register
if(isset($_POST['username']) && !empty($_POST['username'])
&& isset($_POST['password']) && !empty($_POST['password'])
&& isset($_POST['fname']) && !empty($_POST['fname'])
&& isset($_POST['lname']) && !empty($_POST['lname'])
&& isset($_POST['email']) && !empty($_POST['email'])){
//ean einai gemata me kati ta paidia
$myName=trim($_POST['username']);
$myPass= md5(trim($_POST['password']));
$fName=trim($_POST['fname']);
$lName=trim($_POST['lname']);
$eMail=trim($_POST['email']);
if($stmt = $mysqli->prepare("INSTERT INTO users(username,password,fname,lname,email) VALUES (?, ?, ?, ?, ?)")) {
$stmt->bind_param('sssss',$name,$pass,$fname,$lname,$email);
$name = $myName;
$pass = $myPass;
$fname = $fName;
$lname = $lName;
$email = $eMail;
$stmt-> execute();
$stmt-> close();
}
}
}
}else{
echo "no form submited";
}
,這是數據庫連接PHP值不會對數據庫
<?php
$host = "localhost";
$username = "root";
$password = "";
$db_name = "phpwebsite";
$mysqli = new mysqli("$host","$username","$password","$db_name");
// Check connection
if ($mysqli->connect_error) {
die("Connection failed: " . $mysqli->connect_error);
}
?>
我認爲這個問題是插入statment因爲一切似乎是工作的罰款。當我按下注冊按鈕時,不會出現錯誤。唯一的一點是,該值不會對數據庫
錯字拼寫'INSTERT' – Saty
很棒。另外,'!empty()'就足夠了,如果你只是想確保該變量不爲空 – hungrykoala
非常多地使'INSTERT'變爲'INSERT'並嘗試 –