Jump to content

[SOLVED] PARSE Error, please help


kr3m3r

Recommended Posts

Hi guys, I'm trying to follow the code in my book (PHP and MySQL Web Development) as it is listed.  Unfortunately, something isn't working out, I keep getting this error:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/.titch/rwkremer/kr3m3r.com/results.php on line 27

 

I looked up the error on google, and it seemed to be associated with quotes being out of place, but I can't seem to find any evidence of that.

 

The Entire Code for the php is:

<html>
<head>
<title>Book-O-Rama Search Results</title>
</head>
<body>
<h1>Book-O-Rama Search Results</h1>
<?php
//create short variable names
$searchtype=$HTTP_POST_VARS['searchtype'];
$searchterm=$HTTP_POST_VARS['searchterm'];

$searchterm = trim($searchterm);

if(!$searchtype && !$searchterm)
{
echo 'You have not entered search details. Please go back and try again.';
exit;
}

$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);

@ $db - mysql_pconnect('learning', 'bookorama', bookorama123');

if(!$db)
{
echo 'Error: Could not connect to database. Please try later.';
exit;
}

mysql_select_db('books');
$query = "select * from books where ".$searchtype." like '%".$searchterm."%'";
$result = mysql_query($query);

$num_results = mysql_num_rows($result);

echo '<p>Number of books found: '.$num_results.'</p>';

for($i=0; $i<$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo '<p><strong>'.($i+1).'. Title: ';
echo htmlspecialchars(stripslashes($row['title']));
echo '</strong><br />Author: ';
echo stripslashes($row['author']);
echo '<br />ISBN: ';
echo stripslashes($row['isbn']);
echo '<br />Price: ';
echo stripslashes($row['price']);
echo '</p>';
}
?>

</body>
</html>

 

Any help on this issue would be greatly appreciated.  Thanks for your time.

-Robb

Link to comment
Share on other sites

there're two problems on this line:

 

@ $db - mysql_pconnect('learning', 'bookorama', bookorama123');

 

first, you're trying to subtract the mysql_pconnect() results from $db.  i assume you need an equal sign?  you are also missing an opening single quote on the password parameter.  a simple check of syntax highlighting gives you a good idea of where things start to go wrong.

 

EDIT: chocopi beat me to it, but the issue with the equal sign still stands.

Link to comment
Share on other sites

OK, your fresh eyes solved what I could not, that was where the missing quote was.  I've fixed that and now no longer have the problem with the PARSE error.  ;D.  Now before we can put this puppy to bed, can you help me figure out how to correctly specify the host?  the hostname is learning.mysite.com, at least that is what i specified when i created it.  the db i'm working with is called books.  Any more help would be incredibly appreciated.  Thanks again!

-Robb

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.