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
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