Schlo_50 Posted December 11, 2006 Share Posted December 11, 2006 Hello, my form here won't send anything to my database. I hit submit and the page reloads with the message 'Form not submitted Correctly' although im positively unsure why?? lol Please help!Here is the code:[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Order Form</title></head><body><center><form action="http://dombar0.freehostia.com/forms.php" method="post">Mr, Mrs, Miss: <select name="title" size="1" multiple="multiple"> <option value="Mr" selected>Mr</option> <option value="Mrs">Mrs</option> <option value="Miss">Miss</option> </select> <br>First Name: <input type="text" name="fname"><br>Surname: <input type="text" name="sname"><br>Address Line 1: <input type="text" name="adline1"><br>Address Line 2: <input type="text" name="adline2"><br>City:<input type="text" name="city"><br>Post Code: <input type="text" name="postcode"><br>Contact Number: <input type="text" name="hphone"><br>Email Address: <input type="text" name="email"><br><input type="Submit" name=submit value=Submit></form></center><?php$self=$_SERVER['PHP_SELF'];$title=$_POST['title'];$firstname=$_POST['fname'];$surname=$_POST['sname'];$addline1=$_POST['adline1'];$addline2=$_POST['adline2'];$city=$_POST['city'];$postcode=$_POST['postcode'];$contact=$_POST['hphone'];$email=$_POST['email'];$conn = mysql_connect( "host","username","password" ) or die( "Error Connecting to Db" );$rs = mysql_select_db( "dombar0_work", $conn ) or die( "Error selecting Db" ); $sql = "INSERT INTO 'cust_tbl' ( title,fname,sname,adline1,adline2,city,postcode,hphone,email ) VALUES ( \"$title\",\"$firstname\",\"$surname\",\"$addline\",\"$addline\",\"$city\",\"$postcode\",\"$contact\",\"$email\") )"; $rs = mysql_query( $sql, $conn ); if ($rs){ echo( "Order Form Complete $firstname!" ); }else { echo( "Form not submitted correctly!" ); } ?></body></html>[/code]Thanks! Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted December 11, 2006 Share Posted December 11, 2006 i dont no why your using \" in front of your variables. just use the plain ' and remove the \. you can add curly brackets around your variable {$var} like so. but otherwise check each variable... Quote Link to comment Share on other sites More sharing options...
fearmyride Posted December 11, 2006 Share Posted December 11, 2006 [quote author=ProjectFear link=topic=118165.msg482578#msg482578 date=1165838064]i dont no why your using \" in front of your variables. just use the plain ' and remove the \. you can add curly brackets around your variable {$var} like so. but otherwise check each variable...[/quote]i agree with ProjectFearand also why $rs = mysql_query( $sql, $conn );try without the $conn like:$rs = mysql_query( $sql);you already made the connection and selected the db Quote Link to comment Share on other sites More sharing options...
Schlo_50 Posted December 11, 2006 Author Share Posted December 11, 2006 I still can't get anything to load to the database! ??? Something is still wrong with it..[quote]<?php$self=$_SERVER['PHP_SELF'];$title=$_POST['title'];$firstname=$_POST['fname'];$surname=$_POST['sname'];$addline1=$_POST['adline1'];$addline2=$_POST['adline2'];$city=$_POST['city'];$postcode=$_POST['postcode'];$contact=$_POST['hphone'];$email=$_POST['email'];$conn = mysql_connect( "mysql2.freehostia.com","dombar0_work","password" ) or die( "Error Connecting to Db" );$rs = mysql_select_db( "dombar0_work", $conn ) or die( "Error selecting Db" );$sql = "INSERT INTO 'cust_tbl' VALUES ( '$title' '$firstname' '$surname' '$addline' '$addline' '$city' '$postcode' '$contact' '$email') )"; $rs = mysql_query( $sql); if ($rs){ echo( "Order Form Complete $firstname!" ); }else { echo( "Form not submitted correctly!" ); } ?>[/quote]Also, if you have a field in your database that is auto incrementing do you have to include that in your script in the 'INSERT INTO' bit? Quote Link to comment Share on other sites More sharing options...
craygo Posted December 11, 2006 Share Posted December 11, 2006 try using a little debugging tooladd this[code]$rs = mysql_query( $sql) or die ("Error with your query<br>SQL: ".$sql."<br>Error: ".mysql_error());[/code]Ray Quote Link to comment Share on other sites More sharing options...
swatisonee Posted December 11, 2006 Share Posted December 11, 2006 [quote]Also, if you have a field in your database that is auto incrementing do you have to include that in your script in the 'INSERT INTO' bit?[/quote]You do have to account for it but not in the insert into. Once you've got the sql worked out (as craygo said add the debugging tool), then try adding this :[code]$sql1="select max(cid) from 'cust_tbl' ";$result1 = mysql_query($sql1) or die (mysql_error());$myrow = mysql_fetch_row($result1);$cid = $myrow[0];[/code]You might also consider changing your form action to a simpler [code]<form method="post" action="forms.php">[/code] Quote Link to comment Share on other sites More sharing options...
simcoweb Posted December 11, 2006 Share Posted December 11, 2006 In your query line:[code]<?php$sql = "INSERT INTO 'cust_tbl' VALUES ( '$title' '$firstname' '$surname' '$addline' '$addline' '$city' '$postcode' '$contact' '$email') )";?>[/code]You need to separate those values with commas. Like this:[code]<?php$sql = "INSERT INTO 'cust_tbl' VALUES ( '$title', '$firstname', '$surname', '$addline', '$addline', '$city', '$postcode', '$contact', '$email') )";?>[/code]Also, in this line:[code]<?php$rs = mysql_select_db( "dombar0_work", $conn ) or die( "Error selecting Db" );?>[/code]It says your database name is the same as your password ( "dombar0_work" for both ). Is that correct? If either is wrong then it won't work. Quote Link to comment Share on other sites More sharing options...
Schlo_50 Posted December 11, 2006 Author Share Posted December 11, 2006 User names and passwords are all correct.Still can't really find the problem though, im not sure how to use some of your solutions to fix my problem..lolI may just re-code the lot from scratch.. :o Quote Link to comment Share on other sites More sharing options...
simcoweb Posted December 11, 2006 Share Posted December 11, 2006 Ok, so you're saying the database 'name' and the database 'password' are indeed the same text? Honestly that would be unusual but not unheard of.In regards to the fixes, did you add the commas as I pointed out? Quote Link to comment Share on other sites More sharing options...
Schlo_50 Posted December 11, 2006 Author Share Posted December 11, 2006 Well thats what i have so far, but no can do..lol Unless you want to reise it for me! ha ha[quote]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Order Form</title></head><body><center><form action="http://dombar0.freehostia.com/forms.php" method="post">Mr, Mrs, Miss: <select name="title" size="1" multiple="multiple"> <option value="Mr" selected>Mr</option> <option value="Mrs">Mrs</option> <option value="Miss">Miss</option> </select> <br>First Name: <input type="text" name="fname"><br>Surname: <input type="text" name="sname"><br>Address Line 1: <input type="text" name="adline1"><br>Address Line 2: <input type="text" name="adline2"><br>City:<input type="text" name="city"><br>Post Code: <input type="text" name="postcode"><br>Contact Number: <input type="text" name="hphone"><br>Email Address: <input type="text" name="email"><br><input type="Submit" name=submit value=Submit></form></center><?php$self=$_SERVER['PHP_SELF'];$title=$_POST['title'];$firstname=$_POST['fname'];$surname=$_POST['sname'];$addline1=$_POST['adline1'];$addline2=$_POST['adline2'];$city=$_POST['city'];$postcode=$_POST['postcode'];$contact=$_POST['hphone'];$email=$_POST['email'];$conn = mysql_connect( "mysql2.freehostia.com","dombar0_work","password" ) or die( "Error Connecting to Db" );$rs = mysql_select_db( "dombar0_work", $conn ) or die( "Error selecting Db" );$sql = "INSERT INTO 'cust_tbl' VALUES ( '$title', '$firstname', '$surname', '$addline', '$addline', '$city', '$postcode', '$hphone', '$email') )"; $rs = mysql_query( $sql); if ($rs){ echo( "Order Form Complete $firstname!" ); }else { echo( "Form not submitted correctly!" ); } ?> [/quote]</body></html> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 11, 2006 Share Posted December 11, 2006 Please edit your post and change the [nobbc][quote] and [/quote] tags to [code] and [/code] tags [/nobbc]. This will make your code more readable.Ken Quote Link to comment Share on other sites More sharing options...
Schlo_50 Posted December 11, 2006 Author Share Posted December 11, 2006 I modified the post ages ago..This is my now revised code, but now get the error message:'Parse error: parse error, unexpected T_VARIABLE in /home/www/dombar0.freehostia.com/form2.php on line 43'I thought this was because i have missed a ; or space somewhere but can't see it..[quote]<html><head><title>Order Form</title></head><body><form action="http://dombar0.freehostia.com/form2.php" method="post">Mr, Mrs, Miss: <select name="title" size="1" multiple="multiple"> <option value="Mr" selected>Mr</option> <option value="Mrs">Mrs</option> <option value="Miss">Miss</option> </select> <br>First Name: <input type="text" name="firstname"><br>Surname: <input type="text" name="surname"><br>Address Line 1: <input type="text" name="addline1"><br>Address Line 2: <input type="text" name="addline2"><br>City:<input type="text" name="city"><br>Post Code: <input type="text" name="postcode"><br>Contact Number: <input type="text" name="hphone"><br>Email Address: <input type="text" name="email"><br><input type="Submit" name=submit value=Submit></form><?php$self = $_SERVER['PHP_SELF'];$title = $_POST['title'];$firstname = $_POST['firstname'];$surname = $_POST['surname'];$addline1 = $_POST['addline1'];$addline2 = $_POST['addline2'];$city = $_POST['city'];$postcode = $_POST['postcode'];$hphone = $_POST['hphone'];$email = $_POST['email'];{ $conn = @mysql_connect( "mysql2.freehostia.com", "dombar0_work", "password" ) or die("Could not connect to MySQL"); $db = @mysql_select_db( "dombar0_work", $conn ) or die("Could not select a database"); $sql = "INSERT INTO 'cust_tbl' (title,fname,sname,adline1,adline2,city,postcode,hphone,email) VALUES ( "$title", "$firstname", "$surname", "$addline1", "$addline2", "$city", "$postcode", "$hphone", "$email" )"; $result = @mysql_query( $sql ) or die("Could not execute the query"); if( $result ) { echo( "Order form complete $firstname!" ); } }?></body></html>[/quote]Thanks for all your help and patience guys! ;) Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted December 12, 2006 Share Posted December 12, 2006 wrap it in [code=php:0][/code] or [code][/code]. but why do you have so much spaces between your variables.[code=php:0]$self = $_SERVER['PHP_SELF'];$title = $_POST['title'];$firstname = $_POST['firstname'];$surname = $_POST['surname'];$addline1 = $_POST['addline1'];$addline2 = $_POST['addline2'];$city = $_POST['city'];$postcode = $_POST['postcode'];$hphone = $_POST['hphone'];$email = $_POST['email'];[/code] Quote Link to comment Share on other sites More sharing options...
btherl Posted December 12, 2006 Share Posted December 12, 2006 The parse error you're getting is because you are using " inside your query, but " also starts and ends your query. Unfortunately I don't know mysql syntax all that well, so I can't tell you how to fix it. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted December 12, 2006 Share Posted December 12, 2006 around cust_tbl you have ' but you should have `. not sure if that will fix it though. change the " around the variables in your query to ' as well. which is what btherl said. Quote Link to comment Share on other sites More sharing options...
swatisonee Posted December 12, 2006 Share Posted December 12, 2006 Am having a problem posting to this topic. let me see if i can send the script as an attachmentYou need to consider putting all db info. in a separate file and sending it up as a header. file:info.php[code]<?$dbservertype='mysql';$servername='localhost';$dbusername=whatever;$dbpassword='whatever';$dbname='whatever';connecttodb($servername,$dbname,$dbusername,$dbpassword);function connecttodb($servername,$dbname,$dbuser,$dbpassword){global $link;$link=mysql_connect ("$servername","$dbuser","$dbpassword");if(!$link){die("Could not connect to MySQL");}mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());}?>[/code]Then your file form.php[code]<?include "info.php";?><html><head><title>Order Form</title></head><body><form action="form2.php" method="post">Mr, Mrs, Miss: <select name="title" size="1" multiple="multiple"> <option value="Mr" selected>Mr</option> <option value="Mrs">Mrs</option> <option value="Miss">Miss</option> </select> First Name: <input type="text" name="firstname">Surname: <input type="text" name="surname">Address Line 1: <input type="text" name="addline1">Address Line 2: <input type="text" name="addline2">City:<input type="text" name="city">Post Code: <input type="text" name="postcode">Contact Number: <input type="text" name="hphone">Email Address: <input type="text" name="email"><input type="Submit" name=submit value=Submit></form><?php $self = $_SERVER['PHP_SELF']; // remove all those extra spaces ..see title below$title = $_POST['title'];$firstname = $_POST['firstname'];$surname = $_POST['surname'];$addline1 = $_POST['addline1'];$addline2 = $_POST['addline2'];$city = $_POST['city'];$postcode = $_POST['postcode'];$hphone = $_POST['hphone'];$email = $_POST['email'];$sql = "INSERT INTO 'cust_tbl' (title,fname,sname,adline1,adline2,city,postcode,hphone,email) VALUES ( '$title', "$firstname", "$surname", "$addline1", "$addline2", "$city", "$postcode", "$hphone", "$email" )";// use single quotes - see $title) $result = mysql_query( $sql ) or die (mysql_error()) ; // error reporting is important and remove the @echo "information entered" ;// at this point , consider another sql to autoincrement the records as i had posted earlier. ?></body></html>[/code] Quote Link to comment Share on other sites More sharing options...
fearmyride Posted December 12, 2006 Share Posted December 12, 2006 [code]$sql = "INSERT INTO 'cust_tbl' (title,fname,sname,adline1,adline2,city,postcode,hphone,email) VALUES ( "$title", "$firstname", "$surname", "$addline1", "$addline2", "$city", "$postcode", "$hphone", "$email" )";[/code]on the second part of the query after VALUES ("... you cannot use double quotes, change those to single quotes for each variable, the code below should not produce and parsing problems[code]$sql = "INSERT INTO cust_tbl (title, fname, sname, adline1, adline2, city, postcode, hphone, email) VALUES ( '$title', '$firstname', '$surname', '$addline1', '$addline2', '$city', '$postcode', '$hphone', '$email' )";[/code]i can see that all of your variables are strings, but if they weren't you don't have to use any quotes in the query line like the postcode for US will not be a string and you can query it without any quotes.The other thing is when you use double quotes "" you cannot use anymore double quotes inside of them and expect it to work.Hope this help Quote Link to comment Share on other sites More sharing options...
swatisonee Posted December 12, 2006 Share Posted December 12, 2006 ok i modified reply no. 15. Quote Link to comment Share on other sites More sharing options...
Schlo_50 Posted December 12, 2006 Author Share Posted December 12, 2006 Warning: mysql_query(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /home/www/dombar0.freehostia.com/form2.php on line 50Warning: mysql_query(): A link to the server could not be established in /home/www/dombar0.freehostia.com/form2.php on line 50Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)This is the error recieved with swatisonne's help with the code. Im sure everything has been done that you suggested.This is line 50:[quote]$result = mysql_query( $sql ) or die (mysql_error()) ; [/quote] Quote Link to comment Share on other sites More sharing options...
simcoweb Posted December 12, 2006 Share Posted December 12, 2006 change the $servername variable:[quote]$servername = 'localhost';[/quote]To:[quote]$servername = 'mysql2.freehostia.com';[/quote]And, i'm assuming you inserted the correct data into those other variables as well? :P Quote Link to comment Share on other sites More sharing options...
Schlo_50 Posted December 12, 2006 Author Share Posted December 12, 2006 That was not my post. I have already inserted the correct $servername and relevent details. Quote Link to comment Share on other sites More sharing options...
swatisonee Posted December 14, 2006 Share Posted December 14, 2006 The code is ok but for sure its a connection problem. you need to recheck the variables on the mysql connection. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.