我需要使用 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>
任何帮助都会很棒。我真的需要让这一切顺利进行,这样我才能继续前进。
如果我不够具体:
我需要选择菜单选项,以便在选择并提交时能够重定向到新页面。
此外,如果有人可以帮助我将通过选择菜单和文本框输入的值添加到我的数据库中,那就太棒了!!
最佳答案
替换下面的代码并去掉重定向功能。
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");
}
尝试这个并发布任何错误。
关于PHP 页面重定向取决于 jQuery selectmenu 选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38710940/