Help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
idnoble
Forum Commoner
Posts: 28
Joined: Wed Mar 31, 2004 4:09 am

Help!

Post by idnoble »

Hello
I am trying to create a script that use the variable passed to it from an HTML form to search 2 tables in my database and display the results from both tables, i have created the script but each time i run i always get this error message:

Parse error: parse error in /var/www/html/search.php on line 545

I think its a problem with the query PHP is passing to mysql, i've looked through the code but can't figure it our, please help :( :( , My code is below

Code: Select all

<?php
//Create short variable names
$search = $HTTP_POST_VARS['search'];
$search= trim($search);
if (!$search)
{
echo '<p style= "font-size: 15pt color: red"><strong>You have not specified a search term. Please go back and try again.</strong></p>';
exit;
}
$search = addslashes($search);
$session = mysql_connect('localhost', '', '') or die(mysql_error());
if (!$session)
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}

mysql_select_db('xplosive')or die(mysql_error());
$query = "select * 
from movies, music
where movies.Title like '%".$search."%'", && music.Title like '%".$search.'%";
$result = mysql_query($query) or die(mysql_error()); 

$num_results = mysql_num_rows($result);

echo '<p style= "font-size: 10pt"><strong>Search hits: '.$num_results.'></strong></p>';
for ($i=0; $i <$num_results; $i++)
{
 $row = mysql_fetch_array($result);
echo '<p style= "font-size:14pt; color: blue"><strong>'. ($i+1). ':'; 
echo htmlspecialchars (stripslashes($row['Title']));
 echo '<p style= "font-size: 12pt; color: black"<br />Genre: ';
 echo stripslashes($row['Genre']);
 echo '<br/> Synopsis: ';
 echo stripslashes ($row['Synopsis']);
 echo'<br> Price: ';
 echo stripslashes ($row['Price']);
 echo '<br> Cat Number: ';
 echo stripslashes ($row['Cat_No']);
 echo '</p>';
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

1. Help!!!!!!!!!!!!!!! is not a appropriate subect line. Don't do it.
2. Look at the colored PHP code. Specifically, around here:

Code: Select all

$query = "select *
from movies, music
where movies.Title like '%".$search."%'", && music.Title like '%".$search.'%";
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

hmm... look at the colors of your code - for some reason about halfway down it all turns red for string! That's a clue...
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Which line is 545?

Try editing this:

Code: Select all

$query = "select * 
from movies, music 
where movies.Title like '%".$search."%'", && music.Title like '%".$search.'%";
to

Code: Select all

$query = "SELECT * FROM movies, music WHERE movies.Title LIKE '%$search%' AND music.Title LIKE '%$search%'";
Post Reply