Jump to content

Recommended Posts

Posted (edited)

Hello,

 

With the help of a tutorial book, I've experimented with ways to insert a movie review but before I can test it and see if it'll enter the information correctly, I get this error:

 

Parse error: syntax error, unexpected T_VARIABLE in /home/username/public_html/folder/subfolder/addnewreview.php on line 199

 

I had gotten a parse error before because of an "else:" statement which after taking out, got to this (and that error was much higher up). Here's the code:

 

><HTML>
<head>
<title>Review CMS: Add New Review</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<BODY>

$connection = @mysql_connect('localhost', 'username', 'password');
if (!$connection) {
 exit('<p>Unable to connect to the ' .
  'database server at this time.</p>');
}

if (!@mysql_select_db('databasename')) {
 exit('<p>Unable to locate the movie ' .
  'database at this time.</p>');
}

if (isset($_POST['intro'])): 
 // A new review has been entered
 // using the form.

 $id = $_POST['id'];
 $title = $_POST['title'];
 $year = $_POST['year'];
 $releasedate = $_POST['releasedate'];
 $intro = $_POST['intro'];
 $reviewbody1 = $_POST['reviewbody1'];
 $reviewbody2 = $_POST['reviewbody2'];
 $image1 = $_POST['image1'];
 $image2 = $_POST['image2'];
 $poster = $_POST['poster'];
 $mpaa_rating = $_POST['mpaa_rating'];
 $mpaa_reason = $_POST['mpaa_reason'];
 $runtime = $_POST['runtime'];
 $star_rating = $_POST['star_rating'];
 $cid = $_POST['cid'];
 $genres = $_POST['genres'];

 if ($cid == '') {
exit('<p>You must choose a critic for this joke. Click "Back" and try again.</p>');
 }

 $sql = "INSERT INTO movie_reviews SET
id='$id',
title='$title',
year='$year',
reviewdate=CURDATE(),
releasedate='$releasedate',
intro='$intro',
reviewbody1='$reviewbody1',
reviewbody2='$reviewbody2',
image1='$image1',
image2='$image2',
mpaa_rating='$mpaa_rating',
mpaa_reason='$mpaa_reason',
runtime='$runtime',
star_rating='$star_rating',
criticid='$cid',
poster='$poster'";
 if (@mysql_query($sql)) {
echo '<p>New review added</p>';
 } else {
exit('<p>Error adding new review: ' . mysql_error() . '</p>');
 }

 $mid = mysql_insert_id();

 if (isset($_POST['genres'])) {
$genres = $_POST['genres'];
 } else {
$genres = array();
 }

 $numGenres = 0;
 foreach ($genres as $genreID) {
$sql = "INSERT IGNORE INTO moviegenre
		SET movieid=$mid, genreid=$genreID";
$ok = @mysql_query($sql);
if ($ok) {
  $numGenres = $numGenres + 1;
} else {
  echo "<p>Error inserting joke into category $genreID: " .
	  mysql_error() . '</p>';
}
 }
?>

<p>Review was added to <?php echo $numGenre; ?> categories.</p>

<p><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Add another movie review</a></p>
<p><a href="index.php">INDEX PAGE</a></p>

<?php

 $critics = @mysql_query('SELECT id, name FROM critic');
 if (!$critics) {
exit('<p>Unable to obtain critic list from the database.</p>');
 }
 $genres = @mysql_query('SELECT id, category FROM genre');
 if (!$genres) {
exit('<p>Unable to obtain genre list from the database.</p>');
 }

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Movie ID:<br />
<textarea name="id" rows="1" cols="30">
</textarea></p>

<p>Movie Title:<br />
<textarea name="title" rows="1" cols="45">
</textarea></p>

<p>Year:<br />
<textarea name="year" rows="1" cols="10">
</textarea></p>

<p>Release Date:<br />
<textarea name="releasedate" rows="1" cols="10">
</textarea></p>

<p>Introduction:<br />
<textarea name="intro" rows="5" cols="45">
</textarea></p>

<p>Review Part 1:<br />
<textarea name="reviewbody1" rows="10" cols="45">
</textarea></p>

<p>Review Part 2:<br />
<textarea name="reviewbody2" rows="10" cols="45">
</textarea></p>

<p>Image #1:<br />
<textarea name="image1" rows="1" cols="45">
</textarea></p>

<p>Image #2:<br />
<textarea name="image2" rows="1" cols="45">
</textarea></p>

<p>Poster:<br />
<textarea name="poster" rows="1" cols="45">
</textarea></p>

<P>MPAA Rating:
<select name="mpaa_rating" size="1">
 <option selected value="">Select One</option>
 <option value="">--------------------</option>
 <option value="g">G</option>
 <option value="pg">PG</option>
 <option value="pg13">PG-13</option>
 <option value="r">R</option>
 <option value="nc17">NC-17</option>
 <option value="nr">Not Rated</option>
