S A N T A Posted May 20, 2008 Share Posted May 20, 2008 i am building a blog and everything is working fine but there is one problem with this code: <?php session_start(); require("config.php"); ?> <?php if(isset($_GET['id']) == TRUE) { if(is_numeric($_GET['id']) == FALSE) { $error = 1; } if($error == 1) { header("Location: " . $config_basedir); } else { $validentry = $_GET['id']; } } else { $validentry = 0; } if($_POST['submit']) { $db = mysql_connect($dbhost, $dbuser); mysql_select_db($dbdatabase, $db); $sql = "INSERT INTO comments(blog_id, dateposted, name, comment) VALUES(" . $validentry . ", NOW(), '" . $_SESSION['USERNAME'] . "', '" . $_POST['comment'] . "');"; mysql_query($sql) or die(mysql_error(). " in $sql"); header("Location: " . $config_basedir); } else { //code will go here } require("header.php"); if($validentry == 0) { $sql = "SELECT entries.*, categories.cat FROM entries, categories " . "WHERE entries.cat_id = categories.id " . "ORDER BY dateposted DESC " . " LIMIT 1;"; } else { $sql = "SELECT entries.*, categories.cat FROM entries, categories " . "WHERE entries.cat_id = categories.id AND entries.id = " . $validentry . " ORDER BY dateposted DESC LIMIT 1;"; } $result = mysql_query($sql)or die(mysql_error()); $row = mysql_fetch_assoc($result); echo "<h2>" . $row['subject'] . "</h2><br />"; echo "<i>In <a href='viewcat.php?id=" . $row['cat_id'] ."'>" . $row ['cat'] ."</a> - Posted on " . date("D jS FY g.iA", strtotime($row['dateposted'])) ."</i>"; if(isset($_SESSION['ADMIN']) == TRUE) { echo" [<a href='updateentry.php?id=" . $row['id'] . "'>edit</a>]"; } echo "<p>"; echo nl2br($row['body']); echo "</p>"; $commsql = "SELECT * FROM comments WHERE blog_id = " . $validentry . " ORDER BY dateposted DESC;"; $commresult = mysql_query($commsql); $numrows_comm = mysql_num_rows($commresult); if(isset($_SESSION['USERNAME']) == TRUE) { if($numrows_comm == 0) { echo "<p>No comments.</p>"; } else { $i = 1; while($commrow = mysql_fetch_assoc($commresult)) { echo "<a name='comment" . $i . "'>"; echo "<h3>Comment by " . $commrow['name'] . " on " . date("D jS F Y g.iA", strtotime($commrow['dateposted'])) . "</h3>"; echo $commrow['comment']; $i++; } ?> <table> <tr> <td> <h3>Leave a comment</h3> </td> </tr> <form action="<?php echo $SCRIPT_NAME . "?id=" . $validentry; ?>" method="post"> <tr> <td>Comments</td> <td><textarea name="comment" rows="10" cols="50"></textarea></td> </tr> <tr> <td></td> <td><input type="submit" name="submit" value="Add Comment"></td> </tr> <tr> <td> <font size="-2">Do not post inapropriate comments or they will be deleted</font> </td> </tr> </form> </table> <?php } } else { echo "Login to view/add comments!"; } require("footer.php"); ?> the problem is is that footer.php is not being displayed (it has my copyright stuff on it) and that the form is not being displayed. is there something wrong with my .css file? body { font-family: "trbuchet ms", verdena, sans-serif; font-size: 24px; line-hight: 1.5em; color: #000000; background: #3399FF; margin: 0; padding: 0; text-align: center; width: 100% } #header { position: absolute; top: 0px; left: 0px; hight: 60px; width: 100%; background: #3898B8; padding-top: 8px; } #menu { font-family: "trebuchet ms", verdana, sans-serif; font-size: 14px; font-weight: bold; position: absolute; height: 27px; top: 60px; left: 0px; width: 100%; padding: 0px; color: #000000; background-color: #3399FF; } a:link { text-decoration: none; color: #000 } a:visited { text-decoration: none; border-bottom: 1px dotted #369; color: #000; } a:hover, a:active { text-decoration: none; border-bottom: 1px solid #036; color: #000 } #container { position: absolute; top: 85px; left: 0px; background: #3399FF; margin: 0 auto 0 auto; text-align: left; width: 100%; height: 100% } #bar { float: left; width: 200px; background: #95C78D; padding: 10px; margin-right: 30px; height: 94%; } img { border: 0; } #bar h1 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.3em; } #main { margin: 15px 15px 15px 240px; padding: 15px 15px 15px 15px; background: #76ABED; text-align: left; } i get no errors whatsoever and everything else is working perfectly Thanks in advance! Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 20, 2008 Share Posted May 20, 2008 if you indent your code, it might be easier to see why your form isn't displayed: <?php session_start(); require("config.php"); ?> <?php if(isset($_GET['id']) == TRUE) { if(is_numeric($_GET['id']) == FALSE) { $error = 1; } if($error == 1) { header("Location: " . $config_basedir); } else { $validentry = $_GET['id']; } } else { $validentry = 0; } if($_POST['submit']) { $db = mysql_connect($dbhost, $dbuser); mysql_select_db($dbdatabase, $db); $sql = "INSERT INTO comments(blog_id, dateposted, name, comment) VALUES(" . $validentry . ", NOW(), '" . $_SESSION['USERNAME'] . "', '" . $_POST['comment'] . "');"; mysql_query($sql) or die(mysql_error(). " in $sql"); header("Location: " . $config_basedir); } else { //code will go here } require("header.php"); if($validentry == 0) { $sql = "SELECT entries.*, categories.cat FROM entries, categories " . "WHERE entries.cat_id = categories.id " . "ORDER BY dateposted DESC " . " LIMIT 1;"; } else { $sql = "SELECT entries.*, categories.cat FROM entries, categories " . "WHERE entries.cat_id = categories.id AND entries.id = " . $validentry . " ORDER BY dateposted DESC LIMIT 1;"; } $result = mysql_query($sql)or die(mysql_error()); $row = mysql_fetch_assoc($result); echo "<h2>" . $row['subject'] . "</h2><br />"; echo "<i>In <a href='viewcat.php?id=" . $row['cat_id'] ."'>" . $row ['cat'] ."</a> - Posted on " . date("D jS FY g.iA", strtotime($row['dateposted'])) ."</i>"; if(isset($_SESSION['ADMIN']) == TRUE) { echo" [<a href='updateentry.php?id=" . $row['id'] . "'>edit</a>]"; } echo "<p>"; echo nl2br($row['body']); echo "</p>"; $commsql = "SELECT * FROM comments WHERE blog_id = " . $validentry . " ORDER BY dateposted DESC;"; $commresult = mysql_query($commsql); $numrows_comm = mysql_num_rows($commresult); if(isset($_SESSION['USERNAME']) == TRUE) { if($numrows_comm == 0) { echo "<p>No comments.</p>"; } else { $i = 1; while($commrow = mysql_fetch_assoc($commresult)) { echo "<a name='comment" . $i . "'>"; echo "<h3>Comment by " . $commrow['name'] . " on " . date("D jS F Y g.iA", strtotime($commrow['dateposted'])) . "</h3>"; echo $commrow['comment']; $i++; } ?> <table> <tr> <td> <h3>Leave a comment</h3> </td> </tr> <form action="<?php echo $SCRIPT_NAME . "?id=" . $validentry; ?>" method="post"> <tr> <td>Comments</td> <td><textarea name="comment" rows="10" cols="50"></textarea></td> </tr> <tr> <td></td> <td><input type="submit" name="submit" value="Add Comment"></td> </tr> <tr> <td> <font size="-2">Do not post inapropriate comments or they will be deleted</font> </td> </tr> </form> </table> <?php } } else { echo "Login to view/add comments!"; } require("footer.php"); ?> Quote Link to comment Share on other sites More sharing options...
S A N T A Posted May 20, 2008 Author Share Posted May 20, 2008 i don't see where the error is sorry I'm very new to PHP Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 20, 2008 Share Posted May 20, 2008 the form will only display if both of these conditions is true: if(isset($_SESSION['USERNAME']) == TRUE) { AND if ($numrows_comm != 0) { i suspect that one of those conditions isn't true, so you don't see the form. Quote Link to comment Share on other sites More sharing options...
S A N T A Posted May 20, 2008 Author Share Posted May 20, 2008 EDIT: ok i got it to work now i have another problem when you push the submit button it refreshes the page and the page is all messed up Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 20, 2008 Share Posted May 20, 2008 i assume by 'messed up' you mean the page layout is messed up. you might want to copy the HTML and figure out what it takes to fix it, then apply that fix to your code. Quote Link to comment Share on other sites More sharing options...
S A N T A Posted May 20, 2008 Author Share Posted May 20, 2008 yes thats what i would like it to do Quote Link to comment Share on other sites More sharing options...
S A N T A Posted May 20, 2008 Author Share Posted May 20, 2008 also i want to restrict HTML and having nothing in the comments box so i tried this code: if($_POST['submit']) { if($_POST['comment']) == "" { echo "Please right a comment" } but it did not work Quote Link to comment Share on other sites More sharing options...
phpzone Posted May 20, 2008 Share Posted May 20, 2008 if ( $_POST['submit'] ) { if ( $_POST['comment'] == "" ) { echo "Please right a comment"; } Your second if had a close bracket in the wrong place. echo was missing ';' Quote Link to comment Share on other sites More sharing options...
S A N T A Posted May 21, 2008 Author Share Posted May 21, 2008 that sort of worked but it still allowed someone to submit a comment it just echoed "Please right a comment" Quote Link to comment Share on other sites More sharing options...
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.