onthespot Posted July 17, 2009 Share Posted July 17, 2009 <? $from1=$_SESSION['username']; $to1=$_GET['news']; $comment1=$_POST['comment']; $query="INSERT INTO ".TBL_NEWSCOMMENTS." VALUES (NULL '$to1','$comment1', now(), $from1)"; if (!empty($_POST)) { if(!$comment1 || strlen($comment1 = trim($comment1)) == 0) echo "Comment not entered"; else if(!$comment1 || strlen($comment1 = trim($comment1)) < 10) echo "Comment too short, must be 10 characters at least"; else if (!$comment1 || strlen($comment1 = trim($comment1)) > 10){ echo "".$_SESSION['username'].", you have added a comment "; mysql_query($query);}} ?> <form action="" method="POST"> <textarea name="comment" rows="4" cols="66" ></textarea> <div align="right"><input type="submit" name="submit" value="Add Comment"></div> </form> <br> Can anyone see why this wouldn't work? Just doesn't add to the DB Quote Link to comment https://forums.phpfreaks.com/topic/166336-solved-just-dont-get-this/ Share on other sites More sharing options...
ignace Posted July 17, 2009 Share Posted July 17, 2009 $to1=$_GET['news']; if (empty($to1)) /*do something*/; $from1=$_SESSION['username']; if (!empty($_POST)) { $comment1=$_POST['comment']; if(!$comment1 || strlen($comment1 = trim($comment1)) == 0) { echo "Comment not entered"; } else if(!$comment1 || strlen($comment1 = trim($comment1)) < 10) { echo "Comment too short, must be 10 characters at least"; } else if (!$comment1 || strlen($comment1 = trim($comment1)) > 10) { echo "".$from1.", you have added a comment "; $query="INSERT INTO ".TBL_NEWSCOMMENTS." VALUES (NULL '$to1','$comment1', now(), $from1)"; mysql_query($query); } } Quote Link to comment https://forums.phpfreaks.com/topic/166336-solved-just-dont-get-this/#findComment-877134 Share on other sites More sharing options...
onthespot Posted July 17, 2009 Author Share Posted July 17, 2009 That isn't the solution, I just can't work it out!! Quote Link to comment https://forums.phpfreaks.com/topic/166336-solved-just-dont-get-this/#findComment-877141 Share on other sites More sharing options...
onthespot Posted July 17, 2009 Author Share Posted July 17, 2009 ok so this is using two tables in one. <? $from1=$_SESSION['username']; $to1=$_GET['news']; $comment1=$_POST['comment']; $query="INSERT INTO ".TBL_NEWSCOMMENTS." VALUES (NULL '$to1','$comment1', now(), $from1)"; if (!empty($_POST)) { if(!$comment1 || strlen($comment1 = trim($comment1)) == 0) echo "Comment not entered"; else if(!$comment1 || strlen($comment1 = trim($comment1)) < 10) echo "Comment too short, must be 10 characters at least"; else if (!$comment1 || strlen($comment1 = trim($comment1)) > 10){ echo "".$_SESSION['username'].", you have added a comment "; mysql_query($query);}} ?> <form action="" method="POST"> <textarea name="comment" rows="4" cols="66" ></textarea> <div align="right"><input type="submit" name="submit" value="Add Comment"></div> </form> <br> That is the code for the comment being entered into the newscomments table. The newsid field in that table is a foreign key to a table called news. The newsid field in table news is a primary key. So as the URL displays news=newsid from the news table, GET is used to carry that over when I submit the form. As you can see this isn't populating the table that looks like the following, id | newsid | comment | date | user(that posts the comment) Anyone got any idea? thanks Quote Link to comment https://forums.phpfreaks.com/topic/166336-solved-just-dont-get-this/#findComment-877158 Share on other sites More sharing options...
onthespot Posted July 17, 2009 Author Share Posted July 17, 2009 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/166336-solved-just-dont-get-this/#findComment-877175 Share on other sites More sharing options...
ignace Posted July 19, 2009 Share Posted July 19, 2009 $to1=$_GET['news']; if (empty($to1)) /*do something*/; $from1=$_SESSION['username']; if (!empty($_POST)) { $comment1=$_POST['comment']; if (!$comment1) { //=strlen($comment1)==0 echo "Comment not entered"; // odd at first but this checks if their is a character at position 10 (array is 0-based) if their isn't $comment1 < 10 if their is it atleast contains 10 characters. } else if (!isset($comment1[9])) { echo "Comment too short, must be 10 characters at least"; } else { echo "".$from1.", you have added a comment "; $query="INSERT INTO ".TBL_NEWSCOMMENTS." VALUES (NULL '$to1','$comment1', now(), $from1)"; mysql_query($query); } } Quote Link to comment https://forums.phpfreaks.com/topic/166336-solved-just-dont-get-this/#findComment-878268 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.