1

I want to pass a variable value to an url but the problem is when I first clicked the search button the value doesn't appear and when the second clicked is triggered the variable value is shown. How can i fix this? I think the fault is when i click the search button the page is refreshing. Can someone help me about this?

here's my code:

 <div class="form-inline form-padding">
                    <form action="student.php?classid=<?php echo $classid;?>" method="post">
                        <input type="text" class="form-control" name="search" placeholder="Search by ID or Name">
                        <select name="subject" class="form-control" required>
                            <option value="">Select Subject...</option>                            
                            <?php while($row = mysql_fetch_array($mysubject)): ?>
                                <option value="<?php echo $row['id']?>" <?php if($row['id']==$classid) echo 'selected'; ?>><?php echo $row['subject'];?></option>
                            <?php endwhile; ?>
                        </select>
                        <button type="submit" name="submit" id="submit" class="btn btn-primary"><i class="fa fa-search"></i> Search</button>                       
                        <a href="print.php?classid=<?php echo $classid; ?>" target="_blank"><button type="button" name="submit" class="btn btn-success"><i class="fa fa-print"></i> Print</button></a>            
                    </form>
                </div>

enter image description here

3
  • which means at first click your $classid variable has empty value and only then you are assigning some post values to it Commented Aug 21, 2017 at 5:36
  • Why dont you try post request then fetch the data in your php? Commented Aug 21, 2017 at 7:05
  • Why don't you use "GET" method for sending value url ? Commented Aug 21, 2017 at 11:58

1 Answer 1

1

in your

<form action="student.php?classid=<?php echo $classid;?>" method="post">

change it to

<form action="student.php" method="post">
Sign up to request clarification or add additional context in comments.

4 Comments

I want to pass the value to url why remove the classid?
you have the a href. if you say <form action="student.php?classid=<?php echo $classid;?>" method="post">, this mean your setting student.php in $classid value which is null.
the a href tag is the one who passes the value to student.php
<a href="print.php?classid=<?php echo $classid; ?>" target="_blank"><button type="button" name="submit" class="btn btn-success"><i class="fa fa-print"></i> Print</button></a>

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.