2017-07-21 70 views
0
<?php 
//Connect to Database 
$link = mysqli_connect('localhost', 'xxxxxxx', 'xxxxxxx', 'xxxxxxx'); 
mysqli_set_charset($link,'utf8'); 
$delistpost= htmlspecialchars($_GET["delistpost"]); 
//$request = $_SERVER['QUERY_STRING']; 
$request = $delistpost; 

//Error message on unsuccessful connection (connection failure) 
if ($link==false){ 
    //Print error information 
    echo(" ERROR: Could not connect.<br>".mysqli_connect_error()); 
} 

//Successful connection message 
else{ 
    //Split the query string taking '=' as the delimiter 
    if (strpos($request, '=')) 
    { 
     $n=split("=",$request); 
//  $queryStringType=$n[0]; 
     $offset =$n[1]; 
    } 

    $userchar = substr($offset,0,2); 
    $key = ltrim(substr($offset, 2, -1), '0'); 
    $status = substr($offset,-1,1); 

    $query = "SELECT postid FROM userwisePost WHERE postid = $key AND user_email like '$userchar%' AND status = '$status'" ; 
    $updatequery = "UPDATE userwisePost SET post_status = 'draft' WHERE postid = $key AND user_email like '$userchar%' AND status = '$status'" ; 

    //Print the confirmation of SQL query 
    $verify = mysqli_query($link,$query); 
     if(mysqli_num_rows($verify) > 0){ 

      $updateresult = mysqli_query($link,$updatequery); 
      if($updateresult==true){ 

RUN FUNCTION TO SHOW SUCCESS UPDATION. 
} 

else RUN FUNCTION TO SHOW FAILURE. 


?> 

在這裏,我連接到一個數據庫。我按照我的要求解密查詢字符串。在解密查詢字符串後,我將它與數據庫中的記錄進行匹配,如果一切都匹配,我需要運行更新查詢。運行php腳本之前的確認框

目前我的程序正在更新它沒有確認。我需要用戶按確認按鈕來運行更新查詢。

我知道我需要javascript來跟蹤用戶按鈕的點擊。如果用戶確認頁面應該重定向到主頁,我需要在按鈕點擊時顯示一個HTML頁面。

回答

0
<?php 
//Connect to Database 
include "dbconnect.php"; 


$delistpost= htmlspecialchars($_GET["delistpost"]); 
//$request = $_SERVER['QUERY_STRING']; 
//$request = $delistpost; 

    //Split the query string taking '=' as the delimiter 

    $userchar = substr($delistpost,0,2); 
    $key = ltrim(substr($delistpost, 2, -1), '0'); 
    $status = substr($delistpost,-1,1); 

    $query = "SELECT postid FROM userwisePost WHERE postid = $key AND user_email like '$userchar%' AND status = '$status'" ; 
      $verify = mysqli_query($dbconnect,$query); 

     if($verify==true){ 
      if(mysqli_num_rows($verify) > 0) 
      { 
       echo '<!DOCTYPE html> 
         <html> 
         <head> 
         <meta charset="UTF-8"> 
         <title>Confirmation</title>      
          <link rel="stylesheet" href="alertstyle.css">      
         </head> 
         <body> 
         <div class="container"> 
         <form id="contact" action="changepoststatus.php?delistpost='.$delistpost.'" method="post"> 
         <center><h3>Confirmation</h3> 
         <h4>Are you sure you want to delist your post?<br>If you wish to activate the post again, please contact the system administrator or email us at xxxxxxxxxx.</h4> 
         </center> 
          <fieldset> 
          <center> 
          <button name="delistpost" type="submit" id="contact-submit" style="width: 49%;">Confirm</button> 
          </center> 
          </fieldset> 
         </form> 
         </div> 
         </body> 
         </html>';      
      } 
     else { 
      echo  '<!DOCTYPE html> 
         <html> 
         <head> 
         <meta charset="UTF-8"> 
         <title>Failure</title>      
          <link rel="stylesheet" href="alertstyle.css">      
         </head> 
         <body> 
         <div class="container"> 
         <form id="contact" action="https://xxxxxxxxxx" method="post"> 
         <center><h3>Failure</h3> 
         <h4>Something went wrong<br>Please contact the system administrator or email us at xxxxxxxxxx.</h4> 
         </center> 
          <fieldset> 
          <center> 
          <button name="delistpost" type="submit" id="contact-submit" style="width: 49%;">Homepage</button> 
          </center> 
          </fieldset> 
         </form> 
         </div> 
         </body> 
         </html>';      

     } 
    } 

?> 

這就是我做到的。我按下按鈕後再打另一個鏈接。 changepoststatus.php具有幾乎相同的代碼,但具有更新查詢而不是選擇查詢。