我有以下表格,我正在尝试使单选按钮正常工作。我不确定为什么会这样,但是yes选项有效,而no选项今天却给我带来了一些困难。选择该选项时,它总是会说error = notproved。...我也尝试刷新chrome浏览器几次,但收效甚微:
<?php
include_once 'header2.php';
if (!isset($_POST['submit'])) {
header("Location: header2.php?ticket_reply=error");
exit();
} else {
include_once 'includes/dbh.php';
$ticket = strip_tags($_POST['ticket']);
$subject = strip_tags($_POST['subject']);
$date = strip_tags(date("Y-m-d H:i:s"));
$reply = strip_tags($_POST['reply']);
$resolve = strip_tags($_POST['resolve']);
if ($resolve == 'Yes') {
$resolve = 1;
} else {
$resolve = 0;
}
if(!$resolve) {
echo '<meta http-equiv="refresh" content="0;url=ticket.php?ticket_reply=notprovided">';
exit();
} else {
$sql = "SELECT * FROM users WHERE user_uid = ?;";
$stmt = mysqli_stmt_init($conn);
//Prepare the prepared statement
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo 'SQL statement failed';
} else {
//Bind parameters to the placeholder
mysqli_stmt_bind_param($stmt, "s", $_SESSION['u_uid']);
//Run parameters inside database
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$row = mysqli_fetch_assoc($result);
$user_id = 23;
$first = strip_tags($row['user_first']);
$last = strip_tags($row['user_last']);
$email = strip_tags($row['user_email']);
$sql2 = "INSERT INTO customers_enquiry (user_uid, ticket, first_name, last_name, subject, mailfrom, datereplied, replied_by, solved, view_reply) VALUES (?,?,?,?,?,?,?,?,?,?);";
$stmt = mysqli_stmt_init($conn);
//Prepare the prepared statement
if (!mysqli_stmt_prepare($stmt, $sql2)) {
echo 'SQL statement failed';
} else {
//Bind parameters to the placeholder
mysqli_stmt_bind_param($stmt, "ssssssssis", $_SESSION['u_uid'], $ticket, $first, $last, $subject, $email, $date, $_SESSION['u_uid'], $resolve, $reply);
//Run parameters inside database
mysqli_stmt_execute($stmt);
}
// echo "<meta http-equiv='refresh' content='0;url=ticket.php?ticket_reply=success'>";
}
}
}
根据我的理解,如果可以,如果(!$ resolve){};应该检查用户选择的单选按钮是否正确?
这是我提交到以上页面的另一页的表单:
echo '<form action="ticket_reply.php" method="POST">
<table class="ticket">
<tr><th>User ID</th><td>'.$row['user_uid'].'</td></tr>
<tr><th>Ticket No</th><td>'.$row['ticket'].'<input type="hidden" name="ticket" value="'.$row['ticket'].'"></td></tr>
<tr><th>First Name</th><td>'.$row['first_name'].'</td></tr>
<tr><th>Last Name</th><td>'.$row['last_name'].'</td></tr>
<tr><th>Subject</th><td>'.$row['subject'].'<input type="hidden" name="subject" value="'.$reply.'"></td></tr>
<tr><th>Mail From</th><td>'.$row['mailfrom'].'</td></tr>
<tr><th>Message</td></th><td>'.$row['message'].'</td></tr>
<tr><th>Date Submitted</th><td>'.$row['datesubmitted'].'</td></tr>
<tr><th>Date Replied</th><td>'.$row['datereplied'].'</td></tr>
<tr><th>Solved</th><td>'.$row['solved'].'</td></tr>
<tr><th>View Message</th><td>'.$row['view_reply'].'</td></tr>
<tr><th>Replied By</th><td>'.$row['replied_by'].' '.$_SESSION['u_permission'].' '.$_SESSION['u_moderator'].'</td></tr>';
}
echo '<tr><th>Has this been Resolved?</th><td><input type="radio" name="resolve" value="Yes">Yes<input type="radio" name="resolve" value="No">No</td></tr>
<tr><th></th><td><textarea name="reply"></textarea></tr></td>
<tr><th class="add_reply">Add Reply/Message</th><td><input type="submit" name="submit" value="Reply"></tr></td>
</table>
</form>';
答案 0 :(得分:0)
尝试一下:
if(isset($_POST['resolve']) && $_POST['resolve'] == 'Yes'){
$resolve = 1;
}else{
$resolve = 0;
}