2017-07-21 6 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はほとんど同じコードですが、selectクエリの代わりにupdateクエリを使用しています。

関連する問題