在我的注册页面上,它会询问电子邮件和密码,然后将其插入数据库。然后,用户被转发到注册页面,其形式为insertregstration.php =见下文。
问题 - 然后插入所有内容,然后删除电子邮件和密码。我遇到了麻烦,似乎这个代码就是问题所在。
请帮助。
<?php
session_start();
$con=mysqli_connect("localhost", "root", "", "info");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$firstname = mysqli_real_escape_string($con, $_POST['firstname']);
$lastname = mysqli_real_escape_string($con, $_POST['lastname']);
$gender = mysqli_real_escape_string($con, $_POST['gender']);
$contact = mysqli_real_escape_string($con, $_POST['contact']);
$email = mysqli_real_escape_string($con, $_POST['email']);
$password = mysqli_real_escape_string($con, $_POST['password']);
$addressone = mysqli_real_escape_string($con, $_POST['addressone']);
$addresstwo = mysqli_real_escape_string($con, $_POST['addresstwo']);
$city = mysqli_real_escape_string($con, $_POST['city']);
$state = mysqli_real_escape_string($con, $_POST['state']);
$zip = mysqli_real_escape_string($con, $_POST['zip']);
$sql="UPDATE users SET firstname='$firstname', lastname = '$lastname', gender = '$gender', contact='$contact', email = '$email', password = '$password', addressone='$addressone', addresstwo= '$addresstwo',`city`='$city', state = '$state', zip = '$zip' WHERE id='" .$_SESSION['id']."'";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
header("Location:dashboard.php");
mysqli_close($con);
?>
答案 0 :(得分:1)
这是注册页面吗?注册意味着添加新用户。使用插入查询,可能是电子邮件和密码var返回一个空字符串值,因此它会自动将空字符串更新到数据库表。