Yahya
Yahya

Reputation: 33

Entering form data into database through php using wamp server

I am trying to put data from the form to the MySQL database of the wamp server using PHP. I did all and "failed" is displayed on the screen after pressing the submit button.

Here is the PHP code:

<?php

    $con = mysqli_connect('localhost', 'root', '', 'bse3a');

    if (isset($_POST['submit']))
    {
        $fName = $_POST['first_name'];
        $lName = $_POST['last_name'];
        $email = $_POST['email'];
        $password= $_POST['password'];
        $rPassword= $_POST['re_password'];
        $phone = $_POST['phone_number'];
        $dob = $_POST['birth_date'];
        $gender = $_POST['gender'];

        $query = "insert into  students(fName,lName,email,password,rPassword,phone,dob,gender) values ('$fName', '$lName', '$email', '$password', '$rPassword', '$phone', '$dob', '$gender')";

        if(mysqli_query($con,$query)){
            echo "Register successfully";
        }
        else {
            echo "failed";
        }

    }

?>

Upvotes: 0

Views: 963

Answers (1)

Thanh Trung
Thanh Trung

Reputation: 3804

While there's not enough information to debug your case, you should display that last error to understand why it doesn't work.

//in fail case
echo("Error description: " . mysqli_error($con));

Then update your question.

Upvotes: 1

Related Questions