jsanchez1 Posted March 12, 2008 Share Posted March 12, 2008 I am trying to create a simple content management page to facilitate adding a product into a database to be retrieved later. I am failing on the INSERT command and I cannot figure out why. Can anyone help? Here is the form: <table align="center" border="1"> <tr> <td align="center"><h1>Add Product</h1></td> </tr> <tr> <td> <table cellpadding="2" width="600"> <form method="post" action="add_product_function.php"> <tr> <td align="right">Product Name</td> <td><input type="text" name="product_name" size="40"> </td> </tr> <tr> <td align="right">Product Number</td> <td><input type="text" name="product_number" size="20"> </td> </tr> <tr> <td align="right">Product Description</td> <td><textarea rows="5" cols="30" name="product_description"></textarea> </td> </tr> <tr> <td align="right">Product Image Path</td> <td><input type="text" name="product_image" size="40"> </td> </tr> <tr> <td align="right">Serving Size Quantity</td> <td><input type="text" name="serving_size_quantity" size="20"> </td> </tr> <tr> <td align="right">Serving Size Unit</td> <td><select type="text" name="serving_size_unit"> <option value="pc." selected="selected">pc</option> <option value="oz.">oz</option> </select> </td> </tr> <tr> <td align="right">Count Per Case</td> <td><input type="text" name="count_per_case" size="20"> </td> </tr> <tr> <td align="right">UPC</td> <td><input type="text" name="upc" size="20"> </td> </tr> <tr> <td align="right">Net Wt. Quantity</td> <td><input type="text" name="net_wt_quantity" size="20"> </td> </tr> <tr> <td align="right">Net Wt. Unit</td> <td><select type="text" name="net_wt_unit"> <option value="oz." selected="selected">oz</option> <option value="lbs.">lbs</option> </select> </td> </tr> <tr> <td align="right">Gross Ship Wt.</td> <td><input type="text" name="gross_ship_wt" size="20"> </td> </tr> <tr> <td align="right">Gross Ship Wt. Unit</td> <td><select type="text" name="gross_ship_wt_unit"> <option value="lbs." selected="selected">lbs</option> <option value="oz.">oz</option> </select> </td> </tr> <tr> <td align="right">Height</td> <td><input type="text" name="height" size="9"> </td> </tr> <tr> <td align="right">Weight</td> <td><input type="text" name="weight" size="9"> </td> </tr> <tr> <td align="right">Depth</td> <td><input type="text" name="depth" size="9"> </td> </tr> <tr> <td align="right">HxWxD Unit</td> <td><select type="text" name="hwd_unit"> <option value="in." selected="selected">in</option> <option value="ft.">ft</option> </select> </td> </tr> <tr> <td align="right">Case Cube</td> <td><input type="text" name="case_cube" size="20"> </td> </tr> <tr> <td align="right">Case Cube Unit</td> <td><select type="text" name="case_cube_unit"> <option value="ft." selected="selected">ft</option> </select> </td> </tr> <tr> <td align="right">Hi Ti First</td> <td><input type="text" name="hi_ti_first" size="4"> </td> </tr> <tr> <td align="right">Hi Ti Second</td> <td><input type="text" name="hi_ti_second" size="4"> </td> </tr> <tr> <td align="right">Cu Ft.</td> <td><input type="text" name="cu_ft" size="9"> </td> </tr> <tr> <td align="right">Instruction Type</td> <td><select type="text" name="instruction_type"> <option value="Thaw and Serve" selected="selected">Thaw and Serve</option> <option value="Shelf Stable">Shelf Stable</option> </select> </td> </tr> <tr> <td align="right">Instruction</td> <td><textarea rows="5" cols="30" name="instruction"></textarea> </td> </tr> <tr> <td></td> <td align="right"><input type="submit" name="submit" value="Add Product"></td> </tr> </table> </td> </tr> </table> and here is the php function: <? include 'config/configdb.php'; include 'config/opendb.php'; $product_name = $_POST['product_name']; $product_number = $_POST['product_number']; $product_description = $_POST['product_description']; $product_image = $_POST['product_image']; $serving_size_quantity = $_POST['serving_size_quantity']; $serving_size_unit = $_POST['serving_size_unit']; $count_per_case = $_POST['count_per_case']; $upc = $_POST['upc']; $net_wt_quantity = $_POST['net_wt_quantity']; $net_wt_unit = $_POST['net_wt_unit']; $gross_ship_wt = $_POST['gross_ship_wt']; $gross_ship_wt_unit = $_POST['gross_ship_wt_unit']; $height = $_POST['height']; $weight = $_POST['weight']; $depth = $_POST['depth']; $hwd_unit = $_POST['hwd_unit']; $case_cube = $_POST['case_cube']; $case_cube_unit = $_POST['case_cube_unit']; $hi_ti_first = $_POST['hi_ti_first']; $hi_ti_second = $_POST['hi_ti_second']; $cu_ft = $_POST['cu_ft']; $instruction_type = $_POST['instruction_type']; $instruction = $_POST['instruction']; //inserting data order $order = "INSERT INTO product (product_name, product_number, product_description, product_image, serving_size_quantity, serving_size_unit, count_per_case, upc, net_wt_quantity, net_wt_unit, gross_ship_wt, gross_ship_wt_unit, height, weight, depth, hwd_unit, case_cube, case_cube_unit, hi_ti_first, hi_ti_second, cu_ft, instruction_type, instruction) VALUES ('$product_name','$product_number','$product_description','$product_image','$serving_size_quantity','$serving_size_unit','$count_per_case','$upc','$net_wt_quantity','$net_wt_unit','$gross_ship_wt','$gross_ship_wt_unit','$height','$weight','$depth','$hwd_unit','$case_cube','$case_cube_unit','$hi_ti_first','$hi_ti_second','$cu_ft','$instruction_type','$instruction')"; //declare in the order variable $result = mysql_query($order); //order executes if($result){ echo("<br />Product Added<br /><br /><a href=\"add_product_form.php\">Add Another Product</a>"); } else{ echo("<br />Input Failed<br /><br /><a href=\"add_product_form.php\">Add Another Product</a>"); } ?> PHP version 5.25 & MySQL version 5.0.45-community-log. Thanks for taking the time to look. Jason Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 12, 2008 Share Posted March 12, 2008 suggestion, add or die: $result = mysql_query($order) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
jsanchez1 Posted March 12, 2008 Author Share Posted March 12, 2008 Thanks BlueSkyIS!!!! That gave me an error message pointing out that the field "weight" was not found in the database. It should have been 'width", and now it works! Thanks for all the help, Jason 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.