Jump to content

lill77

Members
  • Posts

    29
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

lill77's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello I have a problem that updates every product in my database when i add a new 1 to the the new product details. Can anyone help? Thanks Code is below New product page <?php include 'db.php'; // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); $sql = "INSERT INTO `products` (`category_id` , `title` , `size` , `description` , `image` , `imageenlarge`) VALUES ( '', '$title', '$size', '$description' , '', '');"; $sql_query = mysql_query($sql) or die (mysql_error()); $sql = "SELECT LAST_INSERT_ID()"; $result = mysql_query($sql); $row = mysql_fetch_row($result); $product_id = $row[0]; // free result set memory mysql_free_result($result); // close connection mysql_close($connection); ?> <META HTTP-EQUIV=Refresh CONTENT='0; URL=index.php?page=edit-product.php&product=<? echo $product_id; ?>'> <p align="center" class="smalltext style2 style1">Saving Changes</p> Update Product <? include 'db.php' ?> <? // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); $sql_query = mysql_query("UPDATE `products` SET `title` = '".$_REQUEST['title']."', `size` = '".$_REQUEST['size']."', `description` = '".$_REQUEST['description']."', `category_id` = ".$_REQUEST['category_id'].", `Image` = '".$_REQUEST['image']."', `Imageenlarge` = '".$_REQUEST['imageenlarge']."'") or die (mysql_error()); // close connection mysql_close($connection); ?> <META HTTP-EQUIV=Refresh CONTENT="0; URL=index.php?page=products.php"> Edit page <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <? include 'db.php' ?> <script language="javascript" type="text/javascript"><!-- function popupWindow(url, width, height) { if(width == null){ width =450; } if(height == null){height =150;} window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+width+',height='+height+',screenX=150,screenY=150,top=150,left=100') } //--></script> <script> function log_out() { return confirm('Are you sure you want to Delete this article?'); } </script> <?php // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // create query $query = "SELECT * FROM `products` WHERE `ID` = '".$_REQUEST['product']."'"; // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $row = mysql_fetch_row($result); $CurrentProduct = $row[0]; // free result set memory mysql_free_result($result); // close connection mysql_close($connection); ?> <body> <form method="GET" action="update-product.php"> <div align="center"> <table width="505" border="0" cellpadding="2" cellspacing="2" bordercolor="#FFFFFF" bordercolorlight="#C0C0C0" bordercolordark="#C0C0C0" id="table1"> <tr> <td width="130" align="right"><b> <font face="Arial" size="2" color="#808080">Product ID:</font></b></td> <td width="228" align="center"> <p align="left"> <? echo "$row[0]" ?> <input name="ID" type="hidden" id="ID" value="<? echo "$row[0]" ?>" /> </p> </td> <td width="127" align="right"> </td> </tr> <tr> <td width="130" align="right"><b> <font face="Arial" size="2" color="#808080">Title:</font></b></td> <td align="center"> <div align="left"> <input type="text" name="title" size="36" value="<? echo "$row[2]" ?>" ?> </div></td> <td width="127" align="right"> </td> </tr> <tr> <td width="130"><div align="right"><b><font face="Arial" size="2" color="#808080">Sizes </font></b></div></td> <td align="center"><div align="left"> <input type="text" name="size" size="36" value="<? echo "$row[3]" ?>" ? /><br /> (Format: <b>Small/Medium/Large</b>) </div></td> <td width="127"> </td> </tr> <tr> <td width="130" align="right"><b><font face="Arial" size="2" color="#808080">Description:</font></b></td> <td align="center"><div align="left"> <textarea name="description" cols="50" rows="10" id="description"><? echo "$row[4]" ?></textarea> </div></td> <td width="127" align="right"> </td> </tr> <tr> <td width="130" align="right"><b><font face="Arial" size="2" color="#808080">Category:</font></b></td> <td align="center"><div align="left"> <p> </p> <p><select name="category_id" id="category_id"> <?php $currentcat = $row[1]; // set database server access variables: // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // create query $query = "SELECT * FROM `category`;"; // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($result) > 0) { // yes // print them one after another while($row = mysql_fetch_row($result)) { echo "<option value=\"".$row[0]."\""; if ($row[0]==$currentcat) {echo " Selected";}; echo ">$row[1]</option>"; } } // free result set memory mysql_free_result($result); // close connection mysql_close($connection); ?> </select> </p> </div></td> <td width="127" align="right"> </td> </tr> <tr> <td width="130" align="right"><b><font face="Arial" size="2" color="#808080">Image:</font></b></td> <td align="center"><div align="left"> <select name="image" id="image"> <option value="noimage.png">No Image</option> <?php if ($handle = opendir('../productimages/')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $page_name = $file; //$page_name=substr($file, 0, strpos($file, ".")); echo "<option"; if($page_name==$row[5]){echo ' selected';}; echo ">$page_name</option>"; } } } closedir($handle); ?> </select> </div></td> <td width="127" align="right"> </td> </tr> <tr> <td align="right"><b><font face="Arial" size="2" color="#808080">Enlarge Image:</font></b></td> <td align="center"><div align="left"> <select name="imageenlarge" id="imageenlarge"> <option value="noimage.png">No Image</option> <?php if ($handle = opendir('../productimages/')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $page_name = $file; //$page_name=substr($file, 0, strpos($file, ".")); echo "<option"; if($page_name==$row[6]){echo ' selected';}; echo ">$page_name</option>"; } } } closedir($handle); ?> </select> </div></td> <td align="right"> </td> </tr> <tr> <td width="130" align="right"> </td> <td align="center"><div align="left"></div></td> <td width="127" align="right"> </td> </tr> <tr> <td width="130"> </td> <td align="center"><div align="left"></div></td> <td width="127" align="right"> </td> </tr> <tr> <td width="130" align="right"> </td> <td align="center"> </td> <td width="127" align="right"> </td> </tr> <tr> <td width="130" align="right"> </td> <td align="center"> </td> <td width="127" align="right"> </td> </tr> <tr> <td width="130"> </td> <td align="center"> </td> <td width="127" align="right"> </td> </tr> <tr> <td> </td> <td align="center"> </td> <td> </td> </tr> </table> </div> <p align="center"><input type="submit" value="Save" name="B1"> <input type="reset" value="Close" name="B2" onclick="history.back()"> </p> </form> </p> <p align="center"> </p> </body> </html>
  2. Great thanks for your help, I will have a go and see if i can do it ? Rich
  3. Hello anybody out there who can help me with this \?? :'( :'( When i add a new product it changes all in my database to the details i just added ?? Rich
  4. Hi again.. bit lost now. I have new product pages as below <?php include 'db.php'; // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); $sql = "INSERT INTO `products` (`category_id` , `title` , `size` , `description` , `image` , `imageenlarge`) VALUES ( '', '$title', '$size', '$description' , '', '');"; $sql_query = mysql_query($sql) or die (mysql_error()); $sql = "SELECT LAST_INSERT_ID()"; $result = mysql_query($sql); $row = mysql_fetch_row($result); $product_id = $row[0]; // free result set memory mysql_free_result($result); // close connection mysql_close($connection); ?> <META HTTP-EQUIV=Refresh CONTENT='0; URL=index.php?page=edit-product.php&product=<? echo $product_id; ?>'> <p align="center" class="smalltext style2 style1">Saving Changes</p> and also the edit page, then as below the update product <? include 'db.php' ?> <? // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); $sql_query = mysql_query("UPDATE `products` SET `title` = '".$_REQUEST['title']."', `size` = '".$_REQUEST['size']."', `description` = '".$_REQUEST['description']."', `category_id` = ".$_REQUEST['category_id'].", `Image` = '".$_REQUEST['image']."', `Imageenlarge` = '".$_REQUEST['imageenlarge']."'") or die (mysql_error()); // close connection mysql_close($connection); ?> <META HTTP-EQUIV=Refresh CONTENT="0; URL=index.php?page=products.php">
  5. Hello thanks where abouts in the code should this be entered. . . ??
  6. What should I be doing then ? This code if from the edit-product.php. Thanks
  7. Hello when i insert a new product ino my database it changes all exsisitng products to the same as the new one ??? Ive llloked at the code i have and cant see where the problem is ?? <?php include 'db.php'; // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); $sql = "INSERT INTO `products` (`category_id` , `title` , `size` , `description` , `image` , `imageenlarge`) VALUES ( '', '', 'size', '' , 'noimage.png', 'noimage_big.png');"; $reult = mysql_query($sql) or die (mysql_error()); $product_id = mysql_insert_id(); // close connection mysql_close($connection); ?> <META HTTP-EQUIV=Refresh CONTENT='0; URL=index.php?page=edit-product.php&product=<? echo $product_id; ?>'> <p align="center" class="smalltext style2 style1">Saving Changes</p> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <? include 'db.php' ?> <script language="javascript" type="text/javascript"><!-- function popupWindow(url, width, height) { if(width == null){ width =450; } if(height == null){height =150;} window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+width+',height='+height+',screenX=150,screenY=150,top=150,left=100') } //--></script> <script> function log_out() { return confirm('Are you sure you want to Delete this article?'); } </script> <?php // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // create query $query = "SELECT * FROM `products` WHERE `ID` = '".$_REQUEST['product']."'"; // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $row = mysql_fetch_row($result); $CurrentProduct = $row[0]; // free result set memory mysql_free_result($result); // close connection mysql_close($connection); ?> <body> <form method="GET" action="update-product.php"> <div align="center"> <table width="505" border="0" cellpadding="2" cellspacing="2" bordercolor="#FFFFFF" bordercolorlight="#C0C0C0" bordercolordark="#C0C0C0" id="table1"> <tr> <td width="130" align="right"><b> <font face="Arial" size="2" color="#808080">Product ID:</font></b></td> <td width="228" align="center"> <p align="left"> <? echo "$row[0]" ?> <input name="ID" type="hidden" id="ID" value="<? echo "$row[0]" ?>" /> </p> </td> <td width="127" align="right"> </td> </tr> <tr> <td width="130" align="right"><b> <font face="Arial" size="2" color="#808080">Title:</font></b></td> <td align="center"> <div align="left"> <input type="text" name="title" size="36" value="<? echo "$row[2]" ?>" ?> </div></td> <td width="127" align="right"> </td> </tr> <tr> <td width="130"><div align="right"><b><font face="Arial" size="2" color="#808080">Sizes </font></b></div></td> <td align="center"><div align="left"> <input type="text" name="size" size="36" value="<? echo "$row[3]" ?>" ? /><br /> (Format: <b>Small/Medium/Large</b>) </div></td> <td width="127"> </td> </tr> <tr> <td width="130" align="right"><b><font face="Arial" size="2" color="#808080">Description:</font></b></td> <td align="center"><div align="left"> <textarea name="description" cols="50" rows="10" id="description"><? echo "$row[4]" ?></textarea> </div></td> <td width="127" align="right"> </td> </tr> <tr> <td width="130" align="right"><b><font face="Arial" size="2" color="#808080">Category:</font></b></td> <td align="center"><div align="left"> <p> </p> <p><select name="category_id" id="category_id"> <?php $currentcat = $row[1]; // set database server access variables: // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // create query $query = "SELECT * FROM `category`;"; // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($result) > 0) { // yes // print them one after another while($row = mysql_fetch_row($result)) { echo "<option value=\"".$row[0]."\""; if ($row[0]==$currentcat) {echo " Selected";}; echo ">$row[1]</option>"; } } // free result set memory mysql_free_result($result); // close connection mysql_close($connection); ?> </select> </p> </div></td> <td width="127" align="right"> </td> </tr> <tr> <td width="130" align="right"><b><font face="Arial" size="2" color="#808080">Image:</font></b></td> <td align="center"><div align="left"> <select name="image" id="image"> <option value="noimage.png">No Image</option> <?php if ($handle = opendir('../productimages/')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $page_name = $file; //$page_name=substr($file, 0, strpos($file, ".")); echo "<option"; if($page_name==$row[5]){echo ' selected';}; echo ">$page_name</option>"; } } } closedir($handle); ?> </select> </div></td> <td width="127" align="right"> </td> </tr> <tr> <td align="right"><b><font face="Arial" size="2" color="#808080">Enlarge Image:</font></b></td> <td align="center"><div align="left"> <select name="imageenlarge" id="imageenlarge"> <option value="noimage.png">No Image</option> <?php if ($handle = opendir('../productimages/')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $page_name = $file; //$page_name=substr($file, 0, strpos($file, ".")); echo "<option"; if($page_name==$row[6]){echo ' selected';}; echo ">$page_name</option>"; } } } closedir($handle); ?> </select> </div></td> <td align="right"> </td> </tr> <tr> <td width="130" align="right"> </td> <td align="center"><div align="left"></div></td> <td width="127" align="right"> </td> </tr> <tr> <td width="130"> </td> <td align="center"><div align="left"></div></td> <td width="127" align="right"> </td> </tr> <tr> <td width="130" align="right"> </td> <td align="center"> </td> <td width="127" align="right"> </td> </tr> <tr> <td width="130" align="right"> </td> <td align="center"> </td> <td width="127" align="right"> </td> </tr> <tr> <td width="130"> </td> <td align="center"> </td> <td width="127" align="right"> </td> </tr> <tr> <td> </td> <td align="center"> </td> <td> </td> </tr> </table> </div> <p align="center"><input type="submit" value="Save" name="B1"> <input type="reset" value="Close" name="B2" onclick="history.back()"> </p> </form> </p> <p align="center"> </p> </body> </html>
  8. Hello ive been helped before and am knew to this i really want to display products acroos the page by 4 then contnuing down by ABC.. My code is below can anybody shed some light for me. ??? ??? <?php include 'admin/db.php'; include 'header-home.php'; // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // create query $query = "SELECT * FROM `products` ORDER BY 'CAT' ASC"; // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($result) > 0) { // yes // print them one after another while($row = mysql_fetch_array($result)) { echo "<tr><td align='left' valign='top'><a href='search.php?cat=$row[iD]'>$row[CAT]</a> </tr>"; } } else { // no // print status message echo "<p align='center'><font color='#808080' face='Arial'>No records found.</font></p>"; } // free result set memory mysql_free_result($result); // close connection mysql_close($connection); ?> <?php // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // create query if (isset($_REQUEST['search'])) { $query = "SELECT * FROM products WHERE description LIKE '%".$_REQUEST['search']."%'"; } else if (isset($_REQUEST['cat'])) { $query = "SELECT * FROM products WHERE category_id = ".$_REQUEST['cat']." ORDER BY Title ASC"; } // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if ($num=mysql_num_rows($result) > 0) { // yes // print them one after another ECHO "<table width='90%' height='257' border='0'>"; while($row = mysql_fetch_array($result)) { ?> <p class="style13"> </p> <table width="168" border="0" align="center"> <tr> <td><div align="center"><span class="style13"><? echo $row['title']; ?></span></div></td> </tr> <tr> <td><a href='productimages/<?=$row[5];?> ' rel="lightbox"><img src="productimages/<?=$row[6];?>" width="133" height="180" /></td> </tr> <tr> <td><? echo $row['description']; ?> <div align="center"></div> <div align="center"></div></td> </tr> <tr> <td><div align="center"><span class="style6">Size: <? echo $row['size']; ?></span></div></td> </tr> </table> <p> </p></td> </tr><tr bgcolor="#6699FF"><td height="20" valign="top" bgcolor="#FFFFFF"> </td> </tr> <p> <? } } // free result set memory mysql_free_result($result); // close connection mysql_close($connection); include 'footer.php';?>
  9. Thanks It is better the save the info into a field that is most common eg product, and then search by make ? Do you know of any links to how to do this eg. help or tutorial ?? Thanks for your help Rich
  10. Hello im back again. So I gather that i can show products by type eg duvet set or fleece or pillow etc... and also show by make of the product, with the way im saving the info in my database. Thanks
  11. Great thanks i WILL see how I go !
  12. Im getting myself confussed. I need to save products by two ways cat and by product so it would be a Cushion that belongs to say . . M&S. So then I could pull the info in by product eg cushion and or by M&S. Thanks
  13. Hello I think i want to display the products maybe 4 across the page and list by abc . . . Thanks
  14. Thanks would that be someting like $query = "SELECT * FROM `products` ORDER BY 'CAT' ASC"; an $query = "SELECT * FROM `category` ORDER BY 'CAT' ASC"; ?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.