无法理解为什么经过多次修修补补后,我们将不胜感激:
<?php
// Fetch the user row from the query above
$userData = mysqli_fetch_array($query, MYSQL_ASSOC);
$password = $userData["password"];
if(isset($_POST['password2'])){
$p2 = $_POST['password2'];
}
$password2 = sha1($p2);
// Ajax calls this REGISTRATION code to execute
if($password2 == $password){
// GATHER THE POSTED DATA INTO LOCAL VARIABLES
$personname = preg_replace('#[^a-z ]#i', '', $_POST['personname']);
$email = mysqli_real_escape_string($db_conx, $_POST['email']);
$address_line1 = preg_replace('#[^a-z0-9 ]#i', '', $_POST['address_line1']);
$address_line2 = preg_replace('#[^a-z0-9 ]#i', '', $_POST['address_line2']);
$address_city = preg_replace('#[^a-z0-9 ]#i', '', $_POST['address_city']);
$address_state = preg_replace('#[^a-z0-9 ]#i', '', $_POST['address_state']);
$address_zip = preg_replace('#[^a-z0-9 ]#i', '', $_POST['address_zip']);
$address_country = preg_replace('#[^a-z ]#i', '', $_POST['address_country']);
////////电子邮件的重复数据检查
$sql1 = "SELECT email FROM users WHERE id='$id' AND activated='1' LIMIT 1";
if($email =! email){
$sql = "SELECT id FROM users WHERE email='$email' LIMIT 1";
$query = mysqli_query($db_conx, $sql);
$email_check = mysqli_num_rows($query);
if ($email_check > 0){
echo "That email address is already in use in the system";
exit();
}
//////////表格数据错误处理
else if($personname == "" || $email == "" || $password == "" || $address_country == "" || $address_line1 == "" || $address_line2 == "" || $address_city == "" || $address_state == "" || $address_zip == ""){
echo "The form submission is missing values.";
exit();
}
else {
//////// END FORM DATA ERROR HANDLING ////////开始将数据替换为数据库
//////将用户信息添加到主站点表的数据库表中
$query = "UPDATE users (personname, email, address_line1, address_line2, address_city, address_state, address_zip, address_country)
VALUES('$personname','$email','$address_line1','$address_line2','$address_city','$address_state','$address_zip','$address_country')
WHERE id = '$id'";
if(mysql_query($query)){
echo "updated";
header("location: user.php?id=".$_SESSION["id"]);
} else{ echo "fail";}
}
exit();
}
?>
答案 0 :(得分:2)
首先,}
没有if($password2 == $password){
的右括号$address_country...
,它可能属于}
之后。但是,您的支撑有点偏离,exit;
之后的if($email =! email){
应该与其他几个一起提升。例如if(mysql_query($query))
的那个。
您还要将API与if(mysqli_query($db_conx, $query))
混合,需要MYSQL_ASSOC
和MYSQLI_ASSOC
到if($email =! email){
。那些不同的MySQL函数不会相互混合。另外,请确保您已启动会话,因为您正在使用会话。
然后,此行email
- if($email != email){
被视为constant,并且也是错误的。它应显示为$sql1
。但是,我不知道您想要使用/检查哪个变量(或字符串),甚至不知道您表中的一行。
然后这个查询的变量email
- 它处于不确定状态。我不知道你想怎么做。
如果您想要对#34;电子邮件&#34;匹配一行,那么您需要这样做,从DB中获取行。
参见脚注
尝试以下内容,我已经重新安排了你的支撑:
旁注: 关于<?php
// Fetch the user row from the query above
$userData = mysqli_fetch_array($query, MYSQLI_ASSOC);
$password = $userData["password"];
if(isset($_POST['password2'])){
$p2 = $_POST['password2'];
}
$password2 = sha1($p2);
// Ajax calls this REGISTRATION code to execute
if($password2 == $password){
// GATHER THE POSTED DATA INTO LOCAL VARIABLES
$personname = preg_replace('#[^a-z ]#i', '', $_POST['personname']);
$email = mysqli_real_escape_string($db_conx, $_POST['email']);
$address_line1 = preg_replace('#[^a-z0-9 ]#i', '', $_POST['address_line1']);
$address_line2 = preg_replace('#[^a-z0-9 ]#i', '', $_POST['address_line2']);
$address_city = preg_replace('#[^a-z0-9 ]#i', '', $_POST['address_city']);
$address_state = preg_replace('#[^a-z0-9 ]#i', '', $_POST['address_state']);
$address_zip = preg_replace('#[^a-z0-9 ]#i', '', $_POST['address_zip']);
$address_country = preg_replace('#[^a-z ]#i', '', $_POST['address_country']);
}
//////// DUPLICATE DATA CHECKS FOR EMAIL
$sql1 = "SELECT email FROM users WHERE id='$id' AND activated='1' LIMIT 1";
// unsure what you want to do here
if($email != email){
$sql = "SELECT id FROM users WHERE email='$email' LIMIT 1";
$query = mysqli_query($db_conx, $sql);
$email_check = mysqli_num_rows($query);
if ($email_check > 0){
echo "That email address is already in use in the system";
exit();
}
}
////////// FORM DATA ERROR HANDLING
else if($personname == "" || $email == "" || $password == "" || $address_country == "" || $address_line1 == "" || $address_line2 == "" || $address_city == "" || $address_state == "" || $address_zip == ""){
echo "The form submission is missing values.";
exit();
}
else {
//////// END FORM DATA ERROR HANDLING //////// Begin Replacement of data into the database
//////Add user info into the database table for the main site table
$query = "UPDATE users (personname, email, address_line1, address_line2, address_city, address_state, address_zip, address_country)
VALUES('$personname','$email','$address_line1','$address_line2','$address_city','$address_state','$address_zip','$address_country')
WHERE id = '$id'";
if(mysqli_query($db_conx, $query))
echo "updated";
header("location: user.php?id=".$_SESSION["id"]);
} else{ echo "fail";}
}
exit();
?>
是一个常数,请检查您对上述内容的看法。它在下面没有改变。
UPDATE users...
旁注:
您使用的UPDATE table SET column_x = '$var'
并不是UPDATE的工作方式。
语法为 UPDATE [LOW_ PRIORITY] [IGNORE] table_name [, table_name...]
SET column_name1 = expr1
[, column_name2=expr2 ...]
[WHERE condition]
阅读更新:
即。从该页面:
INSERT INTO
如果您不想更新,请使用or die(mysqli_error($db_conx))
,我更倾向于此。
mysqli_query()
添加到$sql1 = "SELECT email FROM users WHERE id='$id' AND activated='1' LIMIT 1";
$result = mysqli_query($db_conx, $sql1);
$row = mysqli_fetch_row($result);
$email_row = $row['email'];
,您将看到错误。<强>脚注:强>
以下是获取行的示例:
if($email != $email_row){...}
然后你可以这样做:
{{1}}