0

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";
       }
?>

Edited by happygeek: moved

3
Contributors
8
Replies
52
Views
10 Months
Discussion Span
Last Post by cereal
0

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.

0

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

0

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

Edited by AndrisP

0

Thanx for your reply...AndrisP,

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

0

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);
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.