【问题标题】:Confirmation box before running a php script运行 php 脚本之前的确认框
【发布时间】:2017-12-27 00:46:02
【问题描述】:
<?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.


?>

我在这里连接到一个数据库。我根据我的要求解密查询字符串。在我解密查询字符串后,我将它与数据库中的一条记录进行匹配,如果一切都匹配,我需要运行更新查询。

目前我的程序正在更新它而没有确认。我需要用户按下确认按钮来运行更新查询。

我知道我需要 javascript 来跟踪用户按钮的点击。如果用户确认,我需要在按钮单击时显示 HTML 页面,否则页面应重定向到主页。

【问题讨论】:

    标签: php html api confirmation


    【解决方案1】:
    <?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 的代码几乎相同,但使用的是更新查询而不是选择查询。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-05
      • 1970-01-01
      • 2017-04-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多