onthespot Posted August 17, 2009 Share Posted August 17, 2009 Ok So i have a problem. I have a piece of code that is capable of taking information from three different forms. <?php if (!empty($_POST)) { if($submissionFrom = "form1") { $query="INSERT INTO ".TBL_AWARDS." VALUES (NULL, '$type','$user', now(), '$acomment')"; 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_RECOGNITION." VALUES (NULL, '$type2','$user2', now(), '$comment2')"; 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 if($submissionFrom = "form3") { $query3="INSERT INTO warnings VALUES (NULL, '$type3','$user3', now(), '$comment3')"; if(!$comment3 || strlen($comment3 = trim($comment3)) == 0) echo "Comment not entered"; else if(!$comment3 || strlen($comment3 = trim($comment3)) < 10) echo "Comment too short, must be 10 characters at least"; else if (!$comment3 || strlen($comment3 = trim($comment3)) > 10){ echo "".$_SESSION['username'].", you have warned ".$_POST['warninguser']." "; mysql_query($query3);} } else { echo "There is an error with the forms?"; } } ?> It will not work with the 2nd and 3rd forms meaning that there must be an error with the else if? When i use just IF not else if, it works, but still displays errors for the other 2 forms as they arent submitted. Any way around this? Link to comment https://forums.phpfreaks.com/topic/170709-post-issue-modified-question/ Share on other sites More sharing options...
rhodesa Posted August 17, 2009 Share Posted August 17, 2009 in your IF statements, use == not = Link to comment https://forums.phpfreaks.com/topic/170709-post-issue-modified-question/#findComment-900354 Share on other sites More sharing options...
onthespot Posted August 17, 2009 Author Share Posted August 17, 2009 Hey, I did this but then it ran the else statement, tried if with both if and else if. Same result. Went all the way through and ran the ELSE statement Link to comment https://forums.phpfreaks.com/topic/170709-post-issue-modified-question/#findComment-900371 Share on other sites More sharing options...
onthespot Posted August 17, 2009 Author Share Posted August 17, 2009 Can anyone help me? Link to comment https://forums.phpfreaks.com/topic/170709-post-issue-modified-question/#findComment-900393 Share on other sites More sharing options...
rhodesa Posted August 18, 2009 Share Posted August 18, 2009 where is the value of $submissionFrom set? can you post your updated code? Link to comment https://forums.phpfreaks.com/topic/170709-post-issue-modified-question/#findComment-900547 Share on other sites More sharing options...
bubbasheeko Posted August 18, 2009 Share Posted August 18, 2009 in your IF statements, use == not = rhodesa is right, if you only use one = you are setting the variable and not comparing it to the desired variable contents. if($submissionFrom == "form1") elseif ($submissionFrom == "form2") elseif ($submissionFrom == "form3") That would explain why it won't go past the first one because when it checks the first if statement it will set $submissionFrom to "form1" which of couse will fail on all subsequent checks. Link to comment https://forums.phpfreaks.com/topic/170709-post-issue-modified-question/#findComment-900636 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.