ambo Posted March 23, 2009 Share Posted March 23, 2009 Ok im trying to make it so that when some one post in a forum they cant post an empty reply so the form post to this process page which will grab the data and theres a function for uploading it Only Problem is that when you actually have text in there it says you must right something now i am useing a ready form tag which is set to false at error so it doesnt upload and that works fine except it still triggers and error when theres text <?PHP function addforumanswer(){ $post_answer = true; $tbl_fanswer="forum_answer"; // Table name // Get value of id that sent from hidden field $id=$_POST['id']; // Find highest answer number. $sql="SELECT MAX(a_id) AS Maxa_id FROM $tbl_fanswer WHERE question_id='$id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); // add + 1 to highest answer number and keep it in variable name "$Max_id". if there no answer yet set it = 1 if ($rows) { $Max_id = $rows['Maxa_id']+1; } else { $Max_id = 1; } // get values that sent from form $a_name=$_POST['a_name']; $a_answer=$_POST['a_answer']; if ($a_answer <= 0){ $post_answer = false; echo "you Must Type Something"; } $a_answer = str_replace("<", "", $a_answer); $a_answer = str_replace(">", "", $a_answer); //new lines $a_answer = nl2br($a_answer); $datetime=date("d/m/y H:i:s"); // create date and time // Insert answer if ($post_answer == true){ $sql2="INSERT INTO $tbl_fanswer(question_id, a_id, a_name, a_answer, a_datetime)VALUES('$id', '$Max_id', '$a_name', '$a_answer', '$datetime')"; $result2=mysql_query($sql2); if($result2){ echo "Successful<BR>"; echo("<meta http-equiv=\"refresh\" content=\"1;url=../view_topic.php?id=$id\"/>"); $tbl_fquestion="forum_question"; $sql3="UPDATE $tbl_fquestion SET reply='$Max_id' WHERE id='$id'"; $result3=mysql_query($sql3); } else { echo "ERROR"; } mysql_close(); } } ?> Link to comment https://forums.phpfreaks.com/topic/150755-form-verification-always-posts-errors/ Share on other sites More sharing options...
samona Posted March 23, 2009 Share Posted March 23, 2009 try the function empty(); if (empty($a_answer )){...} Link to comment https://forums.phpfreaks.com/topic/150755-form-verification-always-posts-errors/#findComment-792011 Share on other sites More sharing options...
Yesideez Posted March 23, 2009 Share Posted March 23, 2009 empty() is the key but you'll probably want to negate it - you want the if() statement to continue if the post is NOT empty... if (!empty($post)) { Link to comment https://forums.phpfreaks.com/topic/150755-form-verification-always-posts-errors/#findComment-792016 Share on other sites More sharing options...
ambo Posted March 23, 2009 Author Share Posted March 23, 2009 Hmm So your saying <?PHP if (empty($a_answer)){ $readyform = false; } Link to comment https://forums.phpfreaks.com/topic/150755-form-verification-always-posts-errors/#findComment-792028 Share on other sites More sharing options...
Yesideez Posted March 23, 2009 Share Posted March 23, 2009 If that's how you're going with it, that looks fine. Link to comment https://forums.phpfreaks.com/topic/150755-form-verification-always-posts-errors/#findComment-792030 Share on other sites More sharing options...
ambo Posted March 23, 2009 Author Share Posted March 23, 2009 That worked awsome Thanks Link to comment https://forums.phpfreaks.com/topic/150755-form-verification-always-posts-errors/#findComment-792036 Share on other sites More sharing options...
Yesideez Posted March 23, 2009 Share Posted March 23, 2009 If solved please click the "TOPIC SOLVED" button in the bottom left - thanks Link to comment https://forums.phpfreaks.com/topic/150755-form-verification-always-posts-errors/#findComment-792037 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.