Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php code won't write form data to database table - help please!!

Status
Not open for further replies.

jacksondorado

IS-IT--Management
Joined
Apr 12, 2001
Messages
135
Location
US
Hi,

My webpage form submits and emails the data no problem but the data does not write to the table in the database. I can't figure our why. I used a textbook example that works for me and just changed the variables. Any help would be appreciated.

Here is the code piece of code that is supposed to write to the table:

//////////////////////////////////////////////////////////
$dbh=mysql_connect ("localhost", "user", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("$database");

$connection = mysql_connect($host,$user,$password) or die ("Couldn't connect to server.");
$db = mysql_select_db($database, $connection)
or die ("Couldn't select database.");

$sql = "INSERT INTO table (a1001_date_of_your_visit,
a1002_time_of_visit,
a1003_server_name,
a1004_restaurant,
a1005_recommend_to_others,
a1006_dined_at_before,
a1007_host_greeting,
a1008_food_quality_appeal,
a1009_server_experience,
a1010_ambiance_environment,
a1011_beverages,
a1012_price_value,
a1013_comments,
a1014_first_name,
a1015_last_name,
a1016_phone_number,
a1017_best_time_to_reach_me,
a1018_email,
a1019_street_line_1,
a1020_street_line_2,
a1021_city,
a1022_state,
a1023_zip_code) VALUES
('$z1001_date_of_your_visit',
('$z1001_date_of_your_visit',
('$z1002_time_of_visit',
('$z1003_server_name',
('$z1004_restaurant',
('$z1005_recommend_to_others',
('$z1006_dined_at_before',
('$z1007_host_greeting',
('$z1008_food_quality_appeal',
('$z1009_server_experience',
('$z1010_ambiance_environment',
('$z1011_beverages',
('$z1012_price_value',
('$z1013_comments',
('$z1014_first_name',
('$z1015_last_name',
('$z1016_phone_number',
('$z1017_best_time_to_reach_me',
('$z1018_email',
('$z1019_street_line_1',
('$z1020_street_line_2',
('$z1021_city',
('$z1022_state',
('$z1023_zip_code')";
 
I see code which connects to the database, selects the appropriate database, and compiles the SQL statement.

Where's the code that hands the query to the database server and then checks for any errors?



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I am a novice to PHP so I tried my best to replicate a working example.

I have these two statements after the above code:

mysql_query($sql);
$auth="yes";
 
I'm not sure. It's from the Dummies PHP & MySQL book. It just says that mysql_query($sql); "Executes the INSERT query".

I posted the working Dummies code here:

I posted my code that sends an email with the data but does not write to the database here:

thanks for the help.
 
Allow me to point out to you the single most important information resource on the PHP programming language:

In specific, I invite you to examine the manual entry for mysql_query().

mysql_query() returns a value -- every PHP function returns a value. Capture that value and test it, or at least put an "or die(mysql_error())" after your invocation of mysql_query().

I also have a FAQ on debugging PHP scripts, which contains a section on debugging database code. Your problem might also have something to do with the register_globals runtime configuration directive. FAQ434-2999



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Wow,

I am sorry for being so careless but I am really new to using SQL and PHP.

Like nearly every other computing problem it was something simple that I overlooked. I did not realize that I had an opening parentheses before every value to be inserted in the table.

Now it works.

thanks for the help!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top