簡體   English   中英

提交表單后刷新頁面以顯示操作結果

[英]refreshing page after submitting form to display result of the action made

我認為我的代碼有問題,我的頁面顯示了可用的作業列表,其中有兩個按鈕,一個用於顯示作業配置文件“ profile”,第二個用於申請作業“ apply”,單擊“應用”時的預期結果是使應用的作業從所有可用作業的列表中消失。 該代碼在localhost上正常工作,但是將其上傳到服務器后,我必須在單擊Apply后刷新頁面以查看操作的結果。 這是AvailableJobs.php的代碼:

 <?php $sql1= "SELECT * FROM Job"; // select all the Job
$result1= mysqli_query($conn,$sql1);                 
while($row1=mysqli_fetch_array($result1))
{ $JobName= $row1['JobName'];
    $JID= $row1['JobID']; 
    $OrgID= $row1['OrgID']; // get the Org ID for the available Job 

$sql10=" SELECT * FROM JobStudent WHERE JobID='$JID' AND StudentID='$SID'";
$resultss = mysqli_query($conn,$sql10);
$numResults = mysqli_fetch_array($resultss);
if ($numResults == 0) { 

 $sql2="SELECT * FROM RequestedOrganization WHERE OrgID='$OrgID'"; 
$result2= mysqli_query($conn,$sql2);                     
  while($row2=mysqli_fetch_array($result2))
{ $OrgGPA= $row2['GPA'];
    $OrgTrack= $row2['Track']; 
    $Priority= $row2['priorityGT'];
} 
 ?>  
<li><input disabled style="border:none; margin-bottom: 10px; width:100%;" name="JobName" value="<?php echo $row1['JobName'];?>"> </li> <?php
 echo "<form action='AvailableJobAction_page.php' method='POST'>
<input type='hidden' name='tempId' value='$JID'/>
<input style='border-radius: 12px; margin-bottom: 10px; background-color: #ccc;' type='submit' class='right' name='submit-btn' value='Apply' onclick='return func1()'/>
</form>"; 
echo "<form action='OrgProfileSS.php' method='POST'>
<input type='hidden' name='temppId' value='$JID'/>
<input type='hidden' name='tempppId' value='$OrgID'/>
<input style='border-radius: 12px; background-color: #ccc;' type='submit' name='submit-btnn' class='right' value='Profile'/>
</form><br/>"; ?>

這是執行頁面AvailableJobAction_page.php:

$USER=$_SESSION['login_user']; 

if (isset($_POST['submit-btn'])){ 
$Jobid=$_POST['tempId'];  // J ID


$Sql="SELECT * FROM Job WHERE JobID='$Jobid'";
$Result2= mysqli_query($conn,$Sql);
while ( $Row1 =mysqli_fetch_array($Result2)){ 
$JN= $Row1['JobName']; 
$orgid= $Row1['OrgID']; 

$Sql10="SELECT * FROM Employer WHERE EmployerID='$orgid'";
$Result10= mysqli_query($conn,$Sql10);
while ( $Row10 =mysqli_fetch_array($Result10)){ 
$EmpEmail= $Row10['EmailAccount']; 
}  

}     

$sql="SELECT * FROM Student WHERE KsuEmailStuent='$USER'"; // Get S ID 
$result2= mysqli_query($conn,$sql);
while ( $row1 =mysqli_fetch_array($result2)){ 
$StID= $row1['StudentID']; 
}  

$sql4="SELECT * FROM JobStudent WHERE StudentID='$StID' AND JobID='$Jobid'";
$result4= mysqli_query($conn,$sql4);
$rows= mysqli_num_rows($result4);
if ($rows>0){
echo "<script type='text/javascript'>alert('You Already Applied before!')</script>";
echo "<script>window.location.href='AvailableJobs.php';</script>";
}else{ 
$sql4="INSERT INTO JobStudent (JobID,StudentID,Status) VALUES ('$Jobid','$StID','Pending')"; 
$result4= mysqli_query($conn,$sql4);

$sql1="SELECT * FROM Job WHERE JobID='$Jobid'";
$result1= mysqli_query($conn,$sql1);
while ( $row2 =mysqli_fetch_array($result1)){ 
$Nos= $row2['NoOfAppliedstudnets']; 
}   
$Nos++; 
$sql3= "UPDATE Job SET NoOfstudnets='$Nos' WHERE JobID='$Jobid'"; 
$result3= mysqli_query($conn,$sql3);

$to =  $USER; // Send Email with the new Pass 
$subject = "Applied done sucsessfully!";
$message = "Your request have been sent, Please wait for response from employer and note that you can view your request status in your account home";
$message = wordwrap($message,70);
//$headers = "From : Admin@PTN.com";
if(mail($to, $subject, $message)){
echo "<script type='text/javascript'>alert('Applied done sucsessfully!')</script>";
echo "<script>window.location.href='AvailableJobs.php';</script>";
}else{
echo "<script type='text/javascript'>alert('Erorr in send Email ')</script>";
echo "<script>window.location.href='AvailableJobs.php';</script>";
}   

$to =  $EmpEmail; // Send Email with the new Pass 
$subject = "New student have Applied!";
$message = "New student have Applied to this Job ".$JN ;
$message = wordwrap($message,70);
//$headers = "From : Admin@PTN.com";
mail($to, $subject, $message);  
}
}   
else echo "<script type='text/javascript'>alert('ERROR!')</script>";

更改部分中的代碼:

$sql10=" SELECT * FROM JobStudent WHERE JobID='$JID' AND StudentID='$SID'";
$resultss = mysqli_query($conn,$sql10);

將檢查更改為第一個mysqli_num_rows而不是mysqli_fetch_array

$numResults = mysqli_num_rows($resultss);
if ($numResults == 0) { 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM