TheMovieman Posted June 6, 2006 Posted June 6, 2006 (edited) Hello once again OK, I got this code out of a book and changed it to suit my needs. I thought I understood it and actually had it working, but I guess not. So... the problem is I enter data using a form, click submit and. I made a simple page to show the movie title and critic associated and the first entry showed up fine. However, when I did it again for the next movie and I refresh the page, and the new entry isn't there (and it fits the parameters). So, I used an edit page created which fills in the forms with the already entered data (which all shows up correct), I then click the "submit" button on that page, then refresh my test page and now the entry shows up... I've gone through the coding for both pages (newreview, edit) but I can't figure out why this is happening. Here's the coding for the "newreview" page: ><HTML> <head> <title>Review CMS: Add New Review</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head> <BODY> <?php include '../includes/connection.php'; if (isset($_POST['intro'])): // A new review has been entered // using the form. $id = $_POST['id']; $keywords = $_POST['keywords']; $title = $_POST['title']; $listtitle = $_POST['listtitle']; $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 review. 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', keywords='$keywords', listtitle='$listtitle'"; if (@mysql_query($sql)) { echo '<p>New review added</p>'; } else { exit('<p>Error adding new review: ' . mysql_error() . '</p>'); } if (isset($_POST['genres'])) { $genres = $_POST['genres']; } else { $genres = array(); } $numGenres = 0; foreach ($genres as $genreID) { $sql = "INSERT IGNORE INTO moviegenre SET movieid='$id', genreid=$genreID"; $ok = @mysql_query($sql); if ($ok) { $numGenres = $numGenres + 1; } else { echo "<p>Error inserting review 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.html">INDEX PAGE</a></p> <?php else: $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>Keywords:<br /> <textarea name="keywords" rows="4" cols="45"> </textarea></p> <p>Movie Title:<br /> <textarea name="title" rows="1" cols="45"> </textarea></p> <p>Listing Title: (title that will appear on review index pages)<br /> <textarea name="listtitle" rows="1" cols="45"> </textarea></p> <p>Year:<br /> <textarea name="year" rows="1" cols="8"> </textarea></p> <p>Release Date:<br /> <textarea name="releasedate" rows="1" cols="30"> </textarea></p> <p>Introduction:<br /> <textarea name="intro" rows="8" cols="70"> </textarea></p> <p>Review Part 1:<br /> <textarea name="reviewbody1" rows="15" cols="70"> </textarea></p> <p>Review Part 2:<br /> <textarea name="reviewbody2" rows="15" cols="70"> </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="8"> </textarea></p> <P>Star Rating: <select name="star_rating" size="1"> <option selected value="">Select One</option> <option value="">----------------</option> <option value="1star">1 STAR</option> <option value="1.25stars">1.25 STARS</option> <option value="1.5stars">1.5 STARS</option> <option value="1.75stars">1.75 STARS</option> <option value="2stars">2 STARS</option> <option value="2.25stars">2.25 STARS</option> <option value="2.5stars">2.5 STARS</option> <option value="2.75stars">2.75 STARS</option> <option value="3stars">3 STARS</option> <option value="3.25stars">3.25 STARS</option> <option value="3.5stars">3.5 STARS</option> <option value="3.75stars">3.75 STARS</option> <option value="4stars">4 STARS</option> <option value="4.25stars">4.25 STARS</option> <option value="4.5stars">4.5 STARS</option> <option value="4.75stars">4.75 STARS</option> <option value="5stars">5 STARS</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['category']); 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> And now the code for the "edit" page: ><HTML> <head> <title>Review CMS: Add New Review</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head> <BODY> <?php include '../includes/connection.php'; if (isset($_POST['intro'])): // A new review has been entered // using the form. $id = $_POST['id']; $keywords = $_POST['keywords']; $title = $_POST['title']; $listtitle = $_POST['listtitle']; $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 review. 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', keywords='$keywords', listtitle='$listtitle'"; if (@mysql_query($sql)) { echo '<p>New review added</p>'; } else { exit('<p>Error adding new review: ' . mysql_error() . '</p>'); } if (isset($_POST['genres'])) { $genres = $_POST['genres']; } else { $genres = array(); } $numGenres = 0; foreach ($genres as $genreID) { $sql = "INSERT IGNORE INTO moviegenre SET movieid='$id', genreid=$genreID"; $ok = @mysql_query($sql); if ($ok) { $numGenres = $numGenres + 1; } else { echo "<p>Error inserting review 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.html">INDEX PAGE</a></p> <?php else: $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>Keywords:<br /> <textarea name="keywords" rows="4" cols="45"> </textarea></p> <p>Movie Title:<br /> <textarea name="title" rows="1" cols="45"> </textarea></p> <p>Listing Title: (title that will appear on review index pages)<br /> <textarea name="listtitle" rows="1" cols="45"> </textarea></p> <p>Year:<br /> <textarea name="year" rows="1" cols="8"> </textarea></p> <p>Release Date:<br /> <textarea name="releasedate" rows="1" cols="30"> </textarea></p> <p>Introduction:<br /> <textarea name="intro" rows="8" cols="70"> </textarea></p> <p>Review Part 1:<br /> <textarea name="reviewbody1" rows="15" cols="70"> </textarea></p> <p>Review Part 2:<br /> <textarea name="reviewbody2" rows="15" cols="70"> </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="8"> </textarea></p> <P>Star Rating: <select name="star_rating" size="1"> <option selected value="">Select One</option> <option value="">----------------</option> <option value="1star">1 STAR</option> <option value="1.25stars">1.25 STARS</option> <option value="1.5stars">1.5 STARS</option> <option value="1.75stars">1.75 STARS</option> <option value="2stars">2 STARS</option> <option value="2.25stars">2.25 STARS</option> <option value="2.5stars">2.5 STARS</option> <option value="2.75stars">2.75 STARS</option> <option value="3stars">3 STARS</option> <option value="3.25stars">3.25 STARS</option> <option value="3.5stars">3.5 STARS</option> <option value="3.75stars">3.75 STARS</option> <option value="4stars">4 STARS</option> <option value="4.25stars">4.25 STARS</option> <option value="4.5stars">4.5 STARS</option> <option value="4.75stars">4.75 STARS</option> <option value="5stars">5 STARS</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['category']); 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> And here's the test results page in case I'm not entering the query correctly: ><?php $dbcnx = @mysql_connect('localhost', 'username', 'password'); if (!$dbcnx) { exit('<p>Unable to connect to the ' . 'database server at this time.</p>'); } if (!@mysql_select_db('moviema_mmdb')) { exit('<p>Unable to locate the review ' . 'database at this time.</p>'); } $id = $_GET['id']; $genreinfo = @mysql_query("SELECT listtitle, name FROM moviegenre, genre, movie_reviews, critic WHERE genreid=genre.id AND movieid=movie_reviews.id AND criticid=critic.id AND genre.category='$id'"); while ($cats = mysql_fetch_array($genreinfo)) { $title = $cats['listtitle']; $critic = $cats['name']; echo "$title - $critic<br />"; } ?> I apologize for the excessive length but I thought I should include everything that applies. I'm getting a tad frustrated as I thought I was making headway with this and it's probably some minor error on my part. I appreciate any help that can be provided Edited June 6, 2006 by TheMovieman Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.