sykorazza Posted January 1, 2016 Share Posted January 1, 2016 So I wanted to make an automatic table displaying all the products from the database, where you can click on its name and view the whole information of the product. The problem is that it wouldn't load the product's information. Error 1: Warning: Wrong parameter count for mysqli_stmt_bind_result() in C:\wamp\www\goldenrod\index.php on line 59 Error 2: Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, object given in C:\wamp\www\goldenrod\index.php on line 61 Connection to the database: <?php //Database Connections $conn = mysqli_connect('localhost', 'root', '', 'lionsierra_db') or die("Cannot find specified server"); //Product Database $db_products = "SELECT * FROM `products`"; $products = mysqli_query($conn, $db_products); ?> Here is the function: //View product if(isset($_GET['view_product'])) { //now let's build out our query $view_product_statement = mysqli_prepare($conn, "SELECT * FROM `products` WHERE `ID` = ?"); mysqli_stmt_bind_param($view_product_statement, 'i', $_GET['view_product']); mysqli_stmt_execute($view_product_statement); mysqli_stmt_bind_result($view_product_statement); while($product=mysqli_fetch_assoc($view_product_statement)){ //Display a product echo "<p><span> <span style='font-weight:bold;'>" . $product['name'] . "</span><br/> <span>$" . $product['price'] . "</span><br/> <span>" . $product['category'] . "</span><br/> <span>" . $product['description'] . "</span> </p>"; } mysqli_stmt_close($view_product_statement); }else{ //View all products echo '<table width="600" border="1" cellpadding="1" cellspacing="1"> <tr> <th>Name</th> <th>Price</th> <th>Category</th> </tr>'; while($product=mysqli_fetch_assoc($products)) { echo "<tr> <td><a href='./index.php?view_product=" . $product['ID'] . "'>". $product['name'] . "</a></td> <td>" . $product['price'] . "</td> <td>" . $product['category'] . "</td> </tr>"; $ID = $product['ID']; } } Kudos! Quote Link to comment https://forums.phpfreaks.com/topic/300091-troubles-with-showing-a-product-with-sql/ Share on other sites More sharing options...
ginerjm Posted January 1, 2016 Share Posted January 1, 2016 1 - error 1 tells you something very specific. Have you read the manual to see how the bind_result has to be built? Fix the number of args in your call - that is what it is telling you. 2 - If you had PROPERLY done error checking on your bind call, or on your query call you wouldn't have reached the fetch call which won't work since the query probably failed because of error #1 Quote Link to comment https://forums.phpfreaks.com/topic/300091-troubles-with-showing-a-product-with-sql/#findComment-1528957 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.