Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Konrad Pilch
Konrad Pilch
2,435 Points

PHP Error what it mean

HI,

What this error mean? i dont have any code at line 2 anyways.

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

2 Answers

Ryan Field
PLUS
Ryan Field
Courses Plus Student 21,242 Points

This means that you have an error in the syntax of your mySQL database call before your closing parenthesis. It's hard to say anything else without seeing your query, though.

Konrad Pilch
Konrad Pilch
2,435 Points

This is 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>

Database :

<?php

    //Connect to the database
    $con = mysqli_connect("localhost", "root", "root", "029RegisterDB");

    //Check connection
    if($con === false){
        die("ERROR: Could not connect. " . mysqli_connect_error());
    }

Register:

<?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


?>
Konrad Pilch
Konrad Pilch
2,435 Points

I got it! Just a typo, and extra comma at the end : p

What do you think Ruby on Rails vs PHP?