Search the Community
Showing results for tags 'select'.
-
Hi everyone, I'm building my own shopping website. I haven't figured out how to populate two dropdown lists with available sizes and colors of a product_id from database. Here is the result I've got from querying database. id product_name style size color price image sku stock 1 Neck Top 104 S White $30.00 104.jpg 104-1 5 2 Neck Top 104 S Black $30.00 104.jpg 104-2 5 3 Neck Top 104 M Red $30.00 104.jpg 104-3 10 4 Neck Top 104 L Blue $30.00 104.jpg 104-4 10 5 Neck Top 104 XL Black $30.00 104.jpg 104-5 5 And here are my tables: tblProduct tblSizes tblColors tblSpecific_Products id id id id product_name size color product_id style size_id price color_id image stock category (tops,dresses,bottoms,...) subcategory (bodycon,work,evening,cocktail) Is there any way I can have it done without duplicating the values in each dropdown list? Also for each product_id, how can I store 3 different images (front view,back view and side view) for each color? Does it mean I have to create another attribute table for those images and store their names in database? I'm confused.
-
Never mind. I figured it out. The parameters are overwritten by the Select. Can you see what is wrong with this Select. I know the variables are set and I know there is no data, the $islocked and $addr are both blank. I only fetch address to see if I can get any data. I did this from phpmyadmin and it retrieved locked=1 function failed($dbc, $em, $ad, $TheTable) { $islock=0; $addr=""; $stmt = mysqli_prepare($dbc, 'SELECT locked, address FROM $TheTable WHERE (email=? OR address=?) LIMIT 1'); mysqli_stmt_bind_param($stmt, "ss", $em, $ad); mysqli_stmt_execute($stmt) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); mysqli_stmt_bind_result($stmt, $islocked, $addr); mysqli_stmt_fetch($stmt); if ($islocked > 0) { mysqli_stmt_close($stmt); return (true); } mysqli_stmt_close($stmt); return (false); } // End of function. And this is the table CREATE TABLE IF NOT EXISTS `B_Distributors` ( `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT COMMENT 'db increments', `email` varchar(80) COLLATE utf8_unicode_ci NOT NULL, `address` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL, `locked` tinyint(1) unsigned DEFAULT NULL COMMENT 'I forbid', `notes` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `orig_date` datetime DEFAULT NULL, `time_stamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=2 ; -- -- Dumping data for table `B_Distributors` -- INSERT INTO `B_Distributors` (`id`, `email`, `address`, `locked`, `notes`, `orig_date`, `time_stamp`) VALUES (1, 'bca@rr.com', '71st Street', 1, '', '2015-07-11 11:43:41', '2015-07-11 15:43:41');
-
I am building a website after reading this book, and I am having trouble with the selected="selected" part of a select menu. Nothing is getting selected. When I click on submit form it goes through but the item I selected isn't being selected in my database. In the following code, the problem lies in the following section: where the select menu is, but I can't get it to work. help would be appreciated. <?php $optionarray = array(3 => 'Children & Family', 4 => 'Home Business', 5 => 'Advertising', 6 => 'Affiliate Programs', 7 => 'Art & Photography', 9 => 'Beauty & Jewelry', 10 => 'Blogging', 11 => 'Books, Literature', 12 => 'Business & Finance', 13 => 'Computer Games', 14 => 'Computing', 15 => 'Dating & Relationships', 16 => 'Directories', 17 => 'Education', 18 => 'Electronics', 19 => 'Entertainment', 20 => 'Environment', 21 => 'Flowers', 22 => 'Food, Drink', 23 => 'Forums, chat rooms', 24 => 'Free Stuff', 25 => 'Gifts & Shopping', 26 => 'Health', 27 => 'Humor', 28 => 'Interior Design', 29 => 'Internet Marketing', 30 => 'Miscellaneous', 31 => 'Music', 32 => 'Pets', 33 => 'Real Estate', 34 => 'Religion & Spirituality', 35 => 'Science', 36 => 'Sports', 37 => 'Stocks & Trading', 38 => 'Travel', 39 => 'Vehicles', 40 => 'Web Design', 41 => 'Web Hosting', 42 => 'Work At Home', 43 => 'Psychology'); echo '<form action="edit_your_sites.php" method="post"><select name="SiteTypeID"><option value="">Select a Category</option>'; foreach ($optionarray as $key => $value){ echo '<option value="$key"'; if (isset($_POST['SiteTypeID']) && ($_POST['SiteTypeID'] == '. $key . ')) echo 'selected="selected">'; echo $value . '</option>'; } echo '</select>'; ?> <?php $page_title = 'Edit Your Account'; include ('includes/header.html'); include ('includes/functions.php'); include ('includes/config.inc.php'); if (isset($_GET['id']) && is_numeric($_GET['id'])){ $id = $_GET['id']; } elseif (isset($_POST['id']) && is_numeric($_POST['id'])) { $id = $_POST['id']; } else { echo '<p class="error">This page has been accessed in error.</p>'; include ('includes/footer.html'); exit(); } if (isset($_SESSION['UserID'])){ require (MYSQL); echo '<div class="text">'; $scrubbed = array_map('spam_scrubber', $_POST); if ($_SERVER['REQUEST_METHOD'] == 'POST'){ if (filter_var($scrubbed['url'], FILTER_VALIDATE_URL)){ $url = mysqli_real_escape_string($dbc, $scrubbed['url']); } else { $url = ""; echo '<p class="error">Please enter a valid url</p>'; } if (!empty($scrubbed['SiteTypeID'])){ $sitetypeid = $scrubbed['SiteTypeID']; } else { $sitetypeid =""; echo '<p class="error">Please select a category</p>'; } if($url && $sitetypeid){ $q = "SELECT UserID, url, SiteID FROM sites WHERE url='$url' AND SiteTypeID='$sitetypeid' AND SiteTypeID!=$id"; $query = mysqli_query ($dbc, $q); if (mysqli_num_rows($query) == 0){ $q = "UPDATE sites SET url='$url', SiteTypeID='$sitetypeid' WHERE SiteID=$id LIMIT 1"; $query = mysqli_query ($dbc, $q); if (mysqli_affected_rows($dbc) == 1){ echo '<p><b>Your url has been successfully edited</b></p>'; } elseif (mysqli_affected_rows($dbc) == 0){ echo '<p>No new details have been inserted</p>'; } else { echo '<p class="error">The user could not be edited due to a system error. We apologize for any inconvenience.</p>'; // Public message. echo '<p>' . mysqli_error($dbc) . '<br />Query: ' . $q . '</p>'; // Debugging message. } } else { echo '<p><b>That url has already been registered with that category, if you own this site you can change categories if you wish to. Please note that a website cannot be added multiple times in different categories.</b></p>'; } } } ?> <h1>Edit Your Sites</h1><p><b>Do not add duplicate urls, they will be deleted. We only accept family-safe urls. We play fair and expect our members to do the same.</b> </p> <?php $query2 = "SELECT s.SiteTypeID, u.UserID, s.SiteType FROM sitetypes AS s LEFT JOIN sites AS u USING (SiteTypeID) WHERE SiteID=$id"; $mx = mysqli_query($dbc, $query2); if (mysqli_num_rows($mx) ==1){ $row2 = mysqli_fetch_array($mx, MYSQLI_ASSOC); echo '<p>Your site\'s current category is <b>'.$row2['SiteType'] . '</b></p>'; } ?> <?php $optionarray = array(3 => 'Children & Family', 4 => 'Home Business', 5 => 'Advertising', 6 => 'Affiliate Programs', 7 => 'Art & Photography', 9 => 'Beauty & Jewelry', 10 => 'Blogging', 11 => 'Books, Literature', 12 => 'Business & Finance', 13 => 'Computer Games', 14 => 'Computing', 15 => 'Dating & Relationships', 16 => 'Directories', 17 => 'Education', 18 => 'Electronics', 19 => 'Entertainment', 20 => 'Environment', 21 => 'Flowers', 22 => 'Food, Drink', 23 => 'Forums, chat rooms', 24 => 'Free Stuff', 25 => 'Gifts & Shopping', 26 => 'Health', 27 => 'Humor', 28 => 'Interior Design', 29 => 'Internet Marketing', 30 => 'Miscellaneous', 31 => 'Music', 32 => 'Pets', 33 => 'Real Estate', 34 => 'Religion & Spirituality', 35 => 'Science', 36 => 'Sports', 37 => 'Stocks & Trading', 38 => 'Travel', 39 => 'Vehicles', 40 => 'Web Design', 41 => 'Web Hosting', 42 => 'Work At Home', 43 => 'Psychology'); echo '<form action="edit_your_sites.php" method="post"><select name="SiteTypeID"><option value="">Select a Category</option>'; foreach ($optionarray as $key => $value){ echo '<option value="$key"'; if (isset($_POST['SiteTypeID']) && ($_POST['SiteTypeID'] == '. $key . ')) echo 'selected="selected">'; echo $value . '</option>'; } echo '</select>'; ?> <?php $ms = "SELECT UserID, url, SiteID FROM sites WHERE SiteID=$id"; $msp = mysqli_query($dbc, $ms); if (mysqli_num_rows($msp) > 0){ $row = mysqli_fetch_array($msp, MYSQLI_ASSOC); echo '<p>Url:<input type="text" name="url" size="60" maxlength="80" value="' . $row['url'] .'" /><small>You can only add each url once into the database, each url must be unique.</small></p><p><input type="submit" name="submit" value="Edit Site Information!" /><input type="reset" name="reset" value="Clear Form" /> <input type="hidden" name="id" value="' . $id . '" /> </form><p><a href="delete_url.php?id=' . $row['SiteID'] . '"><b>Delete Url</b></a>'; } else { echo '<p class="error">A system error occurred, we apologize for the inconvenience.</p>'; } ?> <?php } else { $url = BASE_URL . 'index.php'; header("Location: $url"); } echo '</div>'; include ('includes/footer.html'); ?>