Nexy Posted June 8, 2008 Share Posted June 8, 2008 Why Hello There! I seem to be having problems with my logic here: <?php $date = mysql_real_escape_string(stripslashes(date('m-j-Y'))); $subject = mysql_real_escape_string(stripslashes($_POST['ctitle'])); $comment = mysql_real_escape_string(stripslashes(nl2br($_POST['cidedit']))); $id = $_GET['id']; $nsql = "SELECT id, user, avatar, subject, date, news FROM news WHERE id = '".$_GET['id']."'"; $nres = mysql_query($csql) OR die(mysql_error()); if($row = mysql_fetch_array($nres)) { echo "<div class='nstaff'> <p class='avatar'>"; echo "<img src='"; echo $row['avatar']; echo "' alt='' class='tinyav' /></p>"; echo "<div class='nstaffcont'>"; echo "<p class='title'>" . $row['subject'] . '</p>'; echo "<p class='usern'>By: " . $row['user'] . '<br />'; echo "Posted On: " . $row['date'] . '</p>'; echo "<p class='news'>" . $row['news'] . '</p></div></div>'; } $csql = "SELECT time, user, subject, content FROM comments WHERE newsid = '".$_GET['id']."'"; $cres = mysql_query($csql) OR die(mysql_error()); while($com = mysql_fetch_array($cres)) { echo $com['subject']; echo $com['time']; echo $com['user']; echo $com['content']; } if($_POST['cosub']) { if(!empty($subject) && !empty($comment)) { if($_SESSION['username']) { mysql_query("INSERT INTO comments(newsid, time, user, subject, content) VALUES ('".$_GET['id']."', '$date', '".$_SESSION['username']."', '$subject', '$comment')"); } else if($_COOKIE['user']) { mysql_query("INSERT INTO comments(newsid, time, user, subject, content) VALUES ('".$_GET['id']."', '$date', '".$_COOKIE['user']."', '$subject', '$comment')"); } } if(empty($subject) || empty($comment)) { echo "Error"; } } if($_SESSION['username'] || $_COOKIE['user']) { echo "<form action='#' method='post'> <fieldset id='com'> <legend>Add Comment:</legend> <p> <label for='ctitle'>Subject:</label> <input type='text' id='ctitle' name='ctitle' tabindex='6' /><br /> <label for='cidedit'>Comment:</label><br /> <textarea id='cidedit' name='cidedit' rows='6' cols='35' tabindex='7'></textarea> </p> <input type='submit' id='cosub' name='cosub' value='Add Comment' tabindex='8' /> <input type='reset' value='Clear Comment' tabindex='9' /> </fieldset> </form>"; } else if(!$_SESSION['username'] || !$_COOKIE['user']) { echo "Please login to post comments."; } ?> The query right here: $csql = "SELECT time, user, subject, content FROM comments WHERE newsid = '".$_GET['id']."'"; $cres = mysql_query($csql) OR die(mysql_error()); Keeps outputting, query is empty and stops the preceding and the code after it to stop displaying on the page. Shouldn't it just not show anything if it's empty? If I was to take that part out, the is statement here: if($_POST['cosub']) { if(!empty($subject) && !empty($comment)) { if($_SESSION['username']) { mysql_query("INSERT INTO comments(newsid, time, user, subject, content) VALUES ('".$_GET['id']."', '$date', '".$_SESSION['username']."', '$subject', '$comment')"); } else if($_COOKIE['user']) { mysql_query("INSERT INTO comments(newsid, time, user, subject, content) VALUES ('".$_GET['id']."', '$date', '".$_COOKIE['user']."', '$subject', '$comment')"); } } if(empty($subject) || empty($comment)) { echo "Error"; } } It still inserts into the db even if subject or comment is empty. This is an included script, so session_start() and setting the cookie are before the <html>. Any help would be appreciated. Thank You! Quote Link to comment Share on other sites More sharing options...
webent Posted June 8, 2008 Share Posted June 8, 2008 perhaps "empty" isn't catching it... try ... if(!empty($subject) || if ($subject == "") && !empty($comment) || if ($comment == "")) Try that in the appropriate locations and see if it makes a difference... And I'm not sure about this though ... I think you need an "isset()" or "!isset()" ... if($_SESSION['username']) like ... if(isset($_SESSION['username'])) Quote Link to comment Share on other sites More sharing options...
Nexy Posted June 8, 2008 Author Share Posted June 8, 2008 I did !isset and that was fixed. Any ideas on the query is empty part? Thank You! Quote Link to comment Share on other sites More sharing options...
webent Posted June 8, 2008 Share Posted June 8, 2008 perhaps here... newsid = '".$_GET['id']."'"; try this... newsid = '{$_GET['id']}'; Whoops, was looking at wrong block of code... nevermind the stuff above ... Try getting rid of the ... OR die(mysql_error()); $cres = mysql_query($csql) OR die(mysql_error()); and try this instead, see if it gives you any additional info... if (!$cres) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $csql; die($message); } Quote Link to comment Share on other sites More sharing options...
Nexy Posted June 8, 2008 Author Share Posted June 8, 2008 It still gives me Query was Empty. I'll post a picture of the table inside mysql. Hope that helps a bit. Quote Link to comment Share on other sites More sharing options...
webent Posted June 8, 2008 Share Posted June 8, 2008 Just curious, did you go into phpmyadmin and check what is actually in the table, make sure everything is kosher, the way it should be, all data accounted for and correct? Quote Link to comment Share on other sites More sharing options...
AndyB Posted June 8, 2008 Share Posted June 8, 2008 Actually, I'd expect the error to be as a result of this: $nsql = "SELECT id, user, avatar, subject, date, news FROM news WHERE id = '".$_GET['id']."'"; $nres = mysql_query($csql) OR die(mysql_error()); Notice that you define $nsql as the querystring and then use $csql when you execute the query ... $csql has no value!! Quote Link to comment Share on other sites More sharing options...
webent Posted June 8, 2008 Share Posted June 8, 2008 My God, LOL... you're right AndyB ... I never seen that little typo, definately time to get new glasses... Quote Link to comment Share on other sites More sharing options...
Nexy Posted June 8, 2008 Author Share Posted June 8, 2008 Wow . Thank You so much, It works now. :D :D 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.