I have a form which will have to call two different php scripts based on the click of 2 submit buttons. Below is a sample of what I have so far

<?php
echo'<form name="form1" method="post">';
echo '<div>';
echo '<input type="submit" name="submit1" id="submit1" value="Create">';
echo '</div>'."\n";
echo '<div>';
echo '<input type="submit" name="submit1" id="submit1" value="Delete">';
echo '</div>'."\n";

if(isset($_POST["submit1"])) {
  	header("Location:script1.php");
  }
  else if(isset($_POST["submit1"])) {
  	header("Location:script2.php");    
}
?>

This doesn't seem to be working. Help please

Hi,

Try this, The issue I can see is output already started before redirect can take place.

<?php
if(isset($_POST["submit1"])) {
  	header("Location:script1.php");
  }
  else if(isset($_POST["submit1"])) {
  	header("Location:script2.php");    
}

echo'<form name="form1" method="post">';
echo '<div>';
echo '<input type="submit" name="submit1" id="submit1" value="Create">';
echo '</div>'."\n";
echo '<div>';
echo '<input type="submit" name="submit1" id="submit1" value="Delete">';
echo '</div>'."\n";
?>

Hello, Sorry but I believe this code won't work either. =/

Try this one.

<?php
if(isset($_POST["submit1"])) header("Location:script1.php");

  else if(isset($_POST["submit2"])) header("Location:script2.php");    

echo'<form name="form1" method="post">';
echo '<div>';
echo '<input type="submit" name="submit1" id="submit1" value="Create">';
echo '</div>'."\n";
echo '<div>';
echo '<input type="submit" name="submit2" id="submit2" value="Delete">';
echo '</div>'."\n";
?>

Cheers

Your IF and the ELSE IF are both checking if submit1 is set. It can only re-direct to script1 or to nowhere. Suggest that you give the two button different names and check each one.

that's what I did because it's logically wrong.

I have a form which will have to call two different php scripts based on the click of 2 submit buttons. Below is a sample of what I have so far

<?php
echo'<form name="form1" method="post">';
echo '<div>';
echo '<input type="submit" name="submit1" id="submit1" value="Create">';
echo '</div>'."\n";
echo '<div>';
echo '<input type="submit" name="submit1" id="submit1" value="Delete">';
echo '</div>'."\n";

if(isset($_POST["submit1"])) {
  	header("Location:script1.php");
  }
  else if(isset($_POST["submit1"])) {
  	header("Location:script2.php");    
}
?>

This doesn't seem to be working. Help please

Use code below and credits goes to this guy

echo'<form name="form1" method="post">';
echo '<div>';
echo '<input type="submit" name="submit1" id="submit1" value="Create">';
echo '</div>'."\n";
echo '<div>';
echo '<input type="submit" name="submit1" id="submit1" value="Delete">';
echo '</div>'."\n";

if($submit1 == "Create")
{
  header("Location:script1.php");
}
else
if($submit1 == "Delete")
{
 header("Location:script2.php");    
}

Use code below and credits goes to this guy

echo'<form name="form1" method="post">';
echo '<div>';
echo '<input type="submit" name="submit1" id="submit1" value="Create">';
echo '</div>'."\n";
echo '<div>';
echo '<input type="submit" name="submit1" id="submit1" value="Delete">';
echo '</div>'."\n";

if($submit1 == "Create")
{
  header("Location:script1.php");
}
else
if($submit1 == "Delete")
{
 header("Location:script2.php");    
}

I'm sorry but this code is wrong too. The header must be on the top I believe. it should be:

if($submit1 == "Create")  header("Location:script1.php");

if($submit1 == "Delete") header("Location:script2.php");    

echo'<form name="form1" method="post">';
echo '<div>';
echo '<input type="submit" name="submit1" id="submit1" value="Create">';
echo '</div>'."\n";
echo '<div>';
echo '<input type="submit" name="submit1" id="submit1" value="Delete">';
echo '</div>'."\n";

Please check your solutions before sending them to the forum.

Cheers

Let the thread poster come back and see if he / she tried anything rather then we spending time to check comments.

:-)

I'm sorry but this code is wrong too. The header must be on the top I believe. it should be:

if($submit1 == "Create")  header("Location:script1.php");

if($submit1 == "Delete") header("Location:script2.php");    

echo'<form name="form1" method="post">';
echo '<div>';
echo '<input type="submit" name="submit1" id="submit1" value="Create">';
echo '</div>'."\n";
echo '<div>';
echo '<input type="submit" name="submit1" id="submit1" value="Delete">';
echo '</div>'."\n";

Please check your solutions before sending them to the forum.

Cheers

purposely so that he can learn from "headers already sent" :)

I'm sorry, I get your point :)

I'm sorry, I get your point :)

No problem :)

No problem :)

yeah this should be mark as SOLVED =/

Excuse me evstevemd sir

Why I get the following error with ur prgm.

Notice: Undefined variable: submit1 in C:\wamp\www\NGOProject\twosubmit.php on line 10

Notice: Undefined variable: submit1 in C:\wamp\www\NGOProject\twosubmit.php on line 15

where is your new code?
I need to see it so that I can comment

ok now try this code.I checked it.It's working fine.

<?php
ob_start();   
echo'<form name="form1" method="post">';
echo '<div>';
echo '<input type="submit" name="submit1" id="submit1" value="Create">';
echo '</div>'."\n";
echo '<div>';
echo '<input type="submit" name="submit2" id="submit2" value="Delete">';
echo '</div>'."\n";

if(isset($_POST["submit1"])) {
      header("Location:script1.php");
      ob_end_flush(); 
  }
  else if(isset($_POST["submit2"])) {
      header("Location:script2.php");
      ob_end_flush();     
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.