Forum Moderators: coopster

Message Too Old, No Replies

Trouble with SQL search

Parse error: parse error, unexpected $ in /home/g/e/MYSITE/

         

phoenix riser

10:02 am on Jul 19, 2005 (gmt 0)

10+ Year Member



I have the error

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%">&nbsp;</td>
<td width="75%" align="left"> <input type="submit" name="submit" value="submit">
&nbsp <input type="reset" name="reset"> </td>
</tr>
</table>
</form>
</body>
</html>
//////////////////////////////////////////////////////

omoutop

10:31 am on Jul 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi...
Maybe its your require statement as u say...

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";

phoenix riser

11:21 am on Jul 19, 2005 (gmt 0)

10+ Year Member



Thank you for the advice but that did not work.

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!

phoenix riser

11:24 am on Jul 19, 2005 (gmt 0)

10+ Year Member



Thought;

If the counter works should it not go and select the other page it is told too? Again hard to tell as error not all that helpful too me!

omoutop

11:25 am on Jul 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I dont know if u have posted the whole script...what u can do is to use the php edit editor to check all brackets if they are closing/opening properly....
i.e. a properly closed bracket is highlighted in yellow color

phoenix riser

11:40 am on Jul 19, 2005 (gmt 0)

10+ Year Member



All code is there. Even went through and corrected all the errors in my form which where simple one </strong> and one extra </font> both of which made no difference anyway.

Would it help to see the standard view all code and try to modify that?

phoenix riser

11:43 am on Jul 19, 2005 (gmt 0)

10+ Year Member



I use Dreamweaver to check my code, what do you use?

omoutop

12:06 pm on Jul 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



PHPEdit...

it is far better for php

[waterproof.fr...]

phoenix riser

12:43 pm on Jul 19, 2005 (gmt 0)

10+ Year Member



Thank you will try. Just having few tech 'issues' at work with printer (like it broke!). Do I want to 30Mb version?

phoenix riser

1:22 pm on Jul 19, 2005 (gmt 0)

10+ Year Member



No errors found in Dreamweaver or PHPeidt :-( (normally good thing but be nice to find the little blitter!)

omoutop

1:36 pm on Jul 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you think php edit is a better editor?

anyway....does the script tell you in which line the problem relies?

phoenix riser

1:47 pm on Jul 19, 2005 (gmt 0)

10+ Year Member



Not really played with it yet and have used Dreamweaver for years.

The error occurs at whichever is teh last line. For example at the end I put a log so I could write down my changes and so the log became the last line and it selected this as the error :-S Something is not closing somewhere.

omoutop

1:58 pm on Jul 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



either this is the problem (something is not closing, maybe a { or (...) OR
there is another problem which the browser can not find/detect (specific line) so it returns the last one or first one, happened to me lots of times...keep trying my friend...I have to go...c u tommorow and hopefully with a working script ;)

jd01

2:32 pm on Jul 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think it's this line:

print '<p> The blog entery could not been added because <b>" . mysql_error() " </b>. The query was $query.</p>';

Maybe try this

print "<p> The blog entery could not been added because <b>" . mysql_error() . "</b> The query was " . $query ."</p>";

Justin

phoenix riser

8:48 am on Jul 21, 2005 (gmt 0)

10+ Year Member



Here is a working version. Yes it is different and I need to add a form back in but it works. What I need to add now is a form to the front end again also when the form processes it needs to then search the word that has been added so thus the current "hello" needs to be a variable that takes it value from a posted value in the form before.

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>');
}
?>
////////////////////////////////////////////////////