-1

i want to export two different type of xlsx file based on radio button .

    $sel = $_POST['sel'];
       echo $sel;

    if(isset($_POST['search'])){

        if($sel == 'board')
        {
         header('Location: export_data1.php? 
       num='.$_POST['staff']);  
       die(); 
        }
       else
       {

         header('Location: export_data2.php? 
          num='.$_POST['desg']);
         die(); 

        }
       }

how to call another php file based on my radio button.Is there any other alternate way to call php file with passing arguments?

7
  • possible duplicate of stackoverflow.com/questions/5678567/… Commented Nov 20, 2018 at 6:47
  • i try that method not working in my form Commented Nov 20, 2018 at 7:41
  • An alternative could be to have bog standard links to your files. Commented Nov 20, 2018 at 8:05
  • What's the problem here, what isn't working? Commented Nov 20, 2018 at 8:07
  • An aside: you might want to url encode your query string. See url_encode and/or http_build_query. Commented Nov 20, 2018 at 8:10

1 Answer 1

0

Your page of form where you will create form

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<form action="<?= $_SERVER['PHP_SELF'] ?>"method="post">
    <!-- radio button -->
    <input type="radio" name="sel" value="board">
    <input type="radio" name="sel" value="your_other_value">
    <!-- radio button -->
   <!-- Drop Down -->
    <input type="option" name="boardlist" value="board">
    <input type="option" name="desgwise" value="Designation">
    <!-- radio button -->

    <input type="hidden" name="staff">
    <input type="hidden" name="desg">
    <input type="submit" name="search">
</form>
</body>
</html> 

This is your export_data1.php file

<?php
if(isset($_POST['search'])){
    if($sel == 'board'){
        header('Location: export_data.php?num='.$_POST['boardlist'];
    } else {
        header('Location: export_data1.php?num='.$_POST['desgwise'];
    }
}
?>

export_data & export_data1 have different format for export xlsx file

Sign up to request clarification or add additional context in comments.

3 Comments

Is this Jeopardy? What's different with this approach here? What's $sel?
I assume the difference here is that instead of having two separate export scripts, you are merging them into one script. I think I prefer the separation of responsibility, unless the code is practically identical. Differentiated URLs could also be a good thing.
i separate into two files. action="export_data1.php?desg=<?php echo $desg ?>" is it correct method to passing parameters

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.