2016-08-02 79 views
0

我需要使用PHP重定向我的selectmenu選項。基本上,我需要能夠在選擇菜單中選擇一名教師,並且在我提交該頁面時,它會重定向到特定的教師頁面。取決於jQuery selectmenu選擇的PHP頁面重定向

<?php 
    ob_start(); 
    session_start(); 
    require_once 'dbconnect.php'; 

    if(!isset($_SESSION['client'])) { 
     header("Location: homepage_login.php"); 
     exit; 
    } 
    // select loggedin users detail 
    $res=mysql_query("SELECT * FROM clients WHERE client_id=".$_SESSION['client']); 
    $userRow=mysql_fetch_array($res); 


    if(isset($_POST['btn-nxt-page'])) { 

     $client_student_id = $_POST['client_student_id']; 
     $ss_name = $_POST['ss_name']; 

     $client_student_id = strip_tags(trim($client_student_id)); 
     $ss_name = strip_tags(trim($ss_name)); 

     $count = mysql_num_rows($result); 

    if ($count) { 

     $query = "INSERT INTO appointments(client_student_id,ss_name,) VALUES('$client_student_id','$ss_name')"; 
     $res = mysql_query($query); 
    } 

     function redirect($where){  
      header("Location: $where"); 
     } 
     if ($_REQUEST['ss_name'] == 'John'){ 
      redirect('http://localhost/homepage_loggedin_book_john.php'); 
     }elseif($_REQUEST['ss_name'] == 'Smith'){ 
      redirect('http://localhost/homepage_loggedin_book_smith.php'); 
     } 
    } 
    ?> 

這是我的HTML,你可以看到我有選項,然後在我的PHP我嘗試重定向,但它不工作...

<div class="form-group"> 
      <div class="input-group"> 
      <input type="text" name="client_student_id" class="form-control" placeholder="Enter your Student ID" required /> 
       </div> 
      </div> 
      <br> 
      <br> 

     <label for="ss" id="menu">Select a teacher</label> 
      <select name="ss_name" id="#menu"> 
       <option value="John">John</option> 
       <option value="Smith">Smith</option> 
       <option value="Greg">Greg</option> 
       <option value="Jess">Jess</option> 
      </select> 
      <br> 
      <br> 

     <div class="form-group"> 
      <button type="submit" class="btn btn-block btn-primary" name="btn-nxt-page">Next Page</button> 
      </div> 

任何幫助將是真棒。我只是非常需要這個工作,所以我可以繼續前進。

如果我不是不夠具體:

我需要selectmenu選項能夠重定向到一個新的頁面選擇和提交時。

此外,如果任何人都可以幫助我添加值,我通過selectmenu和文本框輸入到我的數據庫,這將是真棒!

+0

每次我看到'mysql_ *'和老師在同一個問題的某個地方,我死在裏面..請不要再使用它了。它已被棄用超過2年了! – icecub

+0

究竟是什麼問題?發生了什麼,或什麼不是? – Dekel

+0

當我從菜單中選擇一個選項並單擊提交時,它不會重定向到爲特定名稱創建的新PHP頁面。我只需要它重定向到一個新的頁面,當我點擊提交基於在菜單中做出的選擇 – Isabella

回答

0

替換下面的代碼,擺脫重定向功能。

if ($_REQUEST['ss_name'] == 'John'){ 
    redirect('http://localhost/homepage_loggedin_book_john.php'); 
}elseif($_REQUEST['ss_name'] == 'Smith'){ 
    redirect('http://localhost/homepage_loggedin_book_smith.php'); 
} 

if ($_REQUEST['ss_name'] == 'John') { 
    header("Location: http://localhost/homepage_loggedin_book_john.php"); 
} else if ($_REQUEST['ss_name'] == 'Smith') { 
    header("Location: http://localhost/homepage_loggedin_book_smith.php"); 
} 

試試這個,發佈任何錯誤。

+0

謝謝!但提交按鈕不起作用...正如在我按下按鈕時,沒有任何反應?我的頁面仍然不會重定向 – Isabella

+0

你有表格標籤嗎?確保在

+0

它的工作原理!非常感謝你,你不明白這對我意味着多少! – Isabella