Jump to content

form help new to php


Justafriend
Go to solution Solved by gristoi,

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
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

Link to comment
Share on other sites

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

?>

Link to comment
Share on other sites

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 by gristoi
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by Justafriend
Link to comment
Share on other sites

  • Solution

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.