Hello to all,

I am facing an issue in registering values into database through php.
Many times i have done the same but i don't know why i am unable to do this now. Since from 2-3 months, I have not done anything in php.Please help me out..

<?php 
include("config.php"); 

    $firstName = mysqli_real_escape_string($conn, $_POST["firstname"]);
    $lastname = mysqli_real_escape_string($conn, $_POST["lastname"]);
    $contact = mysqli_real_escape_string($conn, $_POST["contact"]);
    $sex = mysqli_real_escape_string($conn, $_POST["gender"]);
    $dob = mysqli_real_escape_string($conn, $_POST["dob"]);
    $email = mysqli_real_escape_string($conn, $_POST["email"]);
    $country = mysqli_real_escape_string($conn, $_POST["country"]);
    $expr = mysqli_real_escape_string($conn, $_POST["expr"]);
    $education = mysqli_real_escape_string($conn, $_POST["education"]);

    $sql = "INSERT INTO 'login' (firstname, lastname, contact, sex, dob, email, country, experience, education)
    VALUES ('$firstName', '$lastname', '$contact', '$sex', '$dob', '$email', '$country', '$expr', '$education')";

    $result = mysqli_query($conn, $sql);
    if ($result) 
        {
             echo "New record created successfully";
        }

    else
       {
        echo "failed";
       }
?>

Hi, add error checks before and after the query:

if($conn->connect_errno)
    die(sprintf("CONNECT ERROR: %s: %s", $conn->connect_errno, $conn->connect_error));

$result = mysqli_query($conn, $sql);

if($conn->errno)
    die(sprintf("ERROR: %s [%s]: %s", $conn->errno, $conn->sqlstate, $conn->error));

And see if you get any useful input.

Hello Cereal,
Thanx for your reply but I am still facing the same issue.
Can't store values of text fields in variables

Do not use table name in apostrophes! Table name can be in the backticks.

Thanx for your reply...AndrisP,

I already have done it before but still problem is same.

Thanx for your reply but I am still facing the same issue.
Can't store values of text fields in variables

You're welcome, but I was not suggesting a fix, I suggested you to run those functions in order to see if there are errors in your database connection, in the query syntax or if it rises a duplicate entry error (due to unique columns). If you don't get any errors, then check if the $_POST array is populated and if it gets the correct index names:

print_r($_POST);

Thankyou so much..
It's solved
one more thing....in this form, there are three dropdowns, I am not able to store these values
pleeaase help me.

Do you care to share the solution? Also, show us the form and the updated PHP code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.