2017-08-21 113 views
1

我想将一个variable值传递给一个url,但问题是当我第一次点击search button时,该值不会出现,当第二次点击被触发时,将显示variable值。我怎样才能解决这个问题?我认为这个错误是当我点击search button这个页面令人耳目一新时。有人可以帮我解决这个问题吗?将变量值传递给URL

这里是我的代码:

<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

+0

这意味着在第一次点击你的'$ classid'变量空值和onl然后你给它分配一些后期值 – Thamilan

+0

为什么不尝试发布请求然后在你的php中获取数据? – Jixone

+0

为什么不使用“GET”方法发送值url? –

回答

1

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

将其更改为

<form action="student.php" method="post"> 
+0

我想将值传递给url为什么要删除classid? – nethkennnnn

+0

你有一个href。如果你说

”method =“post”>,这意味着你的设置student.php在$ classid值为null。 –

+0

href标记是将值传递给student.php的人 –