dt4233 2016-07-11 05:33
浏览 52
已采纳

PHP / MYSQL:用户注册页面

Recently I have been creating an PHP / MySQL user sign up page, and I've run into a problem in which it's keep getting an error when I call for the function, it returns to me:

"Fatal error: Call to undefined function signUp() in /Users/Ronald/Desktop/PHP/Brighten/admin/signup-method.php on line 65"

I wonder why does that happen. I'm sure this question must have been answered at somewhere already but I'm not that great at searching for it, so thank you for paying attention and thanks in advance

Error message: enter image description here

How it suppose to look like: enter image description here

<?php 
$dbhost = 'database_host';
$dbuser = 'database_user';
$dbpass = 'database_password';
$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbuser);
    if (!$conn){
        die('cannot connect to mysql');
    }


    if(isset($_POST['username'])){
        $username = $_POST['username'];
    }
    if(isset($_POST['password'])){
        $password = $_POST['password'];
    }
    if(isset($_POST['cpassword'])){
        $cpassword = $_POST['cpassword'];
    }
    if(isset($_POST['email'])){
        $email = $_POST['email'];
    }


    function addUser(){
        $query = "INSERT INTO websiteusers (user,password,email) VALUES ('$username','$password','$email')"; 
        $data = mysql_query ($query)or die(mysql_error()); 
        if($data) { 
            $result = '<div class="alert alert-success">Thank you, <strong>'.$_POST['name'].'</strong>! You are successfully registered</div>';
    }

    function signUp(){
        $query = "SELECT * FROM users WHERE user = '$username' AND pass = '$password'";

        $result = mysqli_query($conn, $query);
            if(!$row = mysqli_fetch_array($result)){
                addUser();
            }else{
            die("   <div class='alert alert-warning'>
                        <strong>Warning!</strong> You're already an registered user!
                    </div>");
            }
        }        
    }




    if ($_POST["submit"]) {
        if (!$_POST['username']) {
            $error="<br />Please enter your name";
        }
        if (!$_POST['password']) {
            $error.="<br />Please enter your password";
        }
        if (!$_POST['email']) {
            $error.="<br />Please enter your email";
        }
        if ($password != $cpassword){
            $error.= "<br/> Please confirm password is the same";
        }   
        if ($error) {
            $result='<div class="alert alert-danger"> There were error(s)in your form: '.$error.'</div>';
        }
        signUp();
    }


  ?>
  • 写回答

2条回答 默认 最新

  • douji3623 2016-07-11 05:37
    关注

    You have made a mistake in the add user function. Two { are opened but just one } is closed. Thats why the signUp is undefined because it is now a part of the adduser function.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来