Jump to content

Error on input of data with form


lucy

Recommended Posts

I am trying to get a form to input data to my MYSQL database but im having a little trouble.

 

I have created a php file called custentry.html which holds the form. I have also created another php file called custentry.php which holds the script for connecting to the database and entering the data which has been entered on the html file.

 

Whenever i try to enter the data i get the following message:

" Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/sites/foo/public_html/test/php/custentry.php on line 14 "

 

I cant figure out what is wrong with my code.

 

Here is the html file:

<body>
<form action="php/custentry.php" method="post">
  <p>Title:
    <input type="text" name="title" />
  </p>
  <p>
    <input type="reset" name="clear" id="clear" value="Reset" />
    <input type="submit" name="submit" id="submit" value="Submit" />
  </p>
  <p> </p>
</form>
</body>

 

and here is the php file (with the database name and password and user taken out):

<?

$user="OMITTED"; //specially created username
$password="OMITTED";
$database="OMITTED;

//connect to the database
$con = mysql_connect("localhost",$user,$password) or die ('Could not connect: ' . mysql_error());

//select the database
mysql_select_db($database, $con);

//insert data into database
mysql_query("INSERT INTO customer VALUES ($_POST['title'])") or die('Error: ' . mysql_error());

//close connection
mysql_close();

echo "entered data!";


?>

 

Could someone please suggest why i am getting that message?

 

Thanks,

Lucy

 

Link to comment
https://forums.phpfreaks.com/topic/168922-error-on-input-of-data-with-form/
Share on other sites

Thanks for your help, ive just fixed the problem.

 

the missing " was a typo, sorry, my bad. the original form has the second " in.

 

The problem was '$_POST['title']', i had put extra speech marks in the title part, where it should have only been, '$_POST[title]'.

 

Thanks,

Lucy

  • 2 weeks later...

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.