Jump to content

Need Help With mysqli Database Code Not Outputting Anything


nstruth

Recommended Posts

I'm trying to retrieve a name from a row based on an HTML id# input. I checked print_r and var_dump for the $_POST variable, and it exists. So I think something's wrong with my SQL code. Here it is:

$query = $con->prepare("SELECT name, email FROM crud WHERE id=?"); // prepate a query
$query->bind_param('s', $_POST['identification']); // binding parameters via a safer way than via direct insertion into the query. 'i' tells mysql that it should expect an integer.
$query->execute(); // actually perform the query
$result = $query->get_result(); // retrieve the result so it can be used inside PHP
$r = $result->fetch_array(MYSQLI_ASSOC); // bind the data from the first result row to $r
echo $r['name']; // will return the price

Please help

Link to comment
Share on other sites

I like how the comment says "i" but the code says "s".

So you dumped out the value of the ID from the form, and it says like string(3) "123", and then you looked in your "crud" table and found a row with id=123?

And your code is running successfully, making it to that echo statement, except it doesn't show a value there - and instead PHP actually gives you a one or more warning messages about $result and/or $r and/or the "name" key?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.