数据库连接中没有错误,并且没有在数据库中插入数据,因为发出了发布请求,所以页面重定向到signup.php,并且没有创建查询。我试图回显变量$ email和$ password,它在屏幕上不显示任何内容,似乎整个php脚本未执行。它只是重定向到空白页。
<div class="modal-body">
<form class="form" action="signup.php" method="post">
<input id="textboxid" type="email" placeholder=" Email" name="email" required />
<br>
<br>
<input id="textboxid" type="password" placeholder=" Password" name="password" required />
<br>
<br>
<input id="textboxid" type="password" placeholder=" Confirm Password" name="cnfpassword" required />
<br><br>
<input id="signup" type="submit" name="signup" value="sign up"/>
</form>
</div>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
define('DB_NAME', 'myblog');
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_HOST', 'localhost');
$db = mysqli_connect(DB_HOST, DB_USER, DB_PASS,DB_NAME);
if ($db) {
echo 'conected';
} else {
echo 'not conected';
}
if(!empty($_POST['email']) || !empty($_POST['password']))
{
$email = mysqli_real_escape_string($db, $_POST['email']);
$password = md5($_POST['password']);
$cnfpassword = md5($_POST['cnfpassword']);
echo $email;
$sql = "SELECT id FROM accounts
WHERE email= '" . $email . "' ";
$result = mysqli_query($db, $sql);
$count = mysqli_num_rows($result);
if ($count == 0) {
mysqli_query($db, "INSERT INTO accounts (`email`,`password`)
VALUES('".$email."','".$password."')");
$SESSION['email'] = $email;
header("location:practice.html");
}
}
?>
答案 0 :(得分:0)
我测试了您的代码,它似乎正在工作。请检查以下内容以确保其有效
代码执行完毕后,会将您重定向到Practice.html,这可能是您要重定向到的空白页面,如果未将其配置为回显插入结果,则可以直接在phpmyAdmin上进行检查。
答案 1 :(得分:0)
请记住,此代码是不好的做法,很容易受到SQL注入的影响,请查看用于PHP的PDO API或添加函数
function db_escape($connection, $string) {
return mysqli_real_escape_string($connection, $string);
}
function insert_accounts($accounts) {
global $db;
$sql = "INSERT INTO accounts ";
$sql .= "(email, password) ";
$sql .= "VALUES (";
$sql .= "'" . db_escape($db, $accounts['email']) . "',";
$sql .= "'" . db_escape($db, $accounts['password']) . "',";
//echo $sql;
$sql .= ")";