我创建了一个处理重复数据的函数,如果存在重复,它将显示错误消息,该错误消息在save11.func.php
中声明为
$sql_section = mysqli_query($conn,"select *,COUNT(*) as count from schedule
natural join section
natural join strand
natural join time
where strand ='$strand' and section ='$section' and schedule.timeID = '$daym'
and day ='m' and grade = 'Grade 12'")
or die(mysqli_error($conn));
$row = mysqli_fetch_array($sql_section);
$count_s = $row['count'];
$times=date("h:i a",strtotime($row['time_start']))."-".date("h:i a",strtotime($row['time_end']));
$sections = $row['section'];
$strands = $row['strand'];
$error_s = "<span class='text-danger'>
<table width='100%'>
<tr>
<td>monday</td>
<td>$times</td>
<td>$sections</td>
<td>$strands</td>
<td class='text-danger'><b>Not Available</b></td>
</tr>
</span>
</table>";
它在如下文件中回显:
if (($count_t == 0) and ($count_r == 0) and ($count_s == 0)) {
mysqli_query($conn,"INSERT into schedule (timeID, subject, instructorID, day, room, strand, section, grade) VALUES
('$daym','$subject','$ins', 'm','$room', '$strand', '$section', 'Grade 12')");
echo "<span class='text-success'>
<table width='100%'>
<tr>
<td>monday</td>
<td>$time_t</td>
<td>Success</td>
</tr>
</table></span><br>";
}
else if ($count_t>0) echo $error_t."<br>";
else if ($count_r>0) echo $error_r."<br>";
else {echo $error_c."<br>";}
}
但是我想在自己的schedules.php中回显错误消息,以便用户不必回头,如果输入被接受,他们将停留在同一页面上并输入其他数据。 >
header("Location:../pages/scheduling.php");
是的,可以将我重定向到用户将输入的页面,但不会显示在另一个文件中声明的错误消息。
答案 0 :(得分:0)
是对的,您想在显示错误消息的另一页上显示错误消息吗?
一种解决方案是使用会话。因此,当错误消息生成时,您可以将其放在这样的会话中:
#include <boost/operators.hpp>
class C : private boost::arithmetic<C>
// ^^^^^^^^^^^^^^^^^^^^
// where the magic happens (Barton-Nackmann trick)
{
int m_value ;
public:
C(int value): m_value(value) {} ;
C& operator+=(const C& rhs) { m_value += rhs.m_value; return *this; }
C& operator-=(const C& rhs) { m_value -= rhs.m_value; return *this; }
C& operator*=(const C& rhs) { m_value *= rhs.m_value; return *this; }
C& operator/=(const C& rhs) { m_value /= rhs.m_value; return *this; }
const C& operator+() const { return *this; }
C operator-() const { return {-m_value}; }
int get_value() { return m_value; } ;
};
然后在另一页上:
session_start();
$_SESSION["defineYourNameHere"] = $error
执行此操作时,$ errorstring为空白,或者包含要显示的错误。
session_start();
$errorString = "";
if(isset($_SESSION["theNameOfTheSessionVariable"])
{
$errorString = $_SESSION["theNameOfTheSessionVariable"]
}
会检查您放置在其中的变量是否存在,以防止出现未定义变量的错误。