nstruth Posted September 8, 2023 Share Posted September 8, 2023 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 Quote Link to comment Share on other sites More sharing options...
requinix Posted September 8, 2023 Share Posted September 8, 2023 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? Quote Link to comment Share on other sites More sharing options...
nstruth Posted September 8, 2023 Author Share Posted September 8, 2023 I'm a noob. I was querying empty rows. The code works. Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.