onthespot Posted August 17, 2009 Share Posted August 17, 2009 hey, my code <?php $query="INSERT INTO ".TBL_AWARDS." VALUES (NULL, '$type','$user', now(), '$acomment')"; if (!empty($_POST)) { // processing logic if(!$acomment || strlen($acomment = trim($acomment)) == 0) echo "Comment not entered"; else if(!$acomment || strlen($acomment = trim($acomment)) < 10) echo "Comment too short, must be 10 characters at least"; else if (!$acomment || strlen($acomment = trim($acomment)) > 10){ echo "".$_SESSION['username'].", you have added an award to ".$_POST['awarduser']."'s Profile. "; mysql_query($query);}} ?> <?php $query2="INSERT INTO ".TBL_AWARDS." VALUES (NULL, '$type2','$user2', now(), '$comment2')"; if (!empty($_POST)) { // processing logic if(!$comment2 || strlen($comment2 = trim($comment2)) == 0) echo "Comment not entered"; else if(!$comment2 || strlen($comment2 = trim($comment2)) < 10) echo "Comment too short, must be 10 characters at least"; else if (!$comment2 || strlen($comment2 = trim($comment2)) > 10){ echo "".$_SESSION['username'].", you have added recognition to ".$_POST['recuser']."'s Profile. "; mysql_query($query2);}} ?> How can I seperate these so that they have a unique way of being different when i submit them?? At the moment when one is submitted, the other says no comment entered. Any way around this? Cheers Link to comment https://forums.phpfreaks.com/topic/170671-solved-two-post-forms-in-one-doc/ Share on other sites More sharing options...
Airhead315 Posted August 17, 2009 Share Posted August 17, 2009 I must be confused as to what the question is...because with 300+ posts I would hope this would be more obvious by now...If you have two POST forms submitting to the same PHP script then add a post variable to each form named "submissionForm" and have it be unique between each form: Form 1 add: <input type=hidden name=submissionForm value="form1"> Form 2 add: <input type=hidden name=submissionForm value="form2"> Change code to: <?php if (!empty($_POST)) { if($submissionFrom == "form1") { $query="INSERT INTO ".TBL_AWARDS." VALUES (NULL, '$type','$user', now(), '$acomment')"; // processing logic if(!$acomment || strlen($acomment = trim($acomment)) == 0) echo "Comment not entered"; else if(!$acomment || strlen($acomment = trim($acomment)) < 10) echo "Comment too short, must be 10 characters at least"; else if (!$acomment || strlen($acomment = trim($acomment)) > 10){ echo "".$_SESSION['username'].", you have added an award to ".$_POST['awarduser']."'s Profile. "; mysql_query($query);} } else if($submissionFrom == "form2") { $query2="INSERT INTO ".TBL_AWARDS." VALUES (NULL, '$type2','$user2', now(), '$comment2')"; // processing logic if(!$comment2 || strlen($comment2 = trim($comment2)) == 0) echo "Comment not entered"; else if(!$comment2 || strlen($comment2 = trim($comment2)) < 10) echo "Comment too short, must be 10 characters at least"; else if (!$comment2 || strlen($comment2 = trim($comment2)) > 10){ echo "".$_SESSION['username'].", you have added recognition to ".$_POST['recuser']."'s Profile. "; mysql_query($query2);} } else { echo "Where is this request coming from"; } ?> Please note that there are ALOT of coding issues with your code. For one, you insert into the database before you do your error checking... Link to comment https://forums.phpfreaks.com/topic/170671-solved-two-post-forms-in-one-doc/#findComment-900136 Share on other sites More sharing options...
onthespot Posted August 17, 2009 Author Share Posted August 17, 2009 How do i enter into the DB before error checking? Take a second look? Link to comment https://forums.phpfreaks.com/topic/170671-solved-two-post-forms-in-one-doc/#findComment-900159 Share on other sites More sharing options...
onthespot Posted August 17, 2009 Author Share Posted August 17, 2009 Where do i define submissionform? Link to comment https://forums.phpfreaks.com/topic/170671-solved-two-post-forms-in-one-doc/#findComment-900170 Share on other sites More sharing options...
onthespot Posted August 17, 2009 Author Share Posted August 17, 2009 Solved you used == and i needed =, thanks though Link to comment https://forums.phpfreaks.com/topic/170671-solved-two-post-forms-in-one-doc/#findComment-900173 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.