MsKazza Posted April 28, 2017 Share Posted April 28, 2017 (edited) Hi, i'm recently had to add a new value to our product database called supplier_id, which gets called from the supplier table. Now when i'm trying to add a new product, it looks up the supplier name, but i'm not sure where/how to add the supplier_id so that it gets past to the POST, if someone could help me would much appreciate it. Please see attached file. Thanks, MsKazza <?php include('header.php'); ?> <style> table { width: 600px; } th { height: 50px; } td { height: 30px; vertical-align: middle; } </style> </head> <body> <?php include('navbar.php'); if (isset($_POST['submit'])) { $product_code = $_POST['product_code']; $product_name = $_POST['product_name']; $supplier_id = $_POST['supplier_id']; $supplier = $_POST['supplier']; $category = $_POST['category']; $sub_category = $_POST['sub_category']; $category2 = $_POST['category2']; $sub_category2 = $_POST['sub_category2']; $sql = "SELECT * FROM sub_categories WHERE id = '$sub_category'"; $subcat_result = $con->query($sql); while ($row=mysqli_fetch_array($subcat_result)) { $subcat_name = $row['subcat_name']; } $sub_category1 = preg_replace('/[^a-zA-Z0-9_.]/', '-', $subcat_name); $product_name1 = preg_replace('/[^a-zA-Z0-9_.]/', '-', $product_name); $slug = $sub_category1 . "/" . $product_name1; $slug = strtolower($slug); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // Perform queries mysqli_query($con,"INSERT INTO products (product_code, slug, supplier_id, supplier, category, sub_category, category2, sub_category2,product_name) VALUES ('$product_code', '$slug', '$supplier_id', '$supplier', '$category', '$sub_category', '$category2', '$sub_category2', '$product_name')"); // Perform queries mysqli_query($con,"INSERT INTO images (product_code) VALUES ('$product_code')"); ?> <script> location.replace("products.php"); </script> <? mysqli_close($con); } else { ?> <script language="javascript" type="text/javascript"> function getXMLHTTP() { //fuction to return the xml http object var xmlhttp=false; try{ xmlhttp=new XMLHttpRequest(); } catch(e) { try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e1){ xmlhttp=false; } } } return xmlhttp; } function getSubcat(categoryId) { var strURL="findsubcat.php?category="+categoryId; var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('subcatdiv').innerHTML=req.responseText; } else { alert("Problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } </script> <form method="post" action="" name="addproduct"> <?php $sql = "SELECT * FROM categories ORDER BY cat_name ASC"; $result = $con->query($sql); ?> <div class="container-fluid text-center"> <div class="row content"> <div class="col-sm-12 text-left"> <br /> <h1>Add New Product</h1> <br /> <table> <tr><td>Product Code : </td><td><input type="text" name="product_code" ></td></tr> <tr><td>Product Name : </td><td><input type="text" name="product_name" size="50px"></td></tr> <tr><td><div class="form-group"> <label for="name">Supplier</label><a href="#" style="font-size:12px"> (Edit)</a></td> <td><label class="input-group p-custom-arrow"> <select id="supplier" name="supplier" value="<?php echo $product['supplier']; ?>" class="form-control"> <option class="p-select-default" value="">Select Supplier</option> <?php $sql=mysqli_query($con,"select * from supplier ORDER BY supplier_name ASC"); while($row=mysqli_fetch_array($sql)) { ?> <option value="<?php echo $row['folder']; ?>" <?php if ($product['supplier'] == $row['folder']) echo ' selected="selected"' ?>><?php echo $row['supplier_name']; ?></option> <?php } ?> </select> </label> </div><br /></td></tr><!-- End: form group --> <tr><td style="width:150px;"> Category : </span></td><td><select name="category" onChange="getSubcat(this.value)"> <option value="">Select Category</option> <?php while ($row=mysqli_fetch_array($result)) { ?> <option value=<?php echo $row['id']?>><?php echo $row['cat_name']?></option> <?php } ?> </select> </td></tr> <tr><td style="width:150px;">Sub Category : </span></td><td><div id="subcatdiv"><select name="sub_category" > <option>Select Subcategory</option> </select></div><br /> </td></tr> </table><br /> <input type="submit" value="submit" name="submit"> </form> </div> </div> </div> </div> <?php } ?> <?php include('footer.php'); ?> </body> </html> addproduct.php Edited April 28, 2017 by requinix next time please put the code into your post with [code] tags Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 28, 2017 Share Posted April 28, 2017 (edited) Sorry but your explanation of your problem makes no sense to me nor does the jumbled up mess of php/html/js/css all piled together. The first thing you should do is learn how to organize your code and then your thoughts and maybe you can solve this problem. PS Does this make sense to you? if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "My email"; $email_subject = "Inquiry from site"; // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['email'])) if 'email' is set how could it ever be not set? Edited April 28, 2017 by ginerjm 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.