Forum Moderators: coopster
Parse error: syntax error, unexpected T_STRING in C:\apachefriends\xampp\htdocs\reserve.php on line 24
// If the form has been submitted
<?php
if(isset($_GET['commented']))
{
// Tell the user it has been submitted (optional)
echo('Thank you for your reservation.');
// Set Mysql Variables
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'books';
$table = 'customers';
$surname=$_GET['name'];
$forename=$_GET['Fname'];
$tel=$_GET['Tel'];
$email=$_GET['email'];
mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
$add_all = INSERT INTO $table values('$surname','$forename','$tel','$email');
mysql_query($add_all) or die(mysql_error());
}
else
{
// If the form has not been submitted, display it!
?>
<form method='get' action='<? echo'$PHP_SELF';?>'>
<br><font face="Verdana"><font size=-1>ISBN -</font></font>
<br><font face="Verdana"><font size=-1>Price -</font></font>
<p><font face="Verdana"><font size=-1>Surname</font></font><input NAME = "name" TYPE = "text" SIZE = "25" MAXLENGTH = "20">
<p><font face="Verdana"><font size=-1>Forename</font></font><input NAME = "FName" TYPE = "text" SIZE = "25" MAXLENGTH = "20">
<p><font face="Verdana"><font size=-1>Tel N.o.</font></font><input NAME = "Tel" TYPE = "text" SIZE = "25" MAXLENGTH = "12">
<p><font face="Verdana"><font size=-1>e-Mail address</font></font><input NAME = "email" TYPE = "text" SIZE = "25" MAXLENGTH = "35">
<p><font face="Verdana"><font size=-1>Date picking up</font></font><input NAME = "date" TYPE = "text" SIZE = "5" MAXLENGTH = "8">
<input type='submit' value='Reserve your book'>
</form>
<?
}
?>
Any ideas as I can't figure it out?
// If the form has been submitted
<?php
if(isset($_GET['commented']))
{
// Tell the user it has been submitted (optional)
echo('Thank you for your reservation.');
// Set Mysql Variables
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'books';
$table = 'customers';
$surname=$_GET['name'];
$forename=$_GET['Fname'];
$tel=$_GET['Tel'];
$email=$_GET['email'];
mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
$add_all = "INSERT INTO $table values('$surname','$forename','$tel','$email')";
mysql_query($add_all) or die(mysql_error());
}
else
{
// If the form has not been submitted, display it!
?>
<form method='get' action='<? echo'$PHP_SELF';?>'>
<br><font face="Verdana"><font size=-1>ISBN -</font></font>
<br><font face="Verdana"><font size=-1>Price -</font></font>
<p><font face="Verdana"><font size=-1>Surname</font></font><input NAME = "name" TYPE = "text" SIZE = "25" MAXLENGTH = "20">
<p><font face="Verdana"><font size=-1>Forename</font></font><input NAME = "FName" TYPE = "text" SIZE = "25" MAXLENGTH = "20">
<p><font face="Verdana"><font size=-1>Tel N.o.</font></font><input NAME = "Tel" TYPE = "text" SIZE = "25" MAXLENGTH = "12">
<p><font face="Verdana"><font size=-1>e-Mail address</font></font><input NAME = "email" TYPE = "text" SIZE = "25" MAXLENGTH = "35">
<p><font face="Verdana"><font size=-1>Date picking up</font></font><input NAME = "date" TYPE = "text" SIZE = "5" MAXLENGTH = "8">
<input type='submit' value='Reserve your book'>
</form>
<?
}
?>
Everything seems fine, the database and table are correct and the hostname, username and password are correct too as I have used this on another page.
$add_all = "INSERT INTO $table (surname, forename, tel, email) VALUES('$surname','$forename','$tel','$email')";
I would also do
$email = add_slashes($_GET["surname"]); to be on the safer side
Best regards
Michal Cibor
if(isset($_GET['commented']))
I don't see that represented anywhere. I figured there was nothing from the dies. It is not that the insert doesn't work but my guess is it just isn't ending up in the right part of the if statement.
ok, so let's fix that test. First thing is I would change your method to post in your form, you don't really want to pass all of that jun in the url, better posted. You also will want to change your submit button a little from
<input type='submit' value='Reserve your book'>
to
<input type='submit' name='reserve' value='Reserve your book'>
adding the name will allow for you to test for it's existence in the $_POST array. You also have an error in your action, this should be giving you a 404.
<form method='get' action='<? echo'$PHP_SELF';?>'>
with the single quotes around the php_self it shouldn't even resolve the variable. When you echo vars only they don't need to be surrounded by any type of quotes, if you are mixing string data and vars and want them to resolve then you need to surround them with double quotes. You form tag should look like so (with the post change as well)
<form method='post' action='<? echo $_SERVER['PHP_SELF'];?>'>
that is also using the $_SERVER array instead of the register_globals on version like $PHP_SELF, ultimately you will need to turn off register_globals anyway. Nopw when you test instead of
if(isset($_GET['commented'])) {
use
if(isset($_POST['reserve'])) {
now we are testing for the existence of the submit button in the $_POST array.
try that