Jump to content

POST issue (modified question)


onthespot

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.