ajax data response always 0 in php mysql

前端 未结 2 1309
清歌不尽
清歌不尽 2021-01-29 07:28

I want to load some data from mysql to a div via ajax php. The id field which is auto increment is always equal to zero.

I have tried using get, post etc but none is wor

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-29 08:01

    Start with debugging your actual result from the database.

    if (isset($_REQUEST['customer_id'])) {
    
            $id = intval($_REQUEST['customer_id']);
            $query = "SELECT * FROM customers WHERE customer_id=:id";
            $stmt = $pdo->prepare( $query );
            $stmt->execute(array(':id'=>$id));
            $row=$stmt->setFetchMode(PDO::FETCH_ASSOC);
    

    You are NOT checking for errors.

    Two suggestions:

    1) You are using . If you inspected the resultset you could see what is wrong with that. Just output the result in the (wrongly named) $row variable with print_r() and the like. I am sure you will see what went wrong.

    2) I strong advise AGAINST using $_REQUEST. It is lazy and errorprone. Do you know where the 'customer_id' came from? Session? Cookie? POST? Or Get? If you are passing information via GET => use GET

提交回复
热议问题