Forum Moderators: coopster
Parse error: parse error, unexpected $ in /home/g/e/MYSITE/
I suspect I'm not closing something corretly (maybe the submit?) but am unsure why and where exactly. I'm hoping it's a curly bracket and me staring at it too long. Your help is appreciated!
my code is...
///////////////////////////////////////////////////
<!-- Form designed to work as blog and then to further evolve into a search facility as well -->
<!-- HTML -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Search Function</title>
<!-- CSS Linking -->
<LINK rel=StyleSheet href="css/main.css" TYPE="text/css" MEDIA="screen">
<LINK rel=StyleSheet href="css/print.css" TYPE="text/css" MEDIA="print">
<!-- //CSS Linking -->
</head>
<body>
<!-- PHP uploading script -->
<?php
//error handling - this will show all errors that occur
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
//
//
if(isset ($_POST['submit'])) { // handle the forms submition
//test the database connection.
//<!-- PHP call in database -->
require ("db_locate/db_add.alpha"); //required or no page displayed
//<!-- //PHP call in database -->
//Define the query
$query = "INSERT INTO main (L4F, Username, Postcode, IP, Refer, Browser, Date_entered) VALUES (0, '{$_POST['Username']}', '{$_POST['Postcode']}', '{$_SERVER['REMOTE_ADDR']}', '{$_SERVER['HTTP_REFERER']}', '{$_SERVER['HTTP_USER_AGENT']}', NOW())";
//Execute query
if(@mysql_query ($query)) {
print '<p><big> Details have been added</big> </p>';
}else{
print '<p> The blog entery could not been added because <b>" . mysql_error() " </b>. The query was $query.</p>';
}
mysql_close();
}
//Display the form
?>
<!-- \\PHP uploading script -->
<!-- HTML Form that users see -->
<form action="new_record.php" method="post">
<p align="left">Username <input type="text" name="Username" size="40" maxsize="100" />
</p>
<p>Postcode: <input type="text" name="Postcode" size="40" maxsize="100" /></p>
<input type="submit" name="submit" value="Add user" />
</form>
<!-- \\HTML Form that users see -->
</body>
</html>
<!-- //HTML -->
//////////////////////////////////////////////////////
and the html...
//////////////////////////////////////////////////////
<html>
<head>
<title>Search</title>
<link rel="stylesheet" type="text/css" href="../css/print.css" media="print">
<link rel="stylesheet" type="text/css" href="../css/bwcss.css" media="screen">
</head>
<body>
<p><b><font >Search the database:</font></b></p>
<form method="post" action="search1.php" enctype="multipart/form-data">
<table width="100%"border="0"cellspacing="3"cellpadding="3">
<tr><td width="25%">Username</strong></td>
<td width="75%"> <input name="Username" type="text" size=40 maxlength=255 value=""> </font>
</td>
</tr><tr><td width="25%">Postcode</strong></td>
<td width="75%"> <input name="Postcode" type="text" size=40 maxlength=255 value=""> </font>
</td>
</tr>
<tr>
<td width="25%"> </td>
<td width="75%" align="left"> <input type="submit" name="submit" value="submit">
  <input type="reset" name="reset"> </td>
</tr>
</table>
</form>
</body>
</html>
//////////////////////////////////////////////////////
require ("db_locate/db_add.alpha"); //required or no page displayed
try to call the script (*.php) ONLY instead of a full path and copy your script to the samer folder with the problematic script....
I f this doesnt work try the include statement instead or require to check if this works...
PS:This works fine for my scripts:
include "dbconnect.php";
My inc file is below... it has worked on other submit forms though. My add to feature works just fine just can't search :-(
<?php
if ($dbc = @mysql_connect ('SITENAME', 'USERNAME, 'PASSWORD'))
//PHP Database called and password checked-->
{
//Connect to the database, this needs to be put into an include file.
if (!@mysql_select_db ('DATABASE')) {
die ('<p>Could not select the database because: <b>' . mysql_error() . '</b></p>');
}
} else {
die ('<p>Could not connect to MySQL because: <b>' . mysql_error() . '</b></p>');
}
?>
Still got same error with inc file as a *.php and when in correct file. Tried both include and require. Maybe there is a random bracket somewhere. I'm still suspecting something has been left open but I just can't see the error. I know I'm going to kick myself when You/I see it mind!
Form --> Enter value --> Value carried to php process page --> Search results taken from form variable
/////////////////////////////////////////////////////
Form.php
////////////////////////////////////////////////////
<!-- HTML -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>View customers</title>
</head>
<body>
<!-- PHP Database called and password checked-->
<!-- //PHP Database called and password checked-->
<!-- PHP main section-->
<?php
// Address error handing.
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
// Connect and select.
require("db.php");
// Define the query.
$query = 'SELECT * FROM blog_entries WHERE title = "hello" ORDER BY date_entered DESC';
if ($r = mysql_query ($query)) { // Run the query.
// Retrieve and print every record.
while ($row = mysql_fetch_array ($r)) {
print "<p><h3>{$row['title']}</h3>
<h5>{$row['date_entered']}<br /><br /></h5>
{$row['entry']}<br />
<a href=\"edit_entry.php?id={$row['blog_id']}\">Edit</a>
<a href=\"delete_entry.php?id={$row['blog_id']}\">Delete</a>
</p><hr />\n";
}
} else { // Query didn't run.
die ('<p>Could create the table because: <b>' . mysql_error() . "</b>. The query was $query.</p>");
} // End of query IF.
mysql_close(); // Close the database connection.
?>
<!-- //PHP main section-->
</body>
</html>
<!-- //HTML -->
////////////////////////////////////////////////////
include file
///////////////////////////////////////////////////
<?php
//required or no page displayed
if ($dbc = @mysql_connect ('SITENAME', 'USERNAME', 'PASSWORD'))
{
//Connect to the database, this needs to be put into an include file.
if (!@mysql_select_db ('TABLE')) {
die ('<p>Could select the database because: <b>' . mysql_error() . '</b></p>');
}
} else {
die ('<p>Could not connect to MySQL because: <b>' . mysql_error() . '</b></p>');
}
?>
////////////////////////////////////////////////////