?
Solved

form data not being inserted into database

Posted on 2006-05-13
4
Medium Priority
?
184 Views
Last Modified: 2006-11-18
I am trying to insert form data into a mysql database.  Below is the code for the handle php page i am using.  when i submit the form there are no errors but when i query the database the table is empty.


How do i get the fields below into my database?

//declare text boxes as variables

$name = '$_POST[txtname]';
$email = '$_POST[txtemail]';
$home_phone = '$_POST[txthome_phone]';
$cell_phone = '$_POST[txtcell_phone]';
$business_phone = '$_POST[txtbusiness_phone]';
$address = '$_POST[txtaddress]';
$city = '$_POST[txtcity]';
$state = '$_POST[txtstate]';
$zip = '$_POST[txtzip]';
$interest = '$_POST[txtinterest]';
$questions = '$_POST[txtquestions]';


//Linking to the database on pair.com

$link = mysql_connect($host, $user, $password) or die (mysql_error());
Mysql_select_db("motion_meadow") or die(mysql_error());


//Insert text box values from form into the database
$query = "INSERT INTO form_data(NAME, EMAIL, HOME_PHONE, CELL_PHONE, BUSINESS_PHONE, ADDRESS, CITY, STATE,

ZIP, AREA_OF_INTEREST, QUESTIONS_COMMENTS, HOW_DID_YOU_HEAR_ABOUT_US)

VALUES('$_POST[txtname]','$_POST[txtemail]','$_POST[txthome_phone]','$_POST[txtcell_phone]','$_POST[txtbusines

s_phone]','$_POST[txtaddress]','$_POST[txtcity]','$_POST[txtstate]','$_POST[txtzip]','$_POST[txtinterest]','$_

POST[txtquestions]') ";


//execute query
mysql_query(($query) or die('Error, query failed'));
0
Comment
Question by:andrewaiello
  • 2
  • 2
4 Comments
 
LVL 28

Accepted Solution

by:
gamebits earned 1000 total points
ID: 16674422
$query = mysql_query("INSERT INTO form_data (`NAME`, `EMAIL`, `HOME_PHONE`, `CELL_PHONE`, `BUSINESS_PHONE`, `ADDRESS`, `CITY`, `STATE`, `ZIP`, `AREA_OF_INTEREST`, `QUESTIONS_COMMENTS`, `HOW_DID_YOU_HEAR_ABOUT_US`) VALUES ('$name', '$email', '$home_phone', '$cell_phone', '$business_phone', '$address', '$city', '$state', '$zip', '$interest', '$question','')");

You're missing the mysql_query statement and you have 12 fields in the query and only 11 values.

I had an empty value at the end of the query, you will have to put the variable name there.

gamebits
0
 
LVL 1

Author Comment

by:andrewaiello
ID: 16674543
OK, now there is data being inserted but its not the text box values.  The actual variable is being inserted.

The database is showing $_POST[txtname] $_POST[txtemail]......

How do i get the value that the user puts into the form to go into the db?
0
 
LVL 1

Author Comment

by:andrewaiello
ID: 16674560
I got it working now

thansk for the help
0
 
LVL 28

Expert Comment

by:gamebits
ID: 16674667
Thanks for the points and the grade.

Gamebits
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question