0
<?php
        if($dun==0){
     show form1 and add vaules to database
         }
        else if($toplam==0){
 show form2 and add values to database
    }
        else if($toplam==$dun){
        header('Location: member.php');
         }else{
        echo "<script> alert('Error.');history.go(-1);</script>";
        }
        ?>

How i can show two different from by the if statement

2
  • What is $dun and what is $toplam? Commented Mar 27, 2013 at 16:10
  • $dun a value from database and $toplam is a price comes from another form Commented Mar 27, 2013 at 16:15

3 Answers 3

4

You could use inline HTML by closing the <?PHP tag with ?> like this:

<?php
if($dun==0){
// start parsing HTML
?>
    <form>[...]</form>
<?PHP
} else if($toplam==0){
// start parsing second HTML
?>
    <form>[...]</form>
<?PHP
}
else if($toplam==$dun){
    header('Location: member.php');
}else{
    echo "<script> alert('Error.');history.go(-1);</script>";
}
?>
Sign up to request clarification or add additional context in comments.

1 Comment

I think this is what i need i will try and come back Thank you
2

If OOP is not used and you are unfamiliar with OOP programming and MVC framework or html rendering then you could do the following:

form1.php file holds the HTML for form 1
form2.php file holds the HTML for form 2

if ($dun == 0) {
    include('form1.php');
//add values to database
} else if ($toplam == 0) {
    include('form2.php');
//add values to database
}

1 Comment

I have no idea about OOP and MVC im working with php mysql and html
0

Couldn't you just echo the forms the same way you echo'd the javascript?

<?php
        if($dun==0){
          echo '
             <form name="form1"><input type="submit" name="submit1" /></form>
          ';
         }
        else if($toplam==0){
          echo '
             <form name="form2"><input type="submit" name="submit2" /></form>
          ';
         }
        else if($toplam==$dun){
            header('Location: member.php');
         }else{
            echo "<script> alert('Error.');history.go(-1);</script>";
        }
?>

And if you wanted to insert data into your database depending on the if statements then you could add functions:

<?php

  function doForm1(){
     //MYSQL HERE
  }

  function doForm2(){
     //MYSQL HERE
  }

        if($dun==0){
          echo '
             <form name="form1"><input type="submit" name="submit1" /></form>
          ';
          doForm1();
         }
        else if($toplam==0){
          echo '
             <form name="form2"><input type="submit" name="submit2" /></form>
          ';
          doForm2();
         }
        else if($toplam==$dun){
            header('Location: member.php');
         }else{
            echo "<script> alert('Error.');history.go(-1);</script>";
        }
?>

3 Comments

That's alright bud, let me know if you need any further assistance.
I have used @Luceos solution way and worked perfect for me thank you for all
Click the tick on his answer :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.