Ronald Ng
Ronald Ng

Reputation: 116

PHP / MSQL : User Sign Up Page

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();
    }


  ?>

Upvotes: 1

Views: 79

Answers (2)

Abdullah Ahmed
Abdullah Ahmed

Reputation: 1

parenthesis not closed in adduser just use following code

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>");
        }
    } 

Upvotes: -1

Jonas Wilms
Jonas Wilms

Reputation: 138237

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.

Upvotes: 4

Related Questions