Php-mysql Form

software development

#1

i have made a phpscript the code follows:

<?php $con = mysql_connect("mysql.virtual-conflict.com","vc2006","******"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("test1", $con); $sql="INSERT INTO custinfo (FirstName, street1, street2, city, state, zip, country, phone, email, pw1, pw2, secret_answer) VALUES ('$_POST[firstname]','$_POST[surname]','$_POST[street1]','$_POST[street2]','$_POST[city]','$_POST[state]','$_POST[zip]','$_POST[country]','$_POST[phone]','$_POST[email]''$_POST[pw1]','$_POST[pw2]','$_POST[secret_answer]')"; { die('Error: ' . mysql_error()); } echo "1 record added";mysql_close($con) ?>

and i call this script in the html form. code follows

A little personal info please...

(See our privacy policy.)

First Name:

Last:

Street Address:


City:

State/Providence:

Zip Code:

Country:

united States United Kingdom

Phone:


Your current email:


(For login Use)


Choose password:


(6+characters 20 Max)


Re-type password:


What city were you born in?




I agree to abide by Virtual Conflicts Terms of Service and Anti-Spam Policy. Registration of domains requires acceptance of our Registration Terms.
You will also receive our monthly newsletter, which you may opt out of at any time.

its in a nicely laid out table but when i hit submit it says error nothing more and nothing less

bugging me to hell as i cant find out why

please help

Thanks
Si Wilson


#2

Can you show us the error message?

In the meanwhile, $_POST[firstname] should be $_POST[“firstname”]. same for the rest of $_POST

Save [color=#CC0000]$97[/color] (max discount) on dreamhost plans by using promo code: [color=#CC0000]97CRAZY[/color].


#3

the error message is just error. nothing more and nothing less


#4

ok here is the trick

$sql=“INSERT INTO custinfo (FirstName, street1, street2, city, state, zip, country, phone, email, pw1, pw2, secret_answer)
VALUES
(’$_POST[firstname]’,’$_POST[surname]’,’$_POST[street1]’,’$_POST[street2]’,’$_POST[city]’,’$_POST[state]’,’$_POST[zip]’,’$_POST[country]’,’$_POST[phone]’,’$_POST[email]’’$_POST[pw1]’,’$_POST[pw2]’,’$_POST[secret_answer]’)”;

[color=#CC0000]{
die('Error: ’ . mysql_error());
}[/color]

you call die function after your sql query. I guess there is missing “if-else” here. and you forgot to excute the sql query. It should be something like
[color=#0000CC]$result = mysql_query($sql); if (!$result){ die('Error: '.mysql_error());}[/color]

and your sql query can be simplified as
[color=#0000CC]$sql=“INSERT INTO custinfo
VALUES
(’$_POST[firstname]’,’$_POST[surname]’,’$_POST[street1]’,’$_POST[street2]’,’$_POST[city]’,’$_POST[state]’,’$_POST[zip]’,’$_POST[country]’,’$_POST[phone]’,’$_POST[email]’’$_POST[pw1]’,’$_POST[pw2]’,’$_POST[secret_answer]’)”;[/color]

remember to user doulbe codes in $_POST to retrieve the value of the variable as I mentioned in the last post. $_POST[“firstname”]

:stuck_out_tongue:

Save [color=#CC0000]$97[/color] (max discount) on dreamhost plans by using promo code: [color=#CC0000]97CRAZY[/color].