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 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