Click here to Skip to main content
15,892,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Fatal error: Uncaught Error: Call to undefined function VALUES() in C:\xampp\htdocs\signuptest\Signup.php:32 Stack trace: #0 {main} thrown in C:\xampp\htdocs\signuptest\Signup.php on line 32


What I have tried:

<?php
session_start();
$_SESSION['message']='';

$mysqli = new mysqli('localhost','root', '' , 'signuptest');

if ($_SERVER['REQUEST_METHOD'] == 'POST')  {
    
    //two passwords are equal to each other
    
    if($_POST['password'] == $_POST['confirmpassword']) {
        
        $firstname = $mysqli->real_escape_string($_POST['firstname']);
        $lastname = $mysqli->real_escape_string($_POST['lastname']);
        $email = $mysqli->real_escape_string($_POST['email']);
        $phonenumber = $mysqli->real_escape_string($_POST['phonenumber']);
        $password = md5($_POST['password']); //md5 hash password for security
        $avatar_path = $mysqli -> real_escape_string('image/'.$_FILES['avatar']['name']);
        
        //make sure file type
        
        if (preg_match("!image!", $_FILES['avatar']['type'])) {
           
            //copy image to images/ folder
            
            if(copy($_FILES['avatar']['tmp_name'], $avatar_path)){
                
                $_SESSION['firstname']= $firstname;
                $_SESSION['avatar']= $avatar_path;
                
                $sql = "INSERT INTO users(firstname,lastname,email,phonenumber,password,avatar)"
                .VALUES ('$firstname','$lastname','$email','$phonenumber','$password','$avatar_path');
               
                
                // if the qurey is succesful, redirect to welocme.php page, done!
                
                if ($mysqli -> query($sql) === true) {
                    $_SESSION['message'] = 'Registration Succesful! Added $username to the database!';
                    header("location: welcome.php");
                }
                
                else{
                    $_SESSION['message'] = 'User could not be added to the database';
                  
                }
            }
            
            else{
                $_SESSION['message'] = "File upload failed!";
            }
        }
        else{
            $_SESSION['message'] = "Please only upload JPG files";
        }
    }
    
    else{
        $_SESSION['message'] = "Two Passwords Doesn't match";
    }
}
Posted
Updated 4-Feb-20 15:03pm
Comments
Richard Deeming 3-Feb-20 11:52am    
Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

PHP: SQL Injection - Manual[^]
Richard Deeming 3-Feb-20 11:54am    
Also, using MD5 for password storage is just wrong. MD5 has been broken since 1996, and considered unsuitable for use since 2010.

Use PHP's built-in functions for password storage instead:
PHP: password_hash[^]
PHP: password_verify[^]

You are missing the double quote around the second line of the SQL command. It should be:
PHP
$sql = "INSERT INTO users(firstname,lastname,email,phonenumber,password,avatar)"
. "VALUES ('$firstname','$lastname','$email','$phonenumber','$password','$avatar_path');";
 
Share this answer
 
v2
PHP
$sql = "INSERT INTO users(firstname,lastname,email,phonenumber,password,avatar)"
                .VALUES ('$firstname','$lastname','$email','$phonenumber','$password','$avatar_path');

Not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900