0

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

Edited by vzradha: n/a

7
Contributors
14
Replies
18
Views
6 Years
Discussion Span
Last Post by niths
0

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";
?>

Edited by it200219: n/a

0

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

0

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.

0

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");    
}
0

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

0

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

:-)

0

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" :)

0

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

0

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();     
}
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.