Reputation: 65
<?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
Upvotes: 0
Views: 8285
Reputation: 1580
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>";
}
?>
Upvotes: 0
Reputation: 6720
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>";
}
?>
Upvotes: 4
Reputation: 7653
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
}
Upvotes: 2