0

我有两个步骤注册表单。从第一步开始,我将获取电子邮件和用户名,从第二步开始,我想获取名字和姓氏并将其添加到数据库中。但问题是我从第一种POST形式获得的变量,$bridge_username确切地说,在下面的 IF 语句中不可用(从底部开始的第一个)。问题是它们在其他任何地方都可见,但不在此特定IF语句中。我已经尝试了一切,包括会话。我可以清楚地看到该变量仍然存在(使用vardump或只是echo将其取出),无处不在,但不是我需要它的地方......我很高兴听到你的建议。

$bridge_email = $_POST['email'];
$bridge_username = $_POST['username'];
$bridge_pass = $_POST['password'];
$bridge_pass_conf = $_POST['passconf'];
$bridge_terms = $_POST['terms'];
$bridge_pass_counted = strlen($bridge_pass);
$bridge_username_counted = strlen($bridge_username);
if (isset ($_POST['email']) AND isset ($_POST['password']) AND isset ($_POST['passconf']) AND isset ($_POST['username'])) { 

if ($bridge_email != '' AND $bridge_pass != '' AND $bridge_pass_conf != '' AND $bridge_username != '' AND $bridge_terms != '') {

if ($bridge_pass == $bridge_pass_conf) {

if ($bridge_pass_counted >= 33 OR $bridge_pass_counted <= 5) {
} else {

if ($bridge_username_counted >= 65 OR $bridge_username_counted <= 3) {
} else {

if (is_numeric(substr($bridge_username, 0, 1))) {
                } else {
//CHECK IF USERNAME OR EMAIL ALREADY EXIST  
$checkreguser = $mysqli->query("SELECT username FROM `engine_users` WHERE username = '$bridge_username' OR email = '$bridge_email' LIMIT 0, 1 ");
$checkreguser = $checkreguser->fetch_assoc();
if ($checkreguser == '') {
//CREATING A NEW USER 
$mysqli->query("INSERT INTO `users` (`id`, `username`, `password`, `email`, `fname`, `lname`, `company`, `address`, `city`, `state`, `zip`, `country`, `currency`, `phone`, `vat`, `userlevel`, `created`, `notes`, `lastlogin`, `lastip`, `active`) VALUES\n"
    . "(NULL, '$bridge_username', '1411678a0b9e25ee2f7c8b2f7ac92b6a74b3f9c5', '$bridge_email', '', '', NULL, '', '', '', '', '', '', '', NULL, 5, '2011-05-01 18:10:14', '', '2013-04-19 22:25:11', '127.0.0.1', 'y')");
}}}}}}}

$bridge_fname = $_POST['1_1_3'];
$bridge_lname = $_POST['1_1_4'];
if (isset ($_POST['1_1_3']) AND isset ($_POST['1_1_4'])) {
$mysqli->query("UPDATE `users` SET `fname` = '$bridge_fname',`lname` = '$bridge_lname' WHERE `users`.`username` = '$bridge_username'");
}
4

4 回答 4

0

您是否正在检查会话是否已启动。我看到您一直提到数据已传递给会话。可能需要设置它以确保它得到处理。

尝试检查会话变量是否已创建,如果没有则重定向回注册/登录页面。

例如......如果会话未注册,它将移动到不同的脚本或位置。

session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");

您可以通过在会话的 isset 上回显内容来进一步测试会话以继续测试。同样,我会将您的代码分解为最基本的形式,以了解发生了什么。可能还需要查看前一页代码以了解发生了什么。

在网上找到了另一个可以帮助你的例子。http://www.phpeasystep.com/phptu/6.html

于 2013-04-20T06:32:23.080 回答
0

http://php.net/manual/en/function.isset.php

I would try and break your code down to a simple few lines and test the if statement. Better to identify where it is breaking. Maybe add some echo statements during different steps or comment and step through the code. Example below.

$bridge_email = $_POST['email'];
$bridge_pass = $_POST['password'];

if (isset($_POST['email']) AND isset($_POST['password']){
   // EXECUTE AN ALERT
echo"email and pass are set";
}else {
echo"not passing";
}
于 2013-04-20T05:32:52.967 回答
0

我对您的代码进行了一些修改,以使您成为一个很好的例子,主要问题是您如何构建查询字符串

..." username = '$bridge_username' "

这将产生一个像您看到的字符串
(在执行查询之前打印查询是很好的调试)您必须将其更改为:

." username = '".$bridge_username."' "

并且变量将被其值替换。

还添加了对 post 值的检查,因此如果未设置它们,您不会收到警告。

$bridge_email = (isset($_POST['email']) ? $_POST['email'] : null);
$bridge_username = (isset($_POST['username']) ? $_POST['username'] : null);
$bridge_pass = (isset($_POST['password']) ? $_POST['password'] : null);
$bridge_pass_conf = (isset($_POST['passconf']) ? $_POST['passconf'] : null);
$bridge_terms = (isset($_POST['terms']) ? $_POST['terms'] : null);
//$bridge_pass_counted = strlen($bridge_pass); 
//$bridge_username_counted = strlen($bridge_username);

//return early and stay back from chained IFs
if (!$bridge_email || !$bridge_username || !$bridge_pass || !$bridge_pass_conf) {
    return;
}

if ($bridge_pass != $bridge_pass_conf) {
    return;
}

if ($bridge_pass AND strlen($bridge_pass) > 5 AND strlen($bridge_pass) < 33) {
    return;
}

if ($bridge_username AND strlen($bridge_username) > 5 AND strlen($bridge_username) < 33) {
    return;
}

if (is_numeric(substr($bridge_username, 0, 1))) {
    return;
}

$result = $mysqli->query("SELECT username FROM `engine_users` WHERE username = '" . $bridge_username . "' OR email = '" . $bridge_email . "' LIMIT 0, 1 ");
$checkreguser = $result->fetch_assoc(); // returns associative array of strings  or NULL if there are no more rows 
//if ($checkreguser == '') {

if ($checkreguser === null) {
//CREATING A NEW USER 
    $mysqli->query("INSERT INTO `users` (`id`, `username`, `password`, `email`, `fname`, `lname`, `company`, `address`, `city`, `state`, `zip`, `country`, `currency`, `phone`, `vat`, `userlevel`, `created`, `notes`, `lastlogin`, `lastip`, `active`) VALUES\n"
            . "(NULL, '" . $bridge_username . "', '1411678a0b9e25ee2f7c8b2f7ac92b6a74b3f9c5', '" . $bridge_email . "', '', '', NULL, '', '', '', '', '', '', '', NULL, 5, '2011-05-01 18:10:14', '', '2013-04-19 22:25:11', '127.0.0.1', 'y')");
}

$bridge_fname =  (isset($_POST['1_1_3']) ? $_POST['1_1_3'] : null);
$bridge_lname =  (isset($_POST['1_1_4']) ? $_POST['1_1_4'] : null);
if ($bridge_fname AND $bridge_lname ) {
    $mysqli->query("UPDATE `users` SET `fname` = '" . $bridge_fname . "',`lname` = '" . $bridge_lname . "' WHERE `users`.`username` = '" . $bridge_username . "'");
}

请检查 IF 结构,提前返回使代码更具可读性。

于 2013-04-20T06:22:05.270 回答
0

利用

if(isset($_POST['bridge_username']))

看看它是否存在。

您还可以使用三元运算符

$email = isset($_POST['bridge_username']) ? $_POST['bridge_username'] = false;

是的..“确切地说,$bridge_username 在下面的 IF 语句中不可用。”

如果您想要更详细的答案,请告诉我们确切的错误:)

于 2013-04-20T05:16:14.050 回答