Jump to content

form help new to php


Justafriend

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/277249-form-help-new-to-php/
Share on other sites

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 pagepost-82596-0-49133800-1366808001_thumb.pngpost-82596-0-57920400-1366808025_thumb.png

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);
}

?>

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());

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.