我試圖從註冊表格插入數據到數據庫,但當我點擊註冊時,我沒有看到我的數據庫中的任何東西。連接並插入到php數據庫
我真的需要解決這個問題,以便我能夠插入到我的數據庫中。我無法弄清楚問題出在哪裏。非常感謝您的貢獻。
這是我的代碼幫助我。請幫助我。
<?php
session_start();
$server = 'localhost';
$users = 'root';
$pass = '';
$dataBase = 'accounts';
$_SESSION['message'] = '';
$mysqli = new mysqli($server, $users, $pass, $dataBase) or die("Not connected");
if($mysqli){
echo 'Connected Successfully';
}
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
//The two passwords are equal to each other
if($_POST['Password'] == $_POST['ConfirmPassword']){
$username = $mysqli->real_escape_string($_POST["username"]);
$email = $mysqli->real_escape_string($_POST['email']);
$password = md5($_POST['Password']); //hash password security
$phone = $mysqli->real_escape_string($_POST['Number']);
$_SESSION['username'] = $username;
$sql = "INSERT INTO user (username, email, password, phone) VALUES ('$username','$email','$password','$phone')";
//if the query is correct, then redirect to a welcome.php page. done!
if($mysqli->query($sql) === true){
$_SESSION['message'] = "Registration successful! $username is now a member";
header("location: login.php");
echo 'Successfully Registered!';
}
else{
$_SESSION['message'] == "Sorry you are not registered, check your field";
}
}
else{
$_SESSION['message'] == "Passwords do not match!";
}
}
?>
<body class="bg agileinfo">
<h1 class="agile_head text-center" style="color:#000"> Welcome</h1>
<div class="w3layouts_main wrap">
<!--Horizontal Tab-->
<div id="parentHorizontalTab_agile">
<ul class="resp-tabs-list hor_1">
<!-- <li>LogIn</li> -->
<li>SignUp</li>
</ul>
<div class="agile_its_registration">
<form action="#" method="post" class="agile_form">
<div class="alert alert-error"><?=$_SESSION['message'] ?></div>
<p>Username</p>
<input type="text" name="username" required="required" />
<p>Email</p>
<input type="email" name="email" required="required" />
<p>Phone Number</p>
<input type="text" name="Number" required="required" />
<p>Password</p>
<input type="password" name="Password" required="required" id="Password">
<p>Confirm Password</p>
<input type="password" name="ConfirmPassword" required="required" id="ConfirmPassword">
<div class="check w3_agileits">
<label class="checkbox w3"><input type="checkbox" name="checkbox" required="required" ><i> </i>I accept the terms and conditions</label>
</div>
<input type="submit" value="Signup"/>
<input type="reset" value="Reset" />
</form>
</div>
</div>
</div>
</body>
你說你沒有看到任何東西在你的數據庫,但什麼是SESSION [消息]的執行SQL後的價值? – Bango
做一個 - printf(「Errormessage:%s \ n」,$ mysqli-> error);在你的$ sql之後 –