View Full Version : Hate Parse Errors [PHP]
jw06
December 13th, 2004, 11:14 AM
Ok, I've tried everything I can think of with this script.... Maybe I've looked at it to much and have just overlooked it.
I get this:
Parse error: parse error in /webdirectory/admin_add.php on line 30
<html>
<head>
<title>Add Scholarship Entry</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
#This script is to add scholarships into the database.
#admin_add.php
#Address error handling. Tell us if there is an error.
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
#Handle the form
if (isset ($_POST['submit'])) { #This checks if submit has been clicked.
#Connect and select the database
if ($dbc = @mysql_connect ('localhost', 'root', '')) {
if (!@mysql_select_db ('scholarships')) {
die ('<p>Could not select the database because: <b>' . mysql_error() . '</b></p>');
}
} else { #Cant connect to MySQL
die ('<p>Could not connect to MySQL because: <b>' . mysql_error() . '</b></p>');
}
#Define the query
$query = "INSERT INTO scholarships (id, title, org, description, type, eligibility, decision, minimum, maximum, deadline, address, phone, site, keywords, date_entered)
VALUES (0, '$_POST[title]', '$_POST[org]', '$_POST[description]', '$_POST[type]', '$_POST[eligibility]', '$_POST[decision]', '$_POST[minimum]', '$_POST[maximum]', '$_POST[deadline]', '$_POST[address]', '$_POST[phone]', '$_POST[site]', '$_POST[keywords]', NOW())";
#Execute the query
if (@mysql_query ($query)) {
echo '<p>The ' . {$_POST['title']} . ' Scholarship has been added to the database</p>';
} else {
print '<p>Could not add the entry because: <b>' . mysql_error() . '</b></p>';
}
mysql_close(); #Close the connection to MySQL
}
#Display the HTML Form Below
?>
<br>
<form name="form1" method="post" action="admin_add.php">
<table width="70%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="27%">Award Name:</td>
<td width="73%" align="center"> <input name="title" type="text" id="title" size="50" maxlength="100"></td>
</tr>
<tr>
<td>Organization:</td>
<td align="center"><input name="org" type="text" id="org" size="50" maxlength="100"></td>
</tr>
<tr>
<td>Description:</td>
<td align="center"><textarea name="description" cols="50" rows="6" id="description"></textarea></td>
</tr>
<tr>
<td>Type:</td>
<td align="center"><input name="type" type="text" id="type" size="50" maxlength="100"></td>
</tr>
<tr>
<td>Eligibility:</td>
<td align="center"><textarea name="eligibility" cols="50" rows="6" id="eligibility"></textarea></td>
</tr>
<tr>
<td>Decision:</td>
<td align="center"><input name="decision" type="text" id="decision" size="50" maxlength="200"></td>
</tr>
<tr>
<td>Minimum:</td>
<td align="center"><input name="minimum" type="text" id="minimum" size="50" maxlength="30"></td>
</tr>
<tr>
<td>Maximim:</td>
<td align="center"><input name="maximum" type="text" id="maximum" size="50" maxlength="30"></td>
</tr>
<tr>
<td>Deadline:</td>
<td align="center"><input name="deadline" type="text" id="deadline" size="50" maxlength="50"></td>
</tr>
<tr>
<td>Address:</td>
<td align="center"><input name="address" type="text" id="address" size="50" maxlength="150"></td>
</tr>
<tr>
<td>Phone:</td>
<td align="center"><input name="phone" type="text" id="phone" size="50" maxlength="12"></td>
</tr>
<tr>
<td>Web Site:</td>
<td align="center"><input name="site" type="text" id="site" size="50" maxlength="100"></td>
</tr>
<tr>
<td>Keywords:</td>
<td align="center"><input name="keywords" type="text" id="keywords" size="50" maxlength="100"></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="submit" value="Add Scholarship">
</div></td>
</tr>
</table>
</form>
</body>
</html>
Thanks in advance!
CyanBlue
December 13th, 2004, 11:19 AM
Howdy... :)
Try combining line 29 and 30 and see if it works... :)
In a nutshell this is what you have...
$somevar = "hello blah blah
more blah blah blah bleh bleh";
which should be written like this...
$somevar = "hello blah blah more blah blah blah bleh bleh";
jw06
December 13th, 2004, 11:24 AM
Like this?
$query = "INSERT INTO scholarships (id, title, org, description, type, eligibility, decision, minimum, maximum, deadline, address, phone, site, keywords, date_entered) VALUES (0, '$_POST[title]', '$_POST[org]', '$_POST[description]', '$_POST[type]', '$_POST[eligibility]', '$_POST[decision]', '$_POST[minimum]', '$_POST[maximum]', '$_POST[deadline]', '$_POST[address]', '$_POST[phone]', '$_POST[site]', '$_POST[keywords]', NOW())";
I've already combined it like that....
CyanBlue
December 13th, 2004, 11:57 AM
Oh... Change this...
'$_POST[title]'
to this...
$_POST['title']
which should be applied to all of your variables... :)
jw06
December 15th, 2004, 10:46 AM
Ok, I am getting a NEW PARSE ERROR! its better then what it was, this one is a bit more descriptive you could say:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /webdirectory/admin_add.php on line 25
<html>
<head>
<title>Add Scholarship Entry</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
#This script is to add scholarships into the database.
#admin_add.php
#Address error handling. Tell us if there is an error.
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
#Handle the form
if (isset ($_POST['submit'])) { #This checks if submit has been clicked.
#Connect and select the database
if ($dbc = @mysql_connect ('localhost', 'root', 'sqldb')) {
if (!@mysql_select_db ('scholarships')) {
die ('<p>Could not select the database because: <b>' . mysql_error() . '</b></p>');
}
} else { #Cant connect to MySQL
die ('<p>Could not connect to MySQL because: <b>' . mysql_error() . '</b></p>');
}
#Define the query
$query = "INSERT INTO scholarships (id, title, org, description, type, eligibility, decision, minimum, maximum, deadline, address, phone, site, keywords, date_entered) VALUES (0, '$_POST['title]', '$_POST['org']', '$_POST['description']', '$_POST['type']', '$_POST['eligibility']', '$_POST['decision']', '$_POST['minimum']', '$_POST['maximum']', '$_POST['deadline']', '$_POST['address']', '$_POST['phone']', '$_POST['site']', '$_POST['keywords']', NOW())";
#Execute the query
if (@mysql_query ($query)) {
echo '<p>The ' . {$_POST['title']} . ' Scholarship has been added to the database</p>';
} else {
print '<p>Could not add the entry because: <b>' . mysql_error() . '</b></p>';
}
mysql_close(); #Close the connection to MySQL
}
#Display the HTML Form Below
?>
<br>
<form name="form1" method="post" action="admin_add.php">
<table width="70%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="27%">Award Name:</td>
<td width="73%" align="center"> <input name="title" type="text" id="title" size="50" maxlength="100"></td>
</tr>
<tr>
<td>Organization:</td>
<td align="center"><input name="org" type="text" id="org" size="50" maxlength="100"></td>
</tr>
<tr>
<td>Description:</td>
<td align="center"><textarea name="description" cols="50" rows="6" id="description"></textarea></td>
</tr>
<tr>
<td>Type:</td>
<td align="center"><input name="type" type="text" id="type" size="50" maxlength="100"></td>
</tr>
<tr>
<td>Eligibility:</td>
<td align="center"><textarea name="eligibility" cols="50" rows="6" id="eligibility"></textarea></td>
</tr>
<tr>
<td>Decision:</td>
<td align="center"><input name="decision" type="text" id="decision" size="50" maxlength="200"></td>
</tr>
<tr>
<td>Minimum:</td>
<td align="center"><input name="minimum" type="text" id="minimum" size="50" maxlength="30"></td>
</tr>
<tr>
<td>Maximim:</td>
<td align="center"><input name="maximum" type="text" id="maximum" size="50" maxlength="30"></td>
</tr>
<tr>
<td>Deadline:</td>
<td align="center"><input name="deadline" type="text" id="deadline" size="50" maxlength="50"></td>
</tr>
<tr>
<td>Address:</td>
<td align="center"><input name="address" type="text" id="address" size="50" maxlength="150"></td>
</tr>
<tr>
<td>Phone:</td>
<td align="center"><input name="phone" type="text" id="phone" size="50" maxlength="12"></td>
</tr>
<tr>
<td>Web Site:</td>
<td align="center"><input name="site" type="text" id="site" size="50" maxlength="100"></td>
</tr>
<tr>
<td>Keywords:</td>
<td align="center"><input name="keywords" type="text" id="keywords" size="50" maxlength="100"></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="submit" value="Add Scholarship">
</div></td>
</tr>
</table>
</form>
</body>
</html>
CyanBlue
December 15th, 2004, 11:40 AM
Maybe that error has to do with the single equal sign(=) in line 20??? That has to be double equal sign(==), I think... Try that... :)
adamd
December 15th, 2004, 09:12 PM
echo '<p>The ' . {$_POST['title']} . ' Scholarship has been added to the database</p>';
Why do you have the curly brackets in the concatenated string above?
Also, one thing to keep in mind is that the parser will not allways throw an error on the same line the error actually occurrs.
jw06
December 17th, 2004, 09:58 AM
:( its still doing it after some modifications :(
<html>
<head>
<title>Add Scholarship Entry</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
#This script is to add scholarships into the database.
#admin_add.php
#Address error handling. Tell us if there is an error.
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
#Handle the form
if (isset ($_POST['submit'])) { #This checks if submit has been clicked.
#Connect and select the database
if ($dbc = @mysql_connect ('localhost', 'root', 'sqldb')) {
if (!@mysql_select_db ('scholarships')) {
die ('<p>Could not select the database because: <b>' . mysql_error() . '</b></p>');
}
} else { #Cant connect to MySQL
die ('<p>Could not connect to MySQL because: <b>' . mysql_error() . '</b></p>');
}
#Define the query
$query = "INSERT INTO scholarships (id, title, org, description, type, eligibility, decision, minimum, maximum, deadline, address, phone, site, keywords, date_entered) VALUES (0, '$_POST['title]', '$_POST['org']', '$_POST['description']', '$_POST['type']', '$_POST['eligibility']', '$_POST['decision']', '$_POST['minimum']', '$_POST['maximum']', '$_POST['deadline']', '$_POST['address']', '$_POST['phone']', '$_POST['site']', '$_POST['keywords']', NOW())";
#Execute the query
if (@mysql_query ($query)) {
echo '<p>The ' . $_POST['title'] . ' Scholarship has been added to the database</p>';
} else {
print '<p>Could not add the entry because: <b>' . mysql_error() . '</b></p>';
}
mysql_close(); #Close the connection to MySQL
}
#Display the HTML Form Below
?>
<br>
<form name="form1" method="post" action="admin_add.php">
<table width="70%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="27%">Award Name:</td>
<td width="73%" align="center"> <input name="title" type="text" id="title" size="50" maxlength="100"></td>
</tr>
<tr>
<td>Organization:</td>
<td align="center"><input name="org" type="text" id="org" size="50" maxlength="100"></td>
</tr>
<tr>
<td>Description:</td>
<td align="center"><textarea name="description" cols="50" rows="6" id="description"></textarea></td>
</tr>
<tr>
<td>Type:</td>
<td align="center"><input name="type" type="text" id="type" size="50" maxlength="100"></td>
</tr>
<tr>
<td>Eligibility:</td>
<td align="center"><textarea name="eligibility" cols="50" rows="6" id="eligibility"></textarea></td>
</tr>
<tr>
<td>Decision:</td>
<td align="center"><input name="decision" type="text" id="decision" size="50" maxlength="200"></td>
</tr>
<tr>
<td>Minimum:</td>
<td align="center"><input name="minimum" type="text" id="minimum" size="50" maxlength="30"></td>
</tr>
<tr>
<td>Maximim:</td>
<td align="center"><input name="maximum" type="text" id="maximum" size="50" maxlength="30"></td>
</tr>
<tr>
<td>Deadline:</td>
<td align="center"><input name="deadline" type="text" id="deadline" size="50" maxlength="50"></td>
</tr>
<tr>
<td>Address:</td>
<td align="center"><input name="address" type="text" id="address" size="50" maxlength="150"></td>
</tr>
<tr>
<td>Phone:</td>
<td align="center"><input name="phone" type="text" id="phone" size="50" maxlength="12"></td>
</tr>
<tr>
<td>Web Site:</td>
<td align="center"><input name="site" type="text" id="site" size="50" maxlength="100"></td>
</tr>
<tr>
<td>Keywords:</td>
<td align="center"><input name="keywords" type="text" id="keywords" size="50" maxlength="100"></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="submit" value="Add Scholarship">
</div></td>
</tr>
</table>
</form>
</body>
</html>
CyanBlue
December 17th, 2004, 10:18 AM
Same error message??? Post the error message if not... :)
Voetsjoeba
December 17th, 2004, 10:26 AM
This doesn't look correct to me:
'$_POST['title]'
Remember that the ' from inside the $_POST[''] wil serve as an end of the value to the SQL string. So change the query to:
$query = "INSERT INTO `scholarships` VALUES (0, '$_POST[title]', '$_POST[org]', '$_POST[description]', '$_POST[type]', '$_POST[eligibility]', '$_POST[decision]', '$_POST[minimum]', '$_POST[maximum]', '$_POST[deadline]', '$_POST[address]', '$_POST[phone]', '$_POST[site]', '$_POST[keywords]', NOW());";
Also, as CyanBlue said: what's the error message you get ?
CyanBlue
December 17th, 2004, 11:50 AM
You mean this, Voetsjoeba, right??? :)
$query = "INSERT INTO scholarships (id, title, org, description, type, eligibility, decision, minimum, maximum, deadline, address, phone, site, keywords, date_entered) VALUES (0, $_POST['title'], $_POST['org'], $_POST['description'], $_POST['type'], $_POST['eligibility'], $_POST['decision'], $_POST['minimum'], $_POST['maximum'], $_POST['deadline'], $_POST['address'], $_POST['phone'], $_POST['site'], $_POST['keywords'], NOW())";
jw06
December 17th, 2004, 04:28 PM
Yea sorry, same error message...parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /webdirectory/admin_add.php on line 25
Voetsjoeba
December 19th, 2004, 12:36 PM
You mean this, Voetsjoeba, right??? :)
$query = "INSERT INTO scholarships (id, title, org, description, type, eligibility, decision, minimum, maximum, deadline, address, phone, site, keywords, date_entered) VALUES (0, $_POST['title'], $_POST['org'], $_POST['description'], $_POST['type'], $_POST['eligibility'], $_POST['decision'], $_POST['minimum'], $_POST['maximum'], $_POST['deadline'], $_POST['address'], $_POST['phone'], $_POST['site'], $_POST['keywords'], NOW())";
No, I don't mean that. The whole (id, title, org ...) part is optional, and in your code, you are not placing any values. Values in MySQL are inbetween single quotes, but I don't see any in your SQL string, only in the $_POST['']s. That code will generate an invalid SQL string. Also, the ` `s around the table name are optional, but I experienced that if I leave them out it doesn't work on my MySQL, so to be safe I included those.
JW06, please post the entire code you are using now.
CyanBlue
December 19th, 2004, 12:53 PM
Oh... Now I get it... Thanks... :)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.