Окно подтверждения перед запуском php-скрипта

<?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-страницу при нажатии кнопки, если пользователь подтвердит, что страница должна перенаправляться на домашнюю страницу.


person aBDYsINGH    schedule 21.07.2017    source источник


Ответы (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 имеет почти такой же код, но с запросом на обновление вместо запроса на выборку.

person aBDYsINGH    schedule 28.07.2017