jacko_162 Posted March 8, 2008 Share Posted March 8, 2008 i have managed (not sure how!!??) to code most of a cms system for personal use... i have a small problem but not entirely sure on how to repair this.. when i add a product to my data base i select a manufacturer; if my manufacturer name is one word then everything is ok, for example: Fish - no problem. but if i add a product and select the manufacturer "soft corals" from a pull down menu (data selected from manufacturers table) and click save it views the manufacturer as "soft corals". when i select the edit.php page and click save but dont change the manufacturer, it renames the "soft corals" to "soft" and i have no idea why??? it onle seems to do this when the manufacturer is 2 words long??? What code do i need to post up?? add.php or edit.php??? Link to comment https://forums.phpfreaks.com/topic/95080-database-edit/ Share on other sites More sharing options...
BlueSkyIS Posted March 8, 2008 Share Posted March 8, 2008 edit.php, please. Link to comment https://forums.phpfreaks.com/topic/95080-database-edit/#findComment-487036 Share on other sites More sharing options...
jacko_162 Posted March 8, 2008 Author Share Posted March 8, 2008 apologies for the messy html etc.. but wasnt aware of this problem before i added all the html and tables etc... <title>Edit A Product</title> <script src="nicEdit.js" type="text/javascript"></script> <script type="text/javascript"> bkLib.onDomLoaded(nicEditors.allTextAreas); </script> <? include("includes/header.php") ?> <table width="100%" border="0" cellspacing="0" cellpadding="5" align="center" bgcolor="FFFFFF" bordercolor="#999999"> <tr> <td> <?php if (isset($submit)) { $name = $_POST['name']; $make = $_POST['make']; $catagory = $_POST['catagory']; $price = $_POST['price']; $description = $_POST['description']; $sold = $_POST['sold']; $colour = $_POST['colour']; $cotw = $_POST['cotw']; $sql = "UPDATE products SET name='$name', make='$make', catagory='$catagory', price='$price', description='$description', sold='$sold', colour='$colour', cotw='$cotw' WHERE ID='$ID'"; $query = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error()); $upload_dir = "../images/products/"; $insert_id = $ID; if (!empty($imageOne)) { // we have an image in image one check we have a valid type (jpeg only ?) if ($_FILES['imageOne']['type'] != "image/jpeg" && $_FILES['imageOne']['type'] != "image/pjpeg") { die("Image type is not allowed for Image One. Type found : " . $_FILES['imageOne']['type']); } else { // valid image make up a new filename $new_image_name = $insert_id . "one.jpg"; if (!copy($_FILES['imageOne']['tmp_name'], $upload_dir . $new_image_name)) { // file uploaded add to table row die("Unable to upload Image One"); } } } if (!empty($imageTwo)) { // we have an image in image one check we have a valid type (jpeg only ?) if ($_FILES['imageTwo']['type'] != "image/jpeg" && $_FILES['imageTwo']['type'] != "image/pjpeg") { die("Image type is not allowed for Image Two. Type found : " . $_FILES['imageTwo']['type']); } else { // valid image make up a new filename $new_image_name = $insert_id . "two.jpg"; if (!copy($_FILES['imageTwo']['tmp_name'], $upload_dir . $new_image_name)) { die("Unable to upload Image Two"); } } } if (!empty($imageThree)) { // we have an image in image one check we have a valid type (jpeg only ?) if ($_FILES['imageThree']['type'] != "image/jpeg" && $_FILES['imageThree']['type'] != "image/pjpeg") { die("Image type is not allowed for Image Three. Type found : " . $_FILES['imageThree']['type']); } else { // valid image make up a new filename $new_image_name = $insert_id . "three.jpg"; if (!copy($_FILES['imageThree']['tmp_name'], $upload_dir . $new_image_name)) { die("Unable to upload Image Three"); } } } if (!empty($imageFour)) { // we have an image in image one check we have a valid type (jpeg only ?) if ($_FILES['imageFour']['type'] != "image/jpeg" && $_FILES['imageFour']['type'] != "image/pjpeg") { die("Image type is not allowed for Image Four. Type found : " . $_FILES['imageFour']['type']); } else { // valid image make up a new filename $new_image_name = $insert_id . "four.jpg"; if (!copy($_FILES['imageFour']['tmp_name'], $upload_dir . $new_image_name)) { die("Unable to upload Image Four"); } } } if (!empty($imageFive)) { // we have an image in image one check we have a valid type (jpeg only ?) if ($_FILES['imageFive']['type'] != "image/jpeg" && $_FILES['imageFive']['type'] != "image/pjpeg") { die("Image type is not allowed for Image Five. Type found : " . $_FILES['imageFive']['type']); } else { // valid image make up a new filename $new_image_name = $insert_id . "five.jpg"; if (!copy($_FILES['imageFive']['tmp_name'], $upload_dir . $new_image_name)) { die("Unable to upload Image Five"); } } } if (!empty($imageSix)) { // we have an image in image one check we have a valid type (jpeg only ?) if ($_FILES['imageSix']['type'] != "image/jpeg" && $_FILES['imageSix']['type'] != "image/pjpeg") { die("Image type is not allowed for Image Six. Type found : " . $_FILES['imageSix']['type']); } else { // valid image make up a new filename $new_image_name = $insert_id . "six.jpg"; if (!copy($_FILES['imageSix']['tmp_name'], $upload_dir . $new_image_name)) { die("Unable to upload Image Six"); } } } if (!empty($imageThumb)) { // we have an image in image one check we have a valid type (jpeg only ?) if ($_FILES['imageThumb']['type'] != "image/jpeg" && $_FILES['imageThumb']['type'] != "image/pjpeg") { die("Image type is not allowed for Image Thumb. Type found : " . $_FILES['imageThumb']['type']); } else { // valid image make up a new filename $new_image_name = $insert_id . "thumb.jpg"; if (!copy($_FILES['imageThumb']['tmp_name'], $upload_dir . $new_image_name)) { die("Unable to upload Image Thumb"); } } } // check if we need to delete any images if ($imageOneDelete == "yes") { // delete image one unlink($upload_dir . $insert_id . "one.jpg"); } if ($imageTwoDelete == "yes") { // delete image two unlink($upload_dir . $insert_id . "two.jpg"); } if ($imageThreeDelete == "yes") { // delete image three unlink($upload_dir . $insert_id . "three.jpg"); } if ($imageFourDelete == "yes") { // delete image three unlink($upload_dir . $insert_id . "four.jpg"); } if ($imageFiveDelete == "yes") { // delete image three unlink($upload_dir . $insert_id . "five.jpg"); } if ($imageSixDelete == "yes") { // delete image three unlink($upload_dir . $insert_id . "six.jpg"); } if ($imageThumbDelete == "yes") { // delete image three unlink($upload_dir . $insert_id . "thumb.jpg"); } echo "<BR><table width=700 border=0 align=center cellpadding=0 cellspacing=0> <tr class=table3> <td><table width=100% border=0 cellspacing=1 cellpadding=3 align=center> <tr class=table1 align=center> <td><b>Database Updated.</b></td> </tr> </table> </td> </tr> </table>"; } else { $sql = "SELECT * FROM $table1 WHERE ID='$ID'"; $query = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error()); $result = mysql_fetch_array($query); $catagory = stripslashes($result["catagory"]); $make = stripslashes($result["make"]); $name = stripslashes($result["name"]); $price = stripslashes($result["price"]); $description = stripslashes($result["description"]); $colour = stripslashes($result["colour"]); $sold = stripslashes($result["sold"]); $cotw = stripslashes($result["cotw"]); // check what images exist $images_dir = "../images/products/"; // check for image one if (file_exists($images_dir . $ID . "one.jpg")) { $imageOneExists = 1; } // check for image two if (file_exists($images_dir . $ID . "two.jpg")) { $imageTwoExists = 1; } // check for image three if (file_exists($images_dir . $ID . "three.jpg")) { $imageThreeExists = 1; } // check for image three if (file_exists($images_dir . $ID . "four.jpg")) { $imageFourExists = 1; } // check for image three if (file_exists($images_dir . $ID . "five.jpg")) { $imageFiveExists = 1; } // check for image three if (file_exists($images_dir . $ID . "six.jpg")) { $imageSixExists = 1; } // check for image three if (file_exists($images_dir . $ID . "thumb.jpg")) { $imageThumbExists = 1; } ?> <FORM name=myform method=post action="<? echo $PHP_SELF ?>" enctype="multipart/form-data"> <table wIDth="100%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr class=table3> <td><table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" background="images/subbar_bg.gif"> <tr background="images/subbar_bg.gif"> <td width="4" height="52"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b><font size="1"><b><font size="2" face="Verdana, Arial, Helvetica, sans-serif" color="#3399FF"><img src="images/subbar_left.gif" width="4" height="52" /></font></b></font></b></font></td> <td height="52" align="left" valign="middle" background="images/subbar_bg.gif"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="20%"><img src="images/icons/add_product_logo.gif" width="173" height="39" /></td> <td width="80%"><div align="right"><a href="add.php" target="_self"><img src="images/icons/add.gif" alt="Add a product" width="38" height="38" border="0" /></a><a href="help.php" target="_self"><img src="images/icons/help.gif" width="38" height="38" border="0" /></a></div></td> </tr> </table></td> <td width="4" height="52"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b><font size="1"><b><font size="2" face="Verdana, Arial, Helvetica, sans-serif" color="#3399FF"><img src="images/subbar_right.gif" alt="" /></font></b></font></b></font></td> </tr> </table> <br> <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1"> <tr align="left" valign="top"> <td width="20%"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="4" height="4" bgcolor="#f2f3f5"><img src="images/top_left_corner.gif" width="4" height="4" /></td> <td height="4" background="images/top_menu.gif" bgcolor="#f2f3f5"><img src="images/top_menu.gif" width="1" height="4" /></td> <td width="4" height="4" bgcolor="#f2f3f5"><img src="images/top_right_corner.gif" width="4" height="4" /></td> </tr> <tr> <td width="4" background="images/left_menu.gif" bgcolor="#f2f3f5"><img src="images/left_menu.gif" width="4" height="1" /></td> <td bgcolor="#f2f3f5"><? include("includes/menu.php") ?></td> <td width="4" background="images/right_menu.gif" bgcolor="#f2f3f5"><img src="images/right_menu.gif" width="4" height="1" /></td> </tr> <tr> <td width="4" height="4" bgcolor="#f2f3f5"><img src="images/bottom_left_corner.gif" width="4" height="4" /></td> <td height="4" background="images/bottom_menu.gif" bgcolor="#f2f3f5"><img src="images/bottom_menu.gif" width="1" height="4" /></td> <td width="4" height="4" bgcolor="#f2f3f5"><img src="images/bottom_right_corner.gif" width="4" height="4" /></td> </tr> </table></td> <td width="80%"><table width="75%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="4" height="4" bgcolor="#f2f3f5"><img src="images/top_left_corner.gif" width="4" height="4" /></td> <td height="4" background="images/top_menu.gif" bgcolor="#f2f3f5"><img src="images/top_menu.gif" width="1" height="4" /></td> <td width="4" height="4" bgcolor="#f2f3f5"><img src="images/top_right_corner.gif" width="4" height="4" /></td> </tr> <tr> <td width="4" background="images/left_menu.gif" bgcolor="#f2f3f5"><img src="images/left_menu.gif" width="4" height="1" /></td> <td bgcolor="#f2f3f5"><table wIDth="98%" border="0" cellspacing="1" cellpadding="3" align="center"> <tr> <td width="20%">Catagory:</td> <td width="28%"> <select name="catagory" size="1"> <option value=<?php echo $catagory; ?>> <?php echo $catagory; ?> </option> <option value=" ">-----------------</option> <? // Query to pull information from the "catagory" Database $result = mysql_query("select * from $table13 order by id DESC"); while ($row = mysql_fetch_object($result)){ ?> <option value=<?php echo $row->name; ?>> <?php echo $row->name; ?> <? }?> </option> </select> </td> <td width="13%">Manufacturer:</td> <td width="39%"> <select name="make" size="1"> <option value=<?php echo $make; ?>> <?php echo $make; ?> </option> <option value=" ">-----------------</option> <? // Query to pull information from the "manufacturer" Database $result = mysql_query("select * from $table2 order by id DESC"); while ($row = mysql_fetch_object($result)){ ?> <option value=<?php echo $row->make; ?>> <?php echo $row->make; ?> <?}?> </option> </select> </td> </tr> <tr> <td valign="top">Product Name:</td> <td colspan="3"> <input type="Text" name="name" value="<?php echo $name ?>" size="40"> </td> </tr> <tr class=table2> <td wIDth="20%" valign="top">Description:</td> <td colspan="3"> <textarea name="description" cols="62" rows="8"><?php echo $description ?></textarea> </td> </tr> <tr> <td>Price:</td> <td><input name="price" type="Text" id="price" value="<?php echo $price ?>" size="20"></td> <td>Colour:</td> <td> <input name="colour" type="Text" id="colour" value="<?php echo $colour ?>" size="25"> </td> </tr> <tr> <td>Product of the week:</td> <td><select name="cotw" size="1"> <option value=<?php echo $cotw ?>> <?php echo $cotw ?> </option> <option value=" ">-----------------</option> <? // Query to pull information from the "sold" Database $result = mysql_query("select * from sold order by id DESC"); while ($row = mysql_fetch_object($result)){ ?> <option value=<?php echo $row->sold; ?>> <?php echo $row->sold; ?> <?}?> </option> </select> </td> <td>Sold:</td> <td> <select name="sold" size="1" id="select"> <option value=<?php echo $sold ?>> <?php echo $sold ?> </option> <option value=" ">-----------------</option> <? // Query to pull information from the "sold" Database $result = mysql_query("select * from sold order by id DESC"); while ($row = mysql_fetch_object($result)){ ?> <option value=<?php echo $row->sold; ?>> <?php echo $row->sold; ?> <?}?> </option> </select> </td> </tr> <tr class=table2> <td valign=top>IMAGES:<br> <font size="1">Please select the images (jpeg only):</font></td> <td colspan="3"> 1: <? if ($imageOneExists) { ?> Replace : <input name="imageOne" type="file" class="bginput" id="imageOne"> Delete : <input type="checkbox" name="imageOneDelete" value="yes"> <a target="_new" href="../images/products/<? echo $ID ?>one.jpg">View</a> <? } else { ?> Upload : <input name="imageOne" type="file" class="bginput" id="imageOne"> <? } ?> <br> 2: <? if ($imageTwoExists) { ?> Replace : <input name="imageTwo" type="file" class="bginput" id="imageTwo"> Delete : <input type="checkbox" name="imageTwoDelete" value="yes"> <a target="_new" href="../images/products/<? echo $ID ?>two.jpg">View</a> <? } else { ?> Upload : <input name="imageTwo" type="file" class="bginput" id="imageTwo"> <? } ?> <br> 3: <? if ($imageThreeExists) { ?> Replace : <input name="imageThree" type="file" class="bginput" id="imageThree"> Delete : <input type="checkbox" name="imageThreeDelete" value="yes"> <a target="_new" href="../images/products/<? echo $ID ?>three.jpg">View</a> <? } else { ?> Upload : <input name="imageThree" type="file" class="bginput" id="imageThree"> <? } ?> <br> 4: <? if ($imageFourExists) { ?> Replace : <input name="imageFour" type="file" class="bginput" id="imageFour"> Delete : <input type="checkbox" name="imageFourDelete" value="yes"> <a target="_new" href="../images/products/<? echo $ID ?>four.jpg">View</a> <? } else { ?> Upload : <input name="imageFour" type="file" class="bginput" id="imageFour"> <? } ?> <br> 5: <? if ($imageFiveExists) { ?> Replace : <input name="imageFive" type="file" class="bginput" id="imageFive"> Delete : <input type="checkbox" name="imageFiveDelete" value="yes"> <a target="_new" href="../images/products/<? echo $ID ?>five.jpg">View</a> <? } else { ?> Upload : <input name="imageFive" type="file" class="bginput" id="imageFive"> <? } ?> <br> 6: <? if ($imageSixExists) { ?> Replace : <input name="imageSix" type="file" class="bginput" id="imageSix"> Delete : <input type="checkbox" name="imageSixDelete" value="yes"> <a target="_new" href="../images/products/<? echo $ID ?>six.jpg">View</a> <? } else { ?> Upload : <input name="imageSix" type="file" class="bginput" id="imageSix"> <? } ?> <br> 7: <? if ($imageThumbExists) { ?> Replace : <input name="imageThumb" type="file" class="bginput" id="imageThumb"> Delete : <input type="checkbox" name="imageThumbDelete" value="yes"> <a target="_new" href="../images/products/<? echo $ID ?>thumb.jpg">View</a> <? } else { ?> Upload : <input name="imageThumb" type="file" class="bginput" id="imageThumb"> <? } ?> - Thumbnail Image</td> </tr> <!-- end of new code --> <tr class=table1> <td colspan="4" align="center" valign="top"> <input type="Submit" name="submit" value="Done!" class="bginput"> <input type="hidden" name="ID" value="<?php echo $ID; ?>"> <input type="reset" name="reset" value="Reset" class="bginput"> </td> </tr> </table></td> <td width="4" background="images/right_menu.gif" bgcolor="#f2f3f5"><img src="images/right_menu.gif" width="4" height="1" /></td> </tr> <tr> <td width="4" height="4" bgcolor="#f2f3f5"><img src="images/bottom_left_corner.gif" width="4" height="4" /></td> <td height="4" background="images/bottom_menu.gif" bgcolor="#f2f3f5"><img src="images/bottom_menu.gif" width="1" height="4" /></td> <td width="4" height="4" bgcolor="#f2f3f5"><img src="images/bottom_right_corner.gif" width="4" height="4" /></td> </tr> </table></td> </tr> </table> </td> </tr> </table> </FORM><?php } ?> </td> </tr> </table> <? include("includes/footer.php") ?> Link to comment https://forums.phpfreaks.com/topic/95080-database-edit/#findComment-487042 Share on other sites More sharing options...
BlueSkyIS Posted March 8, 2008 Share Posted March 8, 2008 you need to ALWAYS quote values in form elements <option value='<?php echo $make; ?>'> <?php echo $make; ?> </option> Link to comment https://forums.phpfreaks.com/topic/95080-database-edit/#findComment-487046 Share on other sites More sharing options...
jacko_162 Posted March 8, 2008 Author Share Posted March 8, 2008 thanks, that worked Link to comment https://forums.phpfreaks.com/topic/95080-database-edit/#findComment-487051 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.