我最近将我的旧mysql代码转换为mysqli,我想我错过了一些东西。出于某种原因,我现在没有收到mysql数据库中的任何内容,并且我没有收到提示输入任何警报消息。任何人都有我缺少的想法吗?
<?php
session_start();
if(isset($_SESSION['user'])!="")
{
header("Location: ../index.php");
}
include_once 'dbconnect_i.php';
if(isset($_POST['btn-signup']))
{
$s_firstname = mysqli_real_escape_string($conn,$_POST['student_firstname']);
$s_lastname = mysqli_real_escape_string($conn,$_POST['student_lastname']);
$s_email = mysqli_real_escape_string($conn,$_POST['student_email']);
$s_password = mysqli_real_escape_string($conn,$_POST['student_password']);
$s_street_add = mysqli_real_escape_string($conn,$_POST['student_street_add']);
$s_city_town_add = mysqli_real_escape_string($conn,$_POST['student_city_town_add']);
$s_state_add = mysqli_real_escape_string($conn,$_POST['student_state_add']);
$s_zipcode_add = mysqli_real_escape_string($conn,$_POST['student_zipcode_add']);
$s_phone = mysqli_real_escape_string($conn,$_POST['student_phone']);
$s_bday = mysqli_real_escape_string($conn,$_POST['student_bday']);
$s_newsletter = mysqli_real_escape_string($conn,$_POST['student_newsletter']);
$s_firstname = trim($s_firstname);
$s_lastname = trim( $s_lastname);
$s_email = trim($s_email);
$s_password = trim($s_password);
$s_street_add = trim($s_street_add);
$s_city_town_add = trim($s_city_town_add);
$s_state_add = trim($s_state_add);
$s_zipcode_add = trim($s_zipcode_add);
$s_phone = trim($s_phone);
$s_bday = trim($s_bday);
$s_newsletter = trim($s_newsletter);
$s_password = hash("sha256", $s_password);
// email exist or not
$query = "SELECT student_email FROM studentdata WHERE student_email='$s_email'";
$result = mysqli_query($conn,$query);
if ($result != false) {
$count = mysqli_num_rows($result); // if email not found then register
if($count == 0){
if(mysqli_query($conn, "INSERT INTO studentdata(student_username,student_firstname,student_lastname,student_email,student_password,student_street_add,student_city_town_add,student_state_add,student_zipcode_add,student_phone,student_bday,student_newsletter) VALUES('$s_email','$s_firstname','$s_lastname','$s_email','$s_password','$s_street_add','$s_city_town_add','$s_state_add','$s_zipcode_add','$s_phone','$s_bday','$s_newsletter')"))
{
?>
<script>
alert('successfully registered ');
</script>
<?php
}
else
{
?>
<script>
alert('error while registering you...');
</script>
<?php
}
}
else{
?>
<script>
alert('Sorry Email ID already taken ...');
</script>
<?php
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimal-ui">
<title>HarringtonEd Inc.</title>
<link href="favicon.png" type="image/x-icon" rel="shortcut icon">
<link href="style.css" rel="stylesheet">
<script src="assets/plugins/jquery/jquery-1.11.3.min.js"></script>
</head>
<body>
<center>
<div id="login-form">
<form method="post">
<table align="center" width="40%" border="0">
<tr>
<td>
<label for="student_firstname">First Name</label>
<input type="text" name="student_firstname" placeholder="First Name" required />
</td>
<td>
<label for="student_lastname">Last Name</label>
<input type="text" name="student_lastname" placeholder="Last Name" required />
</td>
</tr>
<tr>
<td>
<label for="student_email">Email</label>
<input type="email" name="student_email" placeholder="Email" required />
</td>
<td>
<label for="student_password">Password</label>
<input type="password" name="student_password" placeholder="Password" required />
</td>
</tr>
<tr>
<td>
<label for="student_street_add">Street Name</label>
<input type="text" name="student_street_add" placeholder="Street Name" required />
</td>
<td>
<label for="student_city_town_add">City/Town</label>
<input type="text" name="student_city_town_add" placeholder="City/Town" required />
</td>
</tr>
<tr>
<td>
<label for="student_state_add">State</label>
<input type="text" name="student_state_add" placeholder="State" required />
</td>
<td>
<label for="student_zipcode_add">Zip Code</label>
<input type="text" name="student_zipcode_add" placeholder="Zip Code" required />
</td>
</tr>
<tr>
<td>
<label for="student_phone">Phone Number</label>
<input type="tel" name="student_phone" placeholder="888 888 8888" pattern="[0-9]{3} [0-9]{3} [0-9]{4}" maxlength="12" required />
</td>
<td>
<label for="student_bday">Birthday</label>
<input type="date" name="student_bday" placeholder="Birthday" required />
</td>
</tr>
<tr>
<td>
<label for="student_newsletter">Subscribe to Newsletter</label>
<input type="checkbox" name="student_newsletter" value="Yes" checked/>
</td>
</tr>
</table>
<table align="center" width="40%" border="0">
<tr>
<td></td>
<td>
<button type="submit" name="btn-signup">Register</button>
</td>
<td></td>
</tr>
</table>
</form>
</div>
</center>
</body>
</html>
答案 0 :(得分:1)
如果您的查询失败,请显示此
<script>
alert('error while registering you...');
</script>
正在开发中,这是一条无用的信息。使用正确的错误报告来找出错误是什么。
echo mysqli_connect_error();
echo mysqli_error($conn);
这并没有解决问题,它只是告诉你问题是什么而不是其他人不得不猜测。