Предупреждение показывается, но данные не обновляются и не могут нажать кнопку «ОК» предупреждения - PullRequest
0 голосов
/ 30 ноября 2018

My Alert показывает, что обновление успешно обновлено, но данные не обновляются в базе данных и не могут нажать кнопку ОК оповещения.Вот мой PHP-код для upresult.php.Надеюсь, что это будет полезно.Заранее спасибо

мой jquery

 $(document).ready(function(){

        $("#form1").submit(function(event){
            event.preventDefault();
            var formData = new FormData(this);
              $.ajax({

                 url:"upresult.php",
                 type:"POST",
                 data:formData,
                 async:true,
                 success:function(data) {
                   alert(data);

                },
                cache:false,
                contentType:false,
                processData:false
            });
         });
    });

upresult.php

<?php
    include("connection.php");

    $no=trim($_POST['upno']);
    $name=trim($_POST['upname']);
    $mob=trim($_POST['upmob_no']);
    $dob=trim($_POST['updob']);
    $add=trim($_POST['upadd']);
    $photo=trim($_FILES['upphoto']['name']);
    $gen=trim($_POST['gender']);
    $cn=trim($_POST['upcountry']);
    $st=trim($_POST['upstate']);
    $ct=trim($_POST['upcity']);

    $qry="update stud set stud_name='".$name."',mobile='".$mob."',dob='".$dob."',address='".$add."',gender='".$gen."',country='".$cn."',state='".$st."',city='".$ct."' where stud_no='".$no."'";
    $data=mysqli_query($conn,$qry);
    if($data)
    {
        echo '<script language="javascript">';
        echo 'alert("Updated Successfully")';
        echo '</script>';
    }
    else {
        echo '<script language="javascript">';
        echo 'alert("Cannot update record")';
        echo '</script>';
    }
?>

1 Ответ

0 голосов
/ 30 ноября 2018

Вы хотите предупредить оповещение.Попробуйте отредактировать свою структуру управления потоком следующим образом:

<?php

    include("connection.php");

    // you need to validate this data before sending it to update query 
    $no=trim($_POST['upno']);
    $name=trim($_POST['upname']);
    $mob=trim($_POST['upmob_no']);
    $dob=trim($_POST['updob']);
    $add=trim($_POST['upadd']);
    $photo=trim($_FILES['upphoto']['name']);
    $gen=trim($_POST['gender']);
    $cn=trim($_POST['upcountry']);
    $st=trim($_POST['upstate']);
    $ct=trim($_POST['upcity']);

    // this parameters should be binded to avoid SQL injection
    $query = "
        update stud 
        set
            stud_name = '$name',
            mobile = '$mob', 
            dob = '$dob', 
            address = '$add',
            gender = '$gen',
            country = '$cn',
            state = '$st',
            city = '$ct'
        where stud_no = '$no';
    ";

    /** This may be query for checking.
    *   Just execute it after first query and grab response from it.
    *   Depends of response you will return appropirate text message.
    */
    $checkUpdateQuery = "
        select if(count(*) = 1, true, false) as response
        from stud
        where stud_name = '$name',
        and mobile = '$mob', 
        and dob = '$dob', 
        and address = '$add',
        and gender = '$gen',
        and country = '$cn',
        and state = '$st',
        and city = '$ct'
        and stud_no = '$no'; 
    ";

    /** mysqli_query will return false only if some error occurred. 
    *   In other cases you will get true, 
    *   so you need to check if data is updated by another query.
    */
    $data = mysqli_query($conn, $query);

    echo $data ? 'Updated Successfully' : 'Cannot update record';

Несколько вещей, которые вы должны учитывать, - если у вас есть определенное свойство stud_no в базе данных, mysqli_query возвращает FALSE в случае сбоя.Для успешных запросов SELECT, SHOW, DESCRIBE или EXPLAIN mysqli_query () вернет объект mysqli_result.Для других успешных запросов mysqli_query () вернет TRUE.

Если вы хотите, мы можем изменить этот запрос.Можете ли вы использовать PDO вместо mysqli?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...