I am using a prepared statement to get information from a database. It doesn't echo anything. Thanks. $query = 'SELECT * FROM mammals WHERE postid = ?'; $stmt = $db->stmt_init(); if ($stmt->prepare($query)) { $stmt->bind_result('d', $postid); $stmt->execute(); $data = $stmt->fetch_assoc(); echo $data['postid']; } PHP:
Thanks for responding. Yes. Just above this statement I posted info and it worked. Now I am trying to display the information that was just entered into the form and database. $query = "insert into mammals05 (postid, title, price, discription, email) values (?, ?, ?, ?, ?)"; $stmt = $db->stmt_init(); if ($stmt->prepare($query)) { $stmt->bind_param('dsdss', $postid, $title, $price, $discription, $email); $stmt->execute(); } $query = 'SELECT * FROM mammals WHERE postid = ?'; $stmt = $db->stmt_init(); if ($stmt->prepare($query)) { $stmt->bind_result('d', $postid); $stmt->execute(); $data = $stmt->fetch_assoc(); echo $data['postid']; } PHP:
If postid is an integer (as defined within your database), it's going to be saved as a 0 when you insert it. If it's a text field, you need to wrap the values within quotes (both for inserting and querying).
postid is a 10 digit time stamp number. Perhaps I should of called it something else. create table mammals05 ( postid int unsigned not null primary key, title char(50) not null, price int unsigned not null, discription char(20) not null, email char(50) not null );
Well... ? is not an integer... there is no way you can store an integer value of "?" in your database, nor can you query for an integer of "?", because there is no such thing. You might as well be asking the database server to give you a random NUMBER between h and e.
When I bind parameters the (?) is replaced with (d) which stands for Double (floating point number) and will represent $postid and $price. (s) stands for string, and will represent $title, $description and $email. I am new at this. Am I not understanding you correctly? The 10 digit postid number inputs into the database correctly. I removed auto-increment from the database table, maybe that's why. $stmt->bind_param('dsdss', $postid, $title, $price, $discription, $email);