</select></p>

<p>MPAA Reason:<br />
<textarea name="mpaa_reason" rows="3" cols="45">
</textarea></p>

<p>Runtime:<br />
<textarea name="runtime" rows="1" cols="10">
</textarea></p>

<P>Star Rating:
<select name="star_rating" size="1">
 <option selected value="">Select One</option>
 <option value="">----------------</option>
 <option value="1star">*</option>
 <option value="1.25stars">*¼</option>
 <option value="1.5stars">*½</option>
 <option value="1.75stars">*¾</option>
 <option value="2stars">**</option>
 <option value="2.25stars">**¼</option>
 <option value="2.5stars">**½</option>
 <option value="2.75stars">**¾</option>
 <option value="3stars">***</option>
 <option value="3.25stars">***¼</option>
 <option value="3.5stars">***½</option>
 <option value="3.75stars">***¾</option>
 <option value="4stars">****</option>
 <option value="4.25stars">****¼</option>
 <option value="4.5stars">****½</option>
 <option value="4.75stars">****¾</option>
 <option value="5stars">*****</option>
</select></p>

<P>Critic:
<select name="cid" size="1">
 <option selected value="">Select One</option>
 <option value="">-----------</option>
<?php
 while ($critic = mysql_fetch_array($critics)) {
$cid = $critic['id']
$cname = htmlspecialchars($critic['name']);
echo "option value='cid'>$cname</option>\n";
 }
?>
</select></p>

<p>Place in Genre(s):<br />
<?php
 while ($genre = mysql_fetch_array($genres)) {
$gid = $genre['id'];
$gname = htmlspecialchars($genre['name']);
echo "<label><input type='checkbox' name='genres[]' " .
	"value='$gid' />$gname</label><br />\n";
 }
?>
</p>

<P><input type="submit" value="INSERT RECORD" /></P>
</form>
<?php endif; ?>


</BODY>
</HTML>

 

I'd appreciate any help at all :)

Edited by TheMovieman
Posted

Give the code below a shot. Fixed probably a half dozen or more miscellaneous missing, misplaced or misused quotes, semicolons, and the leading <?php under the <body> tag. Final product left me unable to connect to the database, but no parse errors. See what it does for you.

 

><HTML>
<head>
<title>Review CMS: Add New Review</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<BODY>

<?php
$connection = @mysql_connect('localhost', 'username', 'password');
if (!$connection) {
 exit('<p>Unable to connect to the ' .
  'database server at this time.</p>');
}

if (!@mysql_select_db('databasename')) {
 exit('<p>Unable to locate the movie ' .
  'database at this time.</p>');
}

if (isset($_POST['intro'])):
 // A new review has been entered
 // using the form.

 $id = $_POST['id'];
 $title = $_POST['title'];
 $year = $_POST['year'];
 $releasedate = $_POST['releasedate'];
 $intro = $_POST['intro'];
 $reviewbody1 = $_POST['reviewbody1'];
 $reviewbody2 = $_POST['reviewbody2'];
 $image1 = $_POST['image1'];
 $image2 = $_POST['image2'];
 $poster = $_POST['poster'];
 $mpaa_rating = $_POST['mpaa_rating'];
 $mpaa_reason = $_POST['mpaa_reason'];
 $runtime = $_POST['runtime'];
 $star_rating = $_POST['star_rating'];
 $cid = $_POST['cid'];
 $genres = $_POST['genres'];

 if ($cid == '') {
exit('<p>You must choose a critic for this joke. Click "Back" and try again.</p>');
 }

 $sql = "INSERT INTO movie_reviews SET
id='$id',
title='$title',
year='$year',
reviewdate=CURDATE(),
releasedate='$releasedate',
intro='$intro',
reviewbody1='$reviewbody1',
reviewbody2='$reviewbody2',
image1='$image1',
image2='$image2',
mpaa_rating='$mpaa_rating',
mpaa_reason='$mpaa_reason',
runtime='$runtime',
star_rating='$star_rating',
criticid='$cid',
poster='$poster'";

 if (@mysql_query($sql)) {
echo '<p>New review added</p>';
 } else {
exit('<p>Error adding new review: ' . mysql_error() . '</p>');
 }

 $mid = mysql_insert_id();

 if (isset($_POST['genres'])) {
$genres = $_POST['genres'];
 } else {
$genres = array();
 }

 $numGenres = 0;
 foreach ($genres as $genreID) {
$sql = "INSERT IGNORE INTO moviegenre
		SET movieid=$mid, genreid=$genreID";
$ok = @mysql_query($sql);
if ($ok) {
  $numGenres = $numGenres + 1;
} else {
  echo "<p>Error inserting joke into category $genreID: " .
	  mysql_error() . '</p>';
}
 }
?>

<p>Review was added to <?php echo $numGenre; ?> categories.</p>

<p><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Add another movie review</a></p>
<p><a href="index.php">INDEX PAGE</a></p>

<?php

 $critics = @mysql_query('SELECT id, name FROM critic');
 if (!$critics) {
exit('<p>Unable to obtain critic list from the database.</p>');
 }
 $genres = @mysql_query('SELECT id, category FROM genre');
 if (!$genres) {
exit('<p>Unable to obtain genre list from the database.</p>');
 }

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Movie ID:<br />
<textarea name="id" rows="1" cols="30">
</textarea></p>

<p>Movie Title:<br />
<textarea name="title" rows="1" cols="45">
</textarea></p>

<p>Year:<br />
<textarea name="year" rows="1" cols="10">
</textarea></p>

<p>Release Date:<br />
<textarea name="releasedate" rows="1" cols="10">
</textarea></p>

<p>Introduction:<br />
<textarea name="intro" rows="5" cols="45">
</textarea></p>

<p>Review Part 1:<br />
<textarea name="reviewbody1" rows="10" cols="45">
</textarea></p>

<p>Review Part 2:<br />
<textarea name="reviewbody2" rows="10" cols="45">
</textarea></p>

<p>Image #1:<br />
<textarea name="image1" rows="1" cols="45">
</textarea></p>

<p>Image #2:<br />
<textarea name="image2" rows="1" cols="45">
</textarea></p>

<p>Poster:<br />
<textarea name="poster" rows="1" cols="45">
</textarea></p>

<P>MPAA Rating:
<select name="mpaa_rating" size="1">
 <option selected value="">Select One</option>
 <option value="">--------------------</option>
 <option value="g">G</option>
 <option value="pg">PG</option>
 <option value="pg13">PG-13</option>
 <option value="r">R</option>
 <option value="nc17">NC-17</option>
 <option value="nr">Not Rated</option>
</select></p>

<p>MPAA Reason:<br />
<textarea name="mpaa_reason" rows="3" cols="45">
</textarea></p>

<p>Runtime:<br />
<textarea name="runtime" rows="1" cols="10">
</textarea></p>

<P>Star Rating:
<select name="star_rating" size="1">
 <option selected value="">Select One</option>
 <option value="">----------------</option>
 <option value="1star">*</option>
 <option value="1.25stars">*¼</option>
 <option value="1.5stars">*½</option>
 <option value="1.75stars">*¾</option>
 <option value="2stars">**</option>
 <option value="2.25stars">**¼</option>
 <option value="2.5stars">**½</option>
 <option value="2.75stars">**¾</option>
 <option value="3stars">***</option>
 <option value="3.25stars">***¼</option>
 <option value="3.5stars">***½</option>
 <option value="3.75stars">***¾</option>
 <option value="4stars">****</option>
 <option value="4.25stars">****¼</option>
 <option value="4.5stars">****½</option>
 <option value="4.75stars">****¾</option>
 <option value="5stars">*****</option>
</select></p>

<P>Critic:
<select name="cid" size="1">
 <option selected value="">Select One</option>
 <option value="">-----------</option>
<?php
 while ($critic = mysql_fetch_array($critics)) {
$cid = $critic['id'];
$cname = htmlspecialchars($critic['name']);
echo "<option value='cid'>$cname</option>\n";
 }
?>
</select></p>

<p>Place in Genre(s):<br />
<?php
 while ($genre = mysql_fetch_array($genres)) {
$gid = $genre['id'];
$gname = htmlspecialchars($genre['name']);
echo "<label><input type='checkbox' name='genres[]' " .
	"value='$gid' />$gname</label><br />\n";
 }
?>
</p>

<P><input type="submit" value="INSERT RECORD" /></P>
</form>
<?php endif; ?>


</BODY>
</HTML>

Posted (edited)

Thanks Tim. Yeah, I noticed and corrected some. I'll give this a try though and see.

 

EDIT:

Well, no parse errors (thankfully), but now all I get is a blank white screen, lol. I was thinking about thinking about removing all the insert code above and have one page for the form and another to insert the data...

 

EDIT #2: (lol)

I had taken out a piece of the code before and did not insert it again. Once I did so, it worked, sort of. The critic lists just fine but there are no genres. Probably just some table naming error.

 

Thanks again Tim :)

 

OK, more of a curiosity than a problem but I got the genres to list (wrong row name). Anyways, it lists all but one of them. There are 14 genres but the second one (Drama) isn't listed. The rest are listed fine and in the order I entered them. Don't know why, though.

 

Here's a screenshot:

genreproblem.gif

Edited by TheMovieman

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...