Hello,
Im making a simple news publishing deal, for my site...
Now, Ive made the Form.html
(So a user can fill it out, then hit submit)
Ive also made the next page 'handleform.php'
Ive provided the code for HandleForm.php below, and form.html...
Form.html, you shouldn't have too look at, I just threw it in there..
However, my question is this:
When I go to the form.html, fill it out, and hit submit, it gives me this error:
Parse error: parse error, unexpected T_VARIABLE in c:\program files\apache group\apache\htdocs\handleform.php on line 19
And Im not sure why it's giving me that error, because I read thru the code, and I found an error, but I did fix it, however, it didn't fix the error...
And just a tip, I have know db_username, or db_password
for any of my Databases...just so you guys know when you see it in the code.
_________________________________________________________
Here is the code for HandleForm.php
<html>
<head>
<Title>Inserting Data</title>
<body>
<?php
/* This page recieves and handles th e data
generated by "form.html". */
// Trim the incoming data.
$Array["FirstName"] = trim
($Array["FirstName"]);
$Array["LastName"] = trim
($Array["LastName"]);
$Array["Email"] = trim
($Array["Email"]);
$Array["Comments"] = trim
($Array["Comments"]);
$Host = "localhost"
$DBName = "New";
$TableName = "Feedback";
$Link = mysql_Connect ($localhost);
$Query = "INSERT into $TableName values
('0', '$Array[FirstName]',
'Array[LastName', 'Array[Email]',
'$Array[Comments]')";
print ("The query is:<BR>$Query<P>\n");
if (mysql_db_query($DBName, $Query,
$Link)) {
print ("The query was successfully
executed!<BR>\n");
} else {
print ("The query could not be
executed<BR>\n");
}
mysql_close($Link);
?>
</body>
</html>
___________________________________________________________
Here is the code for form.html
<HTML>
<HEAD>
<TITLE>HTML Form</title>
</HEAD>
<BODY>
<FORM ACTION="HandleForm.php" METHOD=POST>
First Name <INPUT TYPE=TEXT NAME="Array[FirstName]" SIZE=20><BR>
Last Name <INPUT TYPE=TEXT NAME="Array[LastName]" SIZE=40><BR>
Email Address <INPUT TYPE=TEXT NAME="Array[Email]" SIZE=60><BR>
Comments <TEXTAREA NAME="Array[Comments]" ROWS=5 COLS=40<TEXTAREA></textarea><br>
<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="SUBMIT!">
</FORM>
</BODY>
</HTML>
PHP - HandleForm.php not working [T_Variable Error
Moderator: General Moderators
- Pointybeard
- Forum Commoner
- Posts: 71
- Joined: Wed Sep 03, 2003 7:23 pm
- Location: Brisbane, AUS
- Contact:
Umm...if you looked at line 19 you would see that you are missing a semi-colon
That error you got is almost always because you forgot a semi-colon. 
Code: Select all
$Host = "localhost"
$DBName = "New";
$TableName = "Feedback";- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You are relying on register_globals being on for your script, since it is now off by default you should be using $_POST (if you are using PHP < 4.1 use $HTTP_POST_VARS) to get information posted via a form.
For example, if you changed the initial form to:
you could then do the following:
Mac
For example, if you changed the initial form to:
Code: Select all
<html>
<head>
<title>HTML Form</title>
</head>
<body>
<form action="HandleForm.php" method="post">
First name <input type="text" name="Firstname" size="20" /><br />
Last name <input type="text" name="Lastname" size="40" /><br />
Email Address <input type="text" name="Email" size="60" /><br />
Comments <textarea name="Comments" rows="5" cols="40"></textarea><br />
<input type="submit" name="submit" VALUE="SUBMIT!" />
</form>
</body>
</html>Code: Select all
<html>
<head>
<title>Inserting Data</title>
</head>
<body>
<?php
// loop through the $_POST array to trim() all data, makes life
// much easier than doing it element by element
foreach ($_POST as $key => $value) {
$_POST[$key] = trim($value);
}
$Host = "localhost";
$DBname = "New";
$Tablename = "Feedback";
$Link = mysql_connect($Host);
// you should never plug data directly into MySQL from a form without
// check that data first to ensure that no SQL injection or other
// problems are happening
$Query = "INSERT into $Tablename";
$Query .= "VALUES (0, '$_POST[Firstname]', '$_POST[Lastname]', '$_POST[Email]', '$_POST[Comments]')";
print '<p>The query is:<br />'.$Query.'</p>'."\n";
// mysql_db_query() is a deprecated function and has been for
// some time - you should be using mysql_select_db() and mysql_query()
// instead
@mysql_select_db($DBname) or die(mysql_error());
if (@mysql_query($Query)) {
print '<p>The query was successfully executed!</p>'."\n";
} else {
print '<p>The query could not be executed.</p>'."\n";
print '<p><b>MySQL Error</b>: '.mysql_error().'</br>';
print '<b>SQL Statement</b>: '.$Query.'</p>'."\n";
}
mysql_close($Link);
?>
</body>
</html>
Last edited by twigletmac on Tue Feb 03, 2004 2:26 am, edited 1 time in total.
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
hey why isnt this throwing up and error
from what i can see you have defined
and then you are using this to connect
when the variable $localhost doesnt exist?
from what i can see you have defined
Code: Select all
$Host = "localhost"
$DBName = "New";
$TableName = "Feedback";Code: Select all
$Link = mysql_Connect ($localhost);- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK