我正在创建一个支持票系统,现在我想知道一些事情,我无法弄清楚如何在每张票上制作回复系统。问题是我不知道如何存储回复并为每张票加载它们。例如,如果票证像dashboard.php?id = 3那么只加载来自该滴答ID的回复,如果它有问题,就像其他票证一样,这是我目前的代码:
//这是所有用户票的加载
if (!isset($_GET['action']))
{
echo "
</br><div class='dashboard_info'>Dobrodosli, ovo je vas dashboard. Njegova svrha je pomaganje novim clanovima nase zajednice ali i starijima koji
imaju poteskoce u snalazenju sa radom User Control Panela. Koriscenjem istog imate razne opcije, ali glavna svrha ovog dela jeste resavanje raznih problema otvaranjem tiketa i slanjem upita.
Ispod mozete videti vase aktivne tikete ukoliko imate istih, ukoliko vam treba pomoc oko necega mozete poslati tiket klikom na Novi Tiket.</div>
</br></br></br><center>
<div class='dataTables'>
<table>
<tr>
<td CLASS='MYTABLE'>Naslov Tiketa</td>
<td CLASS='MYTABLE'>#ID Tiketa</td>
<td CLASS='MYTABLE'>Status Tiketa</td>
<td CLASS='MYTABLE'>Vrsta Tiketa</td>
<td CLASS='MYTABLE'>Datum</td>
</tr>
</center>
";
$username = $_COOKIE['username'];
$author = mysqli_real_escape_string($con, $username);
$query = "SELECT * FROM Dashboard WHERE Postavio = '$author'";
$result = mysqli_query($con,$query);
while( $row = mysqli_fetch_array($result,MYSQLI_ASSOC) )
{
$ID = clear($row['ID']);
$Naslov = clear($row['Naslov']);
$Status = clear($row['Status']);
$Vrsta = clear($row['Vrsta']);
$Datum = clear($row['Datum']);
if($Status == 0) { $statusinfo = "Otvoren"; }
else if($Status == 1) { $statusinfo = "Zatvoren"; }
else if($Status == 2) { $statusinfo = "Odgovoren"; }
echo "
<tr CLASS='MYTABLE'>
<td CLASS='MYTABLE'><a href='dashboard.php?id=$ID'>$Naslov</a></td>
<td CLASS='MYTABLE'><a href='dashboard.php?id=$ID'>#0000$ID</a></td>
<td CLASS='MYTABLE'>$statusinfo</td>
<td CLASS='MYTABLE'>$Vrsta</td>
<td CLASS='MYTABLE'>$Datum</td>
<tr>
";
}
}
//这是加载id为
的页面 if(isset($_GET['id']))
{
$id = clear($_GET['id']);
$user = mysqli_real_escape_string($con, $_COOKIE['username']);
$query = "SELECT * FROM `dashboard` WHERE `Postavio` = '$username' AND `ID` = '$id'";
mysqli_query($con, $query);
$output = mysqli_num_rows($result);
if($output == 0)
{
echo "Vi ste vlasnik ovog ticketa";
exit();
}
else
{
echo "Vi niste vlasnik ovog ticketa";
}
}
但是这甚至不能正常工作,它应该从url获取id并将其与数据库中的id进行比较,看看它是否由用户制作,如果由其他人制作,则应将其返回主页。
答案 0 :(得分:1)
...它应该从url获取id并将其与数据库中的id进行比较,看看它是否由用户制作,如果由其他人制作,则应将其返回主页。
在这里查看这些陈述,
$id = clear($_GET['id']);
$user = mysqli_real_escape_string($con, $_COOKIE['username']);
$query = "SELECT * FROM `dashboard` WHERE `Postavio` = '$username' AND `ID` = '$id'";
^ it should be $user
mysqli_query($con, $query);
^ You're not storing the result set.
首先将结果集存储在变量中,然后使用mysqli_num_rows()
函数。
所以你的代码应该是这样的:
// your code
$query = "SELECT * FROM `dashboard` WHERE `Postavio` = '$user' AND `ID` = '$id'";
$result = mysqli_query($con, $query);
$output = mysqli_num_rows($result);
if($output){
// You are the owner of this ticket
echo "Vi ste vlasnik ovog ticketa";
}else{
// redirect the user to main page
header("Location: mainpage.php");
exit();
}
// your code