Parse Error Nightmares :(

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
User avatar
phpnovice
Forum Commoner
Posts: 25
Joined: Mon Feb 02, 2004 6:47 am
Location: england, london

Parse Error Nightmares :(

Post by phpnovice »

Hiya, i was wondering if anyone can help me ive been fiddling with this script for days and keep getting the same parse error on line 37. Im using php 4 and connecting to a mysql database on a linux server which is also serving my pages. Ive chmod 755 all the files too. But i just keep getting the same error can anyone save me?

Here is the script:

Code: Select all

<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head><title> Jims Bargain Basement DVD'S </title></head>
<CENTER><H1>Catalouge</H1><BR></CENTER>
<CENTER><H2>In alphabetical order</H2></CENTER>

<?php

//include details for logging onto mysql database
include 'mysql.php';
//include error function
include 'error.php';

//Setup query for execution
  $result = mysql_query ("SELECT d.title, di.dir_name, p.prod_name, d.duration, d.dvd_desc, g.genre_name , d.price FROM dvd d, director di, producer p, genre g WHERE d.dirid = di.dirid AND d.prodid = p.prodid AND d.genre = g.genreid", $connection);

//connect to mysql with some error handling
if (!($connection = @ mysql_connect($host, $user, $passwd)))
	die("Could not connect to the database");

//select my database with some error handling
if(!mysql_select_db($dbName, $connection))
	showerror();

//Run the query through the connection to mysql with some error handling
if(!($result = @ mysql_query($result,$connection)))
showerror();

echo"<br><table border = "0\ ">";

//List all DVDs using data obtained from $result in an HTML format table
while($row = @ mysql_fetch_array($result))
{
	//format dvd title as a heading
    
	echo"<br><tr><br><td bgcolor = "#6699FF">" .
	$row["title"] . " " .
	"</tr></td><br>"


	//Format review, director name, producer name and genre as a body of text
	echo "<br> <tr> <br> \t <td bgcolor="#CCFFFF">" . " " .
	"<b>Review: </b>" .
	$row["dvd_desc"] . " " .
	"<b>Director: </b>" .
	$row["dir_name"] . " " .
	"<b>Producer: </b>" .
	$row["prod_name"] . " " .
	"<b>Genre: </b>" .
	$row["genre_name"] . " " .
	"</td></tr><br>";

	//format a row for the price
	echo "<br> <tr> <br> \t <td bgcolor="#33FF99">" .
	"<b>Price: £" . 
	$row["price"] . " " . 
	"</td></tr>";

	//for presentation
	echo "<br><tr><br>\t<td></td><br></tr>";
}

echo "<br> </table> <br>";


//close the connection to mysql with some error handling
if(! mysql_close($connection))
showerror();

?>

<CENTER><A HREF="index.php">Home -</A><A HREF="/~bj253/catalouge.php"> Catalouge -</A><A HREF=""> Search  -</A><A HREF=""> Basket  -</A><A HREF=""> Checkout</A></CENTER>

</body>
</html>
Cheers you guys!
Jimbo
User avatar
Pointybeard
Forum Commoner
Posts: 71
Joined: Wed Sep 03, 2003 7:23 pm
Location: Brisbane, AUS
Contact:

Post by Pointybeard »

echo"<br><tr><br><td bgcolor = "#6699FF\">" .

should be

echo"<br><tr><br><td bgcolor = \"#6699FF\">" .
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Code: Select all

echo"<br><table border = "0\ ">";
should be

Code: Select all

echo "<br><table border="0">";
or to remove the need for escaping double quotes:

Code: Select all

echo '<br><table border="0">';
You may find breaking out of PHP into HTML or using HEREDOC format makes it much easier to maintain your code by making it easier to read and removing the need for escaping slashes and the like.

Mac
User avatar
phpnovice
Forum Commoner
Posts: 25
Joined: Mon Feb 02, 2004 6:47 am
Location: england, london

Post by phpnovice »

yeah sorry its just some syntaz errors. but now i cant get mysql to order a query using a get from a select list. i have the query like this

Code: Select all

<?php
 $result ="SELECT d.title, di.dir_name, p.prod_name, d.duration, d.dvd_desc, g.genre_name , d.price FROM dvd d, director di, producer p, genre g WHERE d.dirid = di.dirid AND d.prodid = p.prodid AND d.genre = g.genreid ORDER BY "$dvdOrder"";
?>
and the select list like this:


<b>Please select how you would like to view the catalouge: </b>
<form action="catalouge.php" method="GET">
<select name="dvdOrder">
<option value="d.title" selected>Title
<option value="d.price">Price
<option value="g.genre_name">Genre
<option value="d.dir_name">Director
<option value="d.prod_name">Producer
<input type="submit" value="Go!">
</select>
</form>

but it just returns without re-ordering it.
NB: catalouge.php is the script in the first post but with a new query as above. the select list is at the bottom of the previous script in HTML.

Sorry this is a bit of a side track but i didnt want to start a new post because of it.

Cheers
James
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Not quite sure about your query.


Make sure you have the following

Code: Select all

<?php

 // Connect to the database server 
$dbh=mysql_connect ("localhost", "username", "pw") or die ('I cannot connect to the database because: ' . mysql_error());
  
  // Select the database 
  if (! @mysql_select_db("the database") ) { 
    echo( "<p>Unable to locate the " . 
          "database at this time.</p>" ); 
    exit(); 
  } 

?>

<b>Please select how you would like to view the catalouge: </b> 
<form action="catalouge.php" method="GET"> 
<select name="dvdOrder"> 
<option value="d.title" selected>Title 
<option value="d.price">Price 
<option value="g.genre_name">Genre 
<option value="d.dir_name">Director 
<option value="d.prod_name">Producer 
<input type="submit" name="submitform" value="Go!"> 
</select> 
</form> 

<?php 
if ($submitform == "SUBMIT") { 
  $sql = "INSERT INTO your_database SET d.title='$d.title', d.price ='$d.price', g.genre_name ='$g.genre_name'"; // add rest in

$result ="SELECT d.title, di.dir_name, p.prod_name, d.duration, d.dvd_desc, g.genre_name , d.price FROM dvd d, director di, producer p, genre g WHERE d.dirid = di.dirid AND d.prodid = p.prodid AND d.genre = g.genreid ORDER BY 'dvdOrder'"; 


//but I think you could simply do this 

$result = @mysql_query("SELECT * FROM your_table ORDER BY 'dvdOrder'");

//Then do something like

    while ( $row = mysql_fetch_array($result) ) { 
		$d.title=    $row["d.title"]; 
		$di.dir_name=   $row["di.dir_name"]; 
		$p.prod_name= $row["p.prod_name"]; 
 		$d.duration=  $row["d.duration"];
//add the rest in

//then simply

echo "whatever you want to be displayed";

}


?>
I'm sorry but I don't think will be of any help :S sorta confused I guess.

If anything change

Code: Select all

<?php 
$result ="SELECT d.title, di.dir_name, p.prod_name, d.duration, d.dvd_desc, g.genre_name , d.price FROM dvd d, director di, producer p, genre g WHERE d.dirid = di.dirid AND d.prodid = p.prodid AND d.genre = g.genreid ORDER BY "$dvdOrder""; 


?>
to

Code: Select all

<?php 
$result ="SELECT d.title, di.dir_name, p.prod_name, d.duration, d.dvd_desc, g.genre_name , d.price FROM dvd d, director di, producer p, genre g WHERE d.dirid = di.dirid AND d.prodid = p.prodid AND d.genre = g.genreid ORDER BY '$dvdOrder'"; 
 
?>
Post Reply