Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP

Konrad Pilch
Konrad Pilch
2,435 Points

Whats wrong wit htis code?

I get this error:

ERROR Could not able to executeYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 2

My process looks like this :

<?php

    //When Submited
    if(isset($_POST['register'])){

        //Creating Registration Variables
        $username = mysqli_real_escape_string($con, $_POST['username']);
        $firstname = mysqli_real_escape_string($con, $_POST['firstname']);
        $lastname = mysqli_real_escape_string($con, $_POST['lastname']);
        $pwd = mysqli_real_escape_string($con, $_POST['pwd']);
        $repeat_pwd = mysqli_real_escape_string($con, $_POST['reoeat-pwd']);
        $email = mysqli_real_escape_string($con, $_POST['email']);


        //Validate Input
        if(!isset($username) || $username == '' || !isset($firstname) || $firstname == '' || !isset($lastname) || $lastname == ''  ||  !isset($pwd) || $pwd == '' || !isset($email) || $email == ''){
            $error = 'Please fill in the empty fields';
            header("Location: index.php?error=".urldecode($error));
            exit();
        } else {
            //Inserting Records to the Database
            $query = "INSERT INTO users (user_name, first_name, last_name, password, email)
                        VALUES('$username', '$firstname', '$lastname', '$pwd', '$email', )";
            if(mysqli_query($con, $query)){
                echo "Records added successfully.";
                header("Location: index.php");
                exit();
            } else {
                echo "ERROR Could not able to execute" . mysqli_error($con);
            }
        } 

    }//register

    mysqli_close($con);
?>

my index

<?php include 'database.php'; ?>

<?php include 'reg_process.php'; ?>

<!DOCTYPE html>
<html lang="en">
    <head>

        <title></title>

        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
        <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">

        <!-- Seo meta -->
        <meta name="keywords" content="" />

        <!-- Custom CSS -->
        <link href="includes/css/styles.css" rel="stylesheet">
        <link rel="stylesheet" href="fonts/font-awesome.min.css">

        <!-- Ajax & Bootstrap -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
    </head>
    <body>

        <!-- Header -->
        <header id="header">
            <nav class="navbar navbar-default navbar-inverse">
                <div class="container-fluid">
                    <div class="container">

                        <div class="navbar-header">
                            <a href="" class="navbar-brand">The Ultimate Truth</a>
                        </div><!-- /navbar-header -->

                        <div class="collapse navbar-collapse" id="navbar1">
                            <ul class="nav navbar-nav pull-right">
                                <li>
                                    <a href="">Home</a>
                                </li>
                                <li class="active">
                                    <a href="">Register</a>
                                </li>
                                <li>
                                    <a href="">Log In</a>
                                </li>
                                <li>
                                    <a href="">Log Out</a>
                                </li>
                                <li>
                                    <a href="">Posts</a>
                                </li>
                            </ul>
                        </div><!-- /colllapse navbar -->
                    </div><!-- /container -->
                </div><!-- /container-fluid -->
            </nav><!-- /navbar -->
        </header>


        <div id="registration-form">
            <div class="container">
                <h1>Registration</h1>
                <form method="post" action"reg_process.php">

                   <div class="row">
                    <h4>Enter your Username:</h4>
                      <div class="col-lg-12">
                        <div class="input-group">
                            <span class="input-group-btn">
                                <input type="text" name="username" class="form-control" value="<?php ?>" placeholder="Enter your username.">
                            </span>
                        </div><!-- /input-group --> 
                      </div><!-- /col-lg-12 -->
                    </div><!-- /row -->

                    <div class="row">
                    <h4>Enter your Firstname:</h4>
                      <div class="col-lg-12">
                        <div class="input-group">
                            <span class="input-group-btn">
                                <input type="text" name="firstname" class="form-control" value="<?php ?>" placeholder="Enter your firstname.">
                            </span>
                        </div><!-- /input-group --> 
                      </div><!-- /col-lg-12 -->
                    </div><!-- /row -->

                    <div class="row">
                    <h4>Enter your Lastname:</h4>
                      <div class="col-lg-12">
                        <div class="input-group">
                            <span class="input-group-btn">
                                <input type="text" name="lastname" class="form-control" value="<?php ?>" placeholder="Enter your lastname.">
                            </span>
                        </div><!-- /input-group --> 
                      </div><!-- /col-lg-12 -->
                    </div><!-- /row -->

                    <div class="row">
                    <h4>Enter your Password:</h4>
                      <div class="col-lg-12">
                        <div class="input-group">
                            <span class="input-group-btn">
                                <input type="text" name="pwd" class="form-control" value="<?php ?>" placeholder="Enter your password">
                            </span>
                        </div><!-- /input-group --> 
                      </div><!-- /col-lg-12 -->
                    </div><!-- /row -->

                    <div class="row">
                    <h4>Repeat Password:</h4>
                      <div class="col-lg-12">
                        <div class="input-group">
                            <span class="input-group-btn">
                                <input type="text" name="repeat-pwd" class="form-control" value="<?php ?>" placeholder="Repeat password">
                            </span>
                        </div><!-- /input-group --> 
                      </div><!-- /col-lg-12 -->
                    </div><!-- /row -->

                    <div class="row">
                    <h4>Enter your email:</h4>
                          <div class="col-lg-12">
                            <div class="input-group">
                                <span class="input-group-btn">
                                    <input type="text" name="email" class="form-control" value="<?php ?>" placeholder="Enter your email">
                                </span>
                            </div><!-- /input-group --> 
                        </div><!-- /col-lg-12 -->
                    </div><!-- /row -->

                    <button class="btn btn-default btn-custome" name="register" type="submit">Register!</button>

                </form>
            </div><!-- /container -->
        </div>


        <!-- Footer -->
        <footer>

        </footer>


        <!-- Scripts -->
        <script src="jquery-2.1.0.min.js"></script>
        <script src="app.js"></script>
    </body>
</html>

1 Answer

Rhoda Toynbee
Rhoda Toynbee
18,938 Points

First thing I saw was a typo:

``` $repeat_pwd = mysqli_real_escape_string($con, $_POST['reoeat-pwd']);

'repeat-pwd'

I would go through and check to make sure everything is typed correctly and that all your tags are typed and closed properly :)

Konrad Pilch
Konrad Pilch
2,435 Points

HI, thank you, but i didnt use that code yet though since i didnt make the password check yet xd . Im going throw the code over and over again but im closer , i found a block wheres somewhere error .

Konrad Pilch
Konrad Pilch
2,435 Points

Okay, i know its in my query . I m investigating this now : p

Konrad Pilch
Konrad Pilch
2,435 Points

Hahah very funny : p again, i had an extra comma : p

Konrad Pilch
Konrad Pilch
2,435 Points

It took me like 40minutes to get this right.. and before i had a typo too. Im basicaly learning it and i had somehting little less complex , and now i have a little more comples , but still, just a typo.. : p

Thank you!

Konrad Pilch
Konrad Pilch
2,435 Points

Hope you had a lovely day ( or maybe its just strating : p, depending on the land : p ) ! :)

Konrad Pilch
Konrad Pilch
2,435 Points

Do you know how can i redirect the page to register again? i mean instead of going to the next page, i put a header location index.php but it wont work.