我需要使用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选项,以便在选择并提交时能够重定向到新页面。
此外,如果有人能帮我把我通过选择菜单和文本框输入的值添加到我的数据库中,那就太棒了!!
替换下面的代码并去掉重定向函数。
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");
}
请尝试此操作并发布任何错误。