dousong2967 2015-03-13 14:50
浏览 49

标题不适用于条件

I have been trying to get a page working for a number of days now, and there doesn't seem to be much help from the "related" questions on this site.

I have made a signup.php page, which has a form for inputting user credentials to signup up for the site I am building, when the form is filled out and the user presses the 'submit' button, the form uses the action "signupsuccess.php" which has all of the php code for inserting the credentials into the database, and then redirects the user to the "Login.php" page.

My problem: I have written code to say that if the user has not put in any data for one of the fields in the form, then they are brought back to the signup.php page by using this code:

<?php
if(!isset($_POST['fname'])&&($_POST['lname'])&&($_POST['email'])&&($_POST['pass'])){
    header('Location:Signup.php');
    exit;
}
else{
$host = "localhost";
$user = "******";
$password = "******";
$conn = mysql_connect($host, $user, $password);
$db = mysql_select_db('*****', $conn);
if(! get_magic_quotes_gpc() )
{
   $fname = addslashes ($_POST['fname']);
   $lname = addslashes ($_POST['lname']);
   $email = addslashes($_POST['email']);
   $pass = addslashes($_POST['pass']);
}
else
{
   $fname = $_POST['fname'];
   $lname = $_POST['lname'];
   $email = $_POST['email'];
   $pass= $_POST['pass'];
}
$query = mysql_query("select * from users where pass='$pass' AND email='$email'", $conn);
$rows = mysql_num_rows($query);
if ($rows == 1) {
    $errors[] = 'That user already exists, try another email';
}else
{

$sql = "INSERT INTO users ".
       "(fname,lname, pass, email) ".
       "VALUES('$fname','$lname','$pass','$email')";
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not enter data: ' . mysql_error());
}
}
}
mysql_close($conn);

?>

But the header() just won't bring the user back when they haven't put anything in to the fields. Is there anything I am doing obviously wrong or can anyone help me sort out the redirection of the user if they haven't entered anything.

  • 写回答

4条回答 默认 最新

  • duanao6704 2015-03-13 14:52
    关注

    Your if statement is incorrect. If you're just trying to check to see if those variables are set you need to call isset() on all of them.

    You can do this with individual calls to isset() or all in one call.

    if(!isset($_POST['fname'],$_POST['lname'],$_POST['email'],$_POST['pass'])){
        header('Location:Signup.php');
        exit;
    }
    

    FYI, you are wide open to SQL injections. addslashes() does not prevent SQL injections. Also, the mysql_* funcstions are obsolete and you should not be writing new code using them. Look into mysqli or PDO instead.

    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?