Justafriend Posted April 24, 2013 Share Posted April 24, 2013 ok so i followed a tutorial and cant figure out why this code is not working when i use on server on pc i get a Parse error: syntax error, unexpected T_STRING in C:\wamp\www\insertform.php on line 14 error when i use on my hostgator i just get a blank page any help would be greatly appreciated i changed the pw for posting to password if that does make a difference i can change it back <html> <head> </head> <body> <form action="insertform.php" method="post"> SHG Player Name: <input type="text" name="playername"> Email Address: <input type="text" name="email"> <input type="submit" name="submit" </form> <?php if (isset($_POST['submit'])){ $con=mysql_connect("localhost","dbs_dbs","password"); die(Can not connect: " . mysql_error()); mysql_select_db("dbs_forms",$con); $sql = "INSERT INTO emails(player_name,email)('$_POST[playername]','$_POST[email]')"; mysql_query($sql,$con); mysql_close($con); } ?> </body> </html> ty confuzzled Quote Link to comment Share on other sites More sharing options...
gristoi Posted April 24, 2013 Share Posted April 24, 2013 2 things: 1: <input type="submit" name="submit" // should be <input type="submit" name="submit" /> and: die(Can not connect: " . mysql_error()); // should be die("Can not connect: " . mysql_error()); Quote Link to comment Share on other sites More sharing options...
Justafriend Posted April 24, 2013 Author Share Posted April 24, 2013 Ok thank you that fixed those errors now i got another problem the page shows the form then right below it says can not connect below it i tried the pw to make sure but if i change it to something else it gives me a total different error attached is a screenshot of my db and the error on the page Quote Link to comment Share on other sites More sharing options...
jugesh Posted April 24, 2013 Share Posted April 24, 2013 paste php code top of your page and connection should be declared on top: <?php $con=mysql_connect("localhost","dbs_dbs","password");die("Can not connect: " . mysql_error());mysql_select_db("dbs_forms",$con); if (isset($_POST['submit'])){$sql = "INSERT INTO emails(player_name,email)('$_POST[playername]','$_POST')";mysql_query($sql,$con);mysql_close($con);}?> Quote Link to comment Share on other sites More sharing options...
gristoi Posted April 24, 2013 Share Posted April 24, 2013 (edited) ok firstly, jugesh is wrong, when it comes to mixing html and php on a page, if the php is not outputting ( rendering anything then it is irrelevant where it is on the page ) the reason you are getting this error is because you are manyally killing the script: $con=mysql_connect("localhost","dbs_dbs","password"); die("Can not connect: " . mysql_error()); needs to be $con=mysql_connect("localhost","dbs_dbs","password") or die("Can not connect: " . mysql_error()); Edited April 24, 2013 by gristoi Quote Link to comment Share on other sites More sharing options...
jugesh Posted April 24, 2013 Share Posted April 24, 2013 Yeh.. i Missed that part thanks Gristoi Quote Link to comment Share on other sites More sharing options...
Justafriend Posted April 24, 2013 Author Share Posted April 24, 2013 thank you both error 2 gone now testing it its not inputting into tablecould it have to do with me haing a primary id not listed in the php script i get no errors but the table isnt updating which is why i was wondering that Quote Link to comment Share on other sites More sharing options...
gristoi Posted April 24, 2013 Share Posted April 24, 2013 do $sql = "INSERT INTO emails(`player_name`,`email`)('{$_POST[playername]}','{$_POST[email]}')"; mysql_query($sql,$con) or die(mysql_error()); that should give you some inkling as to whats wrong. Also make sure you have the primary key set to auto incriment Quote Link to comment Share on other sites More sharing options...
Justafriend Posted April 24, 2013 Author Share Posted April 24, 2013 (edited) ok this is the result i get i have a funny feeling its cause the table had to have varchar instead of text You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''playername','email')('test','test')' at line 1 my suspicion and pls correct me if im wrong but checking google and i came across where someone had the same issue cause they had 'price' and it was a numeric value but is there a special way i have to put it for varchar im just grasping at straws i am about to go bald here but i do really appreciate all your help edit yes i checked to make sure the primary key id is set to auto increment Edited April 24, 2013 by Justafriend Quote Link to comment Share on other sites More sharing options...
Solution gristoi Posted April 24, 2013 Solution Share Posted April 24, 2013 ok, firstly, my bad. query should read: $sql = "INSERT INTO emails(`player_name`,`email`) values ('{$_POST['playername']}','{$_POST['email']}')"; pay very close attention to the tick marks surrounding player_name and email. they have to be backticks --> ` <--- not single apostrophes -->'<-- so they should be `player_name` NOT 'player_name' .a varchar and text field can both accept nubmers and characters. your sql error is telling you that you have a syntax error, which is what i have described above. Quote Link to comment Share on other sites More sharing options...
Justafriend Posted April 24, 2013 Author Share Posted April 24, 2013 good news working for inputting it but now its inputting duplicate rows Quote Link to comment Share on other sites More sharing options...
Justafriend Posted April 24, 2013 Author Share Posted April 24, 2013 whoohoon i fixed it it is now working perfectly ty so much for all your help 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.