我有一些表格从下面的代码中的herf ='?id ='获取重要值,问题是当我提交表单时刷新页面而我失去了herf ='?id ='的值,我需要一种方法来阻止代码在提交后刷新?
print ("
<form action='<?php echo $PHP_SELF;?>' method='post' class='f'>
<input type='text' name='subject' placeholder='العنوان'></input>
<textarea name='tmessage' placeholder='الموضوع'></textarea>
<input type='submit' name='t_submit' value='انشاء'></input>
</form>");
$tsubject=$_POST['subject'];
$tmessage=$_POST['tmessage'];
$tsubmit=$_POST['t_submit'];
$ttdate=date ("Y-m-d");
if(isset($tsubmit)){
$int=mysql_query("INSERT INTO tickets(id,u_id,message,subject,date,status)
VALUES('','$_SESSION[id]','$tmessage','$tsubject','$ttdate','0')");
if($int) { echo "تم انشاء التذكرة بنجاح";} else{ echo "خطاء"; }
}
$gtk=mysql_query("SELECT * FROM tickets WHERE u_id='$_SESSION[id]'");
while($ftk=mysql_fetch_object($gtk)){
if($ftk->status == 0) { $tkst= "معلقة"; }
if($ftk->status == 1) { $tkst= "مجابه"; }
print("<a href='tickets.php?tkid=$ftk->id' class='f'>$ftk->subject</a> .
$tkst");
}
$tkid=$_GET['tkid'];
$uig=mysql_query("SELECT * FROM users WHERE id='$_SESSION[id]'");
$fuig=mysql_fetch_object($uig);
$gm=mysql_query("SELECT * FROM tickets WHERE id='$tkid'");
$fgm=mysql_fetch_object($gm);
print ("<fieldset>
<legend>$fuig->username </legend>
$fgm->message
</fieldset>");
$grs=mysql_query("SELECT * FROM responses WHERE t_id='$tkid' ORDER BY id
ASC");
while($fgrs=mysql_fetch_object($grs)){
print("$fgrs->response <br>");
}
print("
<form action='<?php echo $PHP_SELF;?>' method='post'>
<textarea name='response'></textarea>
<input type='submit' name='rsubmit' value='ارسل'></input>
</form>
");
$response=$_POST ['response'];
$rsubmit=$_POST ['rsubmit'];
$tdate=date ("Y-m-d");
if(isset($rsubmit)){
$ir=mysql_query("INSERT INTO responses(id,t_id,response,r_date) VALUES
('','$tkid','$response','$tdate')");
if($ir) { echo "تم ارسال الرد";
} else { echo "خطاء";}
}
?>
答案 0 :(得分:0)
您可以将值存储在隐藏字段中并使用表单提交,以便在页面刷新时使其可用。这样您就不必编写新脚本了。
print ("
<form action='<?php echo $PHP_SELF;?>' method='post' class='f'>
<input type='text' name='subject' placeholder='العنوان'></input>
<textarea name='tmessage' placeholder='الموضوع'></textarea>
<input type='hidden' name='id' value='$_GET['id']'></input>
<input type='submit' name='t_submit' value='انشاء'></input>
</form>");
$id=$_POST['id'];