Hi All,

If someone can help me with this I would be eternally grateful here.

I have created a form on one page with php validation. Once cleared through the validation I have Sessioned the inputted data to catch them on the "insert data page"

on the "insert data page" I have this bit of coding:

// GET POST DATA AND CREATE VARIABLES

$city = $_SESSION['city'];
$state = $_SESSION['state'];
$zip = $_SESSION['zip'];
$address = $_SESSION['address'];
$unit = $_SESSION['unit'];
$price = $_SESSION['price'];
$beds = $_SESSION['beds'];
$baths = $_SESSION['baths'];
$sqft = $_SESSION['sqft'];
$propType = $_SESSION['proptype'];

echo $id, $city, $state, $zip, $address, $unit, $price, $beds, $baths, $sqft, $propType;

include ('includes/conn.inc.php');

// INSERT DATA FROM FORM ONCE THE FORM HAS BEEN SUBMITTED AND VALIDATED
$sql="INSERT INTO table_name (id, city, state, zip, address_no_street, unit_no, price, beds, baths, sqft, property_type, date) VALUES ('$id', '$city', '$state', '$zip', '$address', '$unit', '$price', '$beds', '$baths', '$sqft', '$propType', NOW())";
mysql_query($sql) or die ('Something went wrong with submitting your information');

All variables are echoing properly so the data gets this far. The INSERT however does not fire. I have checked and rechecked my DB for misspells or errors but see none. Is there something I am missing here.

I tried this and it works perfectly:

$sql="INSERT INTO table_name (id, city, state, zip, address_no_street, unit_no, price, beds, baths, sqft, property_type, date) VALUES ('id', 'city', 'state', 'zip', 'address', 'unit', 'price', 'beds', 'baths', 'sqft', 'propType', NOW())";
mysql_query($sql) or die ('Something went wrong with submitting your information');

the variables are not getting in there for some reason and I can't figure out why.

Really appreciate any help on this.

Print your insert query after line no 19.

echo $sql;

Copy and paste it into phpmyadmin(or the query analyser u r using).
Execute the query and check out the errors.
Also modify

mysql_query($sql) or die ('Something went wrong with submitting your information <br>'.mysql_error);
commented: useful post +5

just echo out your qry

echo $sql="INSERT INTO table_name (id, city, state, zip, address_no_street, unit_no, price, beds, baths, sqft, property_type, date) VALUES ('$id', '$city', '$state', '$zip', '$address', '$unit', '$price', '$beds', '$baths', '$sqft', '$propType', NOW())";

copy this query and execute it in the SQl section of your phpmyadmin and see what happens. It will tell if you have any error in your query.

Hi Divyakrishnan,

I did what you suggested and the query is catching the data as well.

Below is what was printed back to me:

INSERT INTO table_name (id, city, state, zip, address_no_street, unit_no, price, beds, baths, sqft, property_type, date) VALUES ('7', 'city', 'Arizona', 'zip', 'address', 'unit', 'price', 'beds', 'baths', 'sqft', 'coop', NOW())Something went wrong with submitting your information 
mysql_error

The last line of code you gave for viewing mysql_errors just gave me an echo of that command.

Any ideas?

Your help is appreciated.

Print your insert query after line no 19.

echo $sql;

Copy and paste it into phpmyadmin(or the query analyser u r using).
Execute the query and check out the errors.
Also modify

mysql_query($sql) or die ('Something went wrong with submitting your information <br>'.mysql_error);

Hi divyakrishnan, I didn't see your post when i posted my post..

Hi Karthik,

No errors there. It executes properly..

Thanks for the suggestion..

replace line 20 with this

mysql_query($sql) or die(mysql_error());

and post the error message here...

That worked nicely Karthik, thank you so much man!

I was trying to INSERT while duplicating a primary id. It's all been fixed now.

Much thanks...

Ok :) Mark this thread as solved

Sorry karthik I missed brackets for mysql_error() function.Thank you for your correction

Sorry karthik I missed brackets for mysql_error() function.Thank you for your correction

OK... NP

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.