amin1982 Posted March 9, 2007 Share Posted March 9, 2007 Hey Guys, Hope someone can help. I an trying to create a drop down menu that is created using data from MySQL and using PHP to select the datat. I want to select the ID and the name only of the product brand and show it in the dropdown menu in alphabetical order. But i keep receiving these errors: 1. mysqli_query() expects parameter 1 to be mysqli, resource given 2. mysqli_close() expects parameter 1 to be mysqli, resource given 3. mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given with my code being: <select name="brand" id="brand"> <option>Select One</option> <?php // Retrieve all the brands and add to the pull-down menu. $query = "SELECT id, CONCAT_WS(' ', brandname) AS name FROM brands ORDER BY brandname ASC"; $result = mysqli_query ($dbc, $query); //error 1 is here! while ($row = mysqli_fetch_array ($result, MYSQLI_ASSOC)) { // error 3 here echo "<option value="{$row['id']}">{$row['name']}</option>n"; } mysqli_close($dbc); //error 2 here ?> </select> anyone know how i can ammmend this? Thanks Link to comment https://forums.phpfreaks.com/topic/41899-mysqli_query-mysqli_closemysqli_fetch_array-errors/ Share on other sites More sharing options...
trq Posted March 9, 2007 Share Posted March 9, 2007 Where do you define $dbc? Looks like you've not made a connection, all the other errors are generated from this one initial error. Link to comment https://forums.phpfreaks.com/topic/41899-mysqli_query-mysqli_closemysqli_fetch_array-errors/#findComment-203147 Share on other sites More sharing options...
amin1982 Posted March 9, 2007 Author Share Posted March 9, 2007 hey, the connect is made earlier in the code throgh an include file. the connection seems to be fine as other queries work. It's just this part of the code that I'm having trouble with. if it helps the fill code is: The errors are towards the bottom <?php require_once ('../includes/buffer.php'); ?> <!-- Style Sheet --> <link rel="stylesheet" type="text/css" href="../css/main_style.css"/> <!-- End Style Sheet --> <title>Administer | Add Hat</title> <br> <table width="900" border="0" align="center" cellpadding="2" cellspacing="2" class="ClaretTable"> <tr> <td colspan="3" rowspan="4"><img src="../images/logo.gif" width="450" height="107"></td> <td colspan="3"> </td> </tr> <tr> <td colspan="3"> <div align="right"> <?php // This is the logout page for the site. // Include the configuration file for error management and such. require_once ('.././includes/config.inc.php'); require_once ('../includes/mysql_connect.php'); // If no admin_name variable exists, redirect the user. // What this does is redirect the user to the login page if they are NOT LOGGED in. The prevents a random user // typing in the address of the page in their browser. i.e http://www.spinmydesign.com/ljum/administer/index.php // if they do they are redirected to the login.php if (!isset($_SESSION['admin_name'])) { // Start defining the URL. $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } // Add the page. $url .= '/login.php'; ob_end_clean(); // Delete the buffer. header("Location: $url"); exit(); // Quit the script. } else { // welcome the user. echo '<div class="WhiteText">you are logged in as:'; if (isset($_SESSION['admin_name'])) { echo " {$_SESSION['admin_name']}"; } echo '</div>'; } ?> </div></td> </tr> <tr> <td colspan="3"><div align="right"><a href="logout.php" class="WhiteText">Logout</a></div></td> </tr> <tr> <td height="23" colspan="3"> </td> </tr> <tr class="WhiteTextLarge"> <td height="24" colspan="6" class="WhiteText"><div align="center"><a href="index.php" class="WhiteTextLarge">Admin Home </a> | <a href="malehats.php" class="WhiteTextLarge">Male Hats</a> | <a href="femalehats.php" class="WhiteTextLarge">Female Hats </a>| <a href="suppliers.php" class="WhiteTextLarge">Suppliers</a> | <a href="viewbrands.php" class="WhiteTextLarge">Brands</a> | <a href="adminoptions.php" class="WhiteTextLarge">Admin Options</a> | <a href="vieworders.php" class="WhiteTextLarge">Orders </a></div></td> </tr> <tr class="WhiteTextLarge"> <td width="230" height="24" class="WhiteText"> </td> <td width="202" class="WhiteText"> </td> <td width="50" height="24" class="WhiteText"> </td> <td width="319"> </td> <td width="32"> </td> <td width="29"> </td> </tr> <tr class="WhiteTextLarge"> <td colspan="6" class="WhiteText"> <form enctype="multipart/form-data" action="addmalehat.php" method="post"> <table width="900%" border="0" cellspacing="2" cellpadding="2"> <tr class="WhiteTextLarge"> <td width="17%"><div align="left"></div></td> <td width="18%"><div align="left">>> Add New Male Hat </div></td> <td width="17%"><div align="left"></div></td> <td width="16%"><div align="left"></div></td> <td width="16%"><div align="left"></div></td> <td width="16%"><div align="left"></div></td> </tr> <tr class="WhiteTextLarge"> <td class="WhiteText"> </td> <td colspan="3"> <?php if (isset($_POST['submitted'])) { // Check if the form has been submitted. // Validate the hat details. // Check for a hat name. if (!empty($_POST['name'])) { $n = escape_data($_POST['name']); } else { $n = FALSE; echo '<p><font color="black">Please enter the products name</font></p>'; } // Check for a hat description if (!empty($_POST['description'])) { $d = escape_data($_POST['description']); } else { $d= FALSE; echo '<p><font color="black">Please enter the products description</font></p>'; } // Check for a hat cost if (!empty($_POST['cost'])) { $d = escape_data($_POST['cost']); } else { $d= FALSE; echo '<p><font color="black">Please enter the products cost</font></p>'; } // Check for an image. if (is_uploaded_file ($_FILES['image']['tmp_name'])) { if (move_uploaded_file($_FILES['image']['tmp_name'], "../../databaseimages/{$_FILES['image']['name']}")) { // Move the file over. echo '<p>The file has been uploaded!</p>'; } else { // Couldn't move the file over. echo '<p><font color="black">The file could not be moved.</font></p>'; $i = FALSE; } $i = $_FILES['image']['name']; } else { $i = FALSE; } // Check for a hat description if (!empty($_POST['description'])) { $d = escape_data($_POST['description']); } else { $d= FALSE; echo '<p><font color="black">Please enter the products description</font></p>'; } // Check for a price. if (is_numeric($_POST['price'])) { $p = (float) $_POST['price']; } else { $p = FALSE; echo '<p><font color="red">Please enter the print\'s price!</font></p>'; } // Check for a description (not required). if (!empty($_POST['description'])) { $d = escape_data($_POST['description']); } else { $d = '<i>No description available.</i>'; } // Validate the artist. if ($_POST['artist'] == 'new') { // If it's a new artist, add the artist to the database. $query = 'INSERT INTO artists (first_name, middle_name, last_name) VALUES ('; if (!empty($_POST['first_name'])) { $query .= "'" . escape_data($_POST['first_name']) . "', "; } else { $query .= 'NULL, '; } if (!empty($_POST['middle_name'])) { $query .= "'" . escape_data($_POST['middle_name']) . "', "; } else { $query .= 'NULL, '; } // Check for a last_name. if (!empty($_POST['last_name'])) { $query .= "'" . escape_data($_POST['last_name']) . "')"; // Improved MySQL Version: $result = mysqli_query($dbc, $query); $a = mysqli_insert_id($dbc); /* Standard MySQL Version: $result = mysql_query ($query); // Run the query. $a = mysql_insert_id(); // Get the artist ID. */ } else { // No last name value. $a = FALSE; echo '<p><font color="red">Please enter the artist\'s name!</font></p>'; } } elseif ( ($_POST['artist'] == 'existing') && ($_POST['existing'] > 0)) { // Existing artist. $a = (int) $_POST['existing']; } else { // No artist selected. $a = FALSE; echo '<p><font color="red">Please enter or select the print\'s artist!</font></p>'; } if ($pn && $p && $a && $i) { // If everything's OK. // Add the print to the database. $query = "INSERT INTO prints (artist_id, print_name, price, size, description, image_name) VALUES ($a, '$pn', $p, '$s', '$d', '$i')"; if ($result = mysqli_query ($dbc, $query)) { // Worked. echo '<p>The print has been added.</p>'; } else { // If the query did not run OK. echo '<p><font color="red">Your submission could not be processed due to a system error.</font></p>'; } } else { // Failed a test. echo '<p><font color="red">Please click "back" and try again.</font></p>'; } } // Display the form. ?> </td> <td colspan="2" class="WhiteText"> </td> </tr> <tr class="WhiteTextLarge"> <td class="WhiteText"> </td> <td><div align="left">Name: </div></td> <td><div align="left"> <input name="name" type="text" class="Fields" id="name" maxlength="100"> </div></td> <td><div align="left"></div></td> <td colspan="2" class="WhiteText"><div align="left"></div> <div align="left">Add the product name here, maximum 100 characters.</div></td> </tr> <tr class="WhiteTextLarge"> <td class="WhiteText"> </td> <td>Description:</td> <td><textarea name="decription" rows="6" class="Fields" id="decription"></textarea></td> <td> </td> <td colspan="2" class="WhiteText">Add a few lines to describe the product (max 255 characters). </td> </tr> <tr class="WhiteTextLarge"> <td class="WhiteText"> </td> <td>Cost:</td> <td><input name="cost" type="text" class="Fields" id="cost"></td> <td> </td> <td colspan="2" class="WhiteText">Add the cost of the product. Should be in the follwoing format 13.95 or 9.95.</td> </tr> <tr class="WhiteTextLarge"> <td class="WhiteText"> </td> <td>Image:</td> <td colspan="2"><input name="image" type="file" class="Fields" /></td> <td colspan="2" class="WhiteText">Add image of product (max 125px X 125px)</td> </tr> <tr class="WhiteTextLarge"> <td class="WhiteText"> </td> <td>Brand:</td> <td><select name="brand" id="brand"> <option>Select One</option> <?php // Retrieve all the brands and add to the pull-down menu. $query = "SELECT * FROM brands ORDER BY name ASC"; $result = mysqli_query ($dbc, $query); //error 1 is here! while ($row = mysqli_fetch_array ($result, MYSQLI_ASSOC)) { //error 3 is here! echo "<option value=\"{$row['id']}\">{$row['brands']}</option>\n"; } mysqli_close($dbc); //error 2 here ?> </select></td> <td> </td> <td colspan="2" class="WhiteText">Please select the brand of the hat. If its a new brand please <a href="addnewbrand.php" class="WhiteText"><strong>CLICK HERE</strong></a> to add a new brand.</td> </tr> <tr class="WhiteTextLarge"> <td class="WhiteText"> </td> <td>Supplier:</td> <td> <select name="supplier" id="supplier"> <option>Select One</option> <?php // Retrieve all the artists and add to the pull-down menu. $query = "SELECT id, CONCAT_WS(' ', suppliername) AS name FROM suppliers ORDER BY suppliername ASC"; $result = mysqli_query ($dbc, $query);//error 1 here while ($row = mysqli_fetch_array ($result, MYSQLI_ASSOC)) {//error 3 here echo "<option value=\"{$row['id']}\">{$row['name']}</option>\n"; } mysqli_close($dbc); //error 2 here ?> </select> </td> <td> </td> <td colspan="2" class="WhiteText">Please select the supplier of the hat. If its a new supplier please <a href="addnewsupplier.php" class="WhiteText"><strong>CLICK HERE</strong></a> to add a new brand.</td> </tr> <tr class="WhiteTextLarge"> <td class="WhiteText"> </td> <td>Quantity:</td> <td><input name="cost" type="text" class="Fields" id="cost"></td> <td> </td> <td colspan="2" class="WhiteText">How many of the hats are available?</td> </tr> <tr class="WhiteTextLarge"> <td class="WhiteText"> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr class="WhiteTextLarge"> <td class="WhiteText"><div align="left"></div></td> <td><div align="left"></div></td> <td> <input name="submit" type="submit" class="Fields" value="Submit" /> <input type="hidden" name="submitted" value="TRUE" /></td> <td><div align="left"></div></td> <td><div align="left"></div></td> <td><div align="left"></div></td> </tr> </table> </form></td> </tr> <tr class="WhiteTextLarge"> <td height="24" class="WhiteText"><div align="center"> </div> <div align="left" class="WhiteTextLarge"></div></td> <td class="WhiteText"> </td> <td height="24" class="WhiteText"> </td> <td> </td> <td> </td> <td> </td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/41899-mysqli_query-mysqli_closemysqli_fetch_array-errors/#findComment-203177 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.