Jump to content

webznz

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Everything posted by webznz

  1. Great thank you so much for the solution and the explanation works perfectly!
  2. after doing that this is what was printed to the screen. However there is still an entry missing before Mag Wheel, here are the database entries (buffer is the one missing)
  3. Hi there Im currently working on a website for a friend. A, to help him out B, to give me some experiance. I have created a mySql database that has a table called Products in it, there are several columns like ID, Name, Description. I have also made a back end system that updates the database with information entered into an html form please see code for this below... <html> <head> <title> MTS Controll panle </title> <link rel="stylesheet" type="text/css" href="../css/backend.css" /> </head> <body> <div id="wrap"> <div id="header"></div> <div id="nav"></div> <div id="sidebar"> <!-- start of controll links --> <a href="bk_index.html">Insert new Products</a></br> <a href="php/Delete.php">Delete Products</a></br> <a href="bk_services.html">Insert New Service</a></br> <a href="php/Delete_services.php">Delete Services</a></br> <!-- controll links end here --> </div> <div id="main"> <!-- controll panel start here --> <form method="post" action="php/update_products.php"> Item Type:</br> <input type="text" name="Name" size="25" /></br></br> Modle:</br> <input type="text" name="ModelName" size="25" /></br></br> Description:</br> <textarea rows="10" cols="20" wrap="physical" name="Description"> </textarea></br> Slideshow:</br> <textarea rows="10" cols="20" wrap="physical" name="SlideShow"> </textarea></br> Price:</br> <input type="text" name="Price" size="25" /></br></br> <input type="submit" value="Update Database" /> </form> <!--controllpanel links start here --> </div> <div align="center"> <div id="footer">Controll Panel Developed by Casey Smith</div> </div> </div> </body> </html> Here is update_products.php <?php $Name =$_POST['Name']; $ModelName =$_POST['ModelName']; $Description =$_POST['Description']; $SlideShow =$_POST['SlideShow']; $Price =$_POST['Price']; mysql_connect ("localhost", "root", "maryanne") or die ('Error: ' . mysql_error()); mysql_select_db ("mtsproducts"); $query="INSERT products (Name, ModelName, Description, SlideShow, Price)VALUES ('".$Name."', '".$ModelName."', '".$Description."', '".$SlideShow."', '".$Price."')"; mysql_query($query) or die ('Error updating database'); echo "1 entry entered" .$Name. " " .$ModelName. " " .$Description. " " . htmlspecialchars($SlideShow) . " " .$Price ; ?> From here the database is now updated with the information entered by the user. At the front end the first thing Im trying to create with this data from the database is a type of user menu generated from the Name column in Products, just nice and simple for now however *as you will see in the code below* I have a print loop that dosnt seem to want to print the first entry in the database. i.e. if this was the array[0], array[1], array[2]. Only array[1] & array[2] would be echoed to the screen?! Here is the code for the client side page. <html> <head> <title>MTS - Mag - Tyers - Suspension</title> <link rel="stylesheet" type="text/css" href="css/main.css" /> <!-- Mouse over buttons --> <SCRIPT LANGUAGE="JavaScript"> <!-- Hide from old browsers var NN3 = false; image1 = new Image(); image1.src = "images/menu/home_button1.png"; image1on = new Image(); image1on.src = "images/menu/home_button2.png"; image2 = new Image(); image2.src = "images/menu/service_button1.png"; image2on = new Image(); image2on.src = "images/menu/service_button2.png"; image3 = new Image(); image3.src = "images/menu/shop_button1.png"; image3on = new Image(); image3on.src = "images/menu/shop_button2.png"; image4 = new Image(); image4.src = "images/menu/gallery_button1.png"; image4on = new Image(); image4on.src = "images/menu/gallery_button2.png"; image5 = new Image(); image5.src = "images/menu/videos_button1.png"; image5on = new Image(); image5on.src = "images/menu/videos_button2.png"; image6 = new Image(); image6.src = "images/menu/contact_button1.png"; image6on = new Image(); image6on.src = "images/menu/contact_button2.png"; function on3(name) { document[name].src = eval(name + "on.src"); } function off3(name) { document[name].src = eval(name + ".src"); } NN3 = true; function on(name) { if (NN3) on3(name); } function off(name) { if (NN3) off3(name); } // --> </SCRIPT> <!-- Mouse over Button END --> </head> <body onload="initialize()"> <div id="top-centerbar"> <div id="container"> <!-- AddThis Button starts here --> <a class="addthis_button" href="http://www.addthis.com/bookmark.php?v=250&username=xa-4b60df317994ba46"><img src="http://s7.addthis.com/static/btn/sm-share-en.gif" width="83" height="16" alt="Bookmark and Share" style="border:0"/></a><script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=xa-4b60df317994ba46"></script> <!-- AddThis Button ends here --> </div id> </div id> <div id="inside-main_b"> <div id="services_main"> <div align="left"> <!-- php code from here --> <?php mysql_connect ("localhost", "root", "verysecret") or die ('Error: ' . mysql_error()); mysql_select_db ("mtsproducts") or die('Database Error' . mysql_error()); ?> <?php $data = mysql_query("SELECT name FROM products") or die(mysql_error()); $info = mysql_fetch_array( $data ); Print "<b>Products:</b></br> "; while($info = mysql_fetch_array( $data )){ Print "" .$info[0]. "</br> "; } ?> <!-- php code to here --> </div> </div id> </div id> <div align="center"> <div id="bottom-centerbar"> <!-- buttons start --> <a href="index.html" onmouseover="on('image1');" onmouseout="off('image1')"><img src="images/menu/home_button1.png" border="0" name="image1" ALT="Click for next page" ALIGN=ABSMIDDLE></a>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp <a href="services.php" onmouseover="on('image2');" onmouseout="off('image2')"><img src="images/menu/service_button1.png" border="0" name="image2" ALT="Click for next page" ALIGN=ABSMIDDLE></a>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp <a href="shop.html" onmouseover="on('image3');" onmouseout="off('image3')"><img src="images/menu/shop_button1.png" border="0" name="image3" ALT="Click for next page" ALIGN=ABSMIDDLE></a>&nbsp&nbsp&nbsp&nbsp&nbsp <a href="gallery.html" onmouseover="on('image4');" onmouseout="off('image4')"><img src="images/menu/gallery_button1.png" border="0" name="image4" ALT="Click for next page" ALIGN=ABSMIDDLE></a>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp <a href="videos.html" onmouseover="on('image5');" onmouseout="off('image5')"><img src="images/menu/videos_button1.png" border="0" name="image5" ALT="Click for next page" ALIGN=ABSMIDDLE></a>&nbsp&nbsp&nbsp&nbsp&nbsp <a href="contact.html" onmouseover="on('image6');" onmouseout="off('image6')"><img src="images/menu/contact_button1.png" border="0" name="image6" ALT="Click for next page" ALIGN=ABSMIDDLE></a> <!-- buttons end --> </div id> </body> </html> any help would be greatly appreciated. Regards Casey.
  4. I realize i named this thread a stupid name, it should be I need help, or how do you? etc etc.. sounds like im telling people how to do it when i dont actually know myself. Is there a way to edit the thread? i have looked everywhere.
  5. I have been trying to find out how to store html code into a mysql table then later use it on another page. I have a form where the user can input products lets say for a car. one of the fields is for embedded Picasa slide show code. here is the form for inserting: <!-- controll panel start here --> <form method="post" action="php/update.php"> Item Type:</br> <input type="text" name="Name" size="25" /></br></br> Modle:</br> <input type="text" name="ModelName" size="25" /></br></br> Description:</br> <textarea rows="10" cols="20" wrap="physical" name="Description"> </textarea></br> Slideshow:</br> <textarea rows="10" cols="20" wrap="physical" name="SlideShow"> </textarea></br> Price:</br> <input type="text" name="Price" size="25" /></br></br> <input type="submit" value="Update Database" /> </form> <!--controllpanel links start here --> once update database is clicked the information in the text fields are then sent to update.php which is here: <?php $Name =$_POST['Name']; $ModelName =$_POST['ModelName']; $Description =$_POST['Description']; $SlideShow =$_POST['SlideShow']; $Price =$_POST['Price']; mysql_connect ("localhost", "root", "onlyiknow") or die ('Error: ' . mysql_error()); mysql_select_db ("mtsproducts"); $query="INSERT products (Name, ModelName, Description, SlideShow, Price)VALUES ('".$Name."', '".$ModelName."', '".$Description."', '".$SlideShow."', '".$Price."')"; mysql_query($query) or die ('Error updating database'); echo "1 entry entered" .$Name. " " .$ModelName. " " .$Description. " " . htmlspecialchars($SlideShow) . " " .$Price ; ?> The questions I have are - Am i storing the embedded code correctly into the mysql SlideShow column? - How do i later use/call this code so it shows my picasa slideshow on a different page? any suggestions would be much appreciated.
  6. okay i did alot more digging around and seem to have found the solution. where this code appears <?=$PHP_SELF?> needs to be replaced with <?php echo($PHP_SELF); ?> i found the problem because after submitting each image it would come up with a weird url each time i tried to submit. but the echo php_self is what is needed to reload the page with the updated content.
  7. Hi there im currently working with a small tutorial --> http://www.anyexample.com/programming/php/php_mysql_example__image_gallery_(blob_storage).xml its fairly straight forward and i hope to use parts of the code later to produce my own variation for a car site im building for a friend. The only thing being is that im getting an error i have never meet before and am unsure how to get round it, this is the error. The table has been set up properly and is working fine, apache is also working fine as i can work on all my other pages without any errors so im guessing its in the code but im just not sure what to look at as i have never experienced this type of error any help would be appreciated. <?php $db_host = 'localhost'; // don't forget to change $db_user = 'root'; $db_pwd = 'verysecret'; $database = 'mtsproducts'; $table = 'ae_gallery'; // use the same name as SQL table $password = '123'; // simple upload restriction, // to disallow uploading to everyone if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); // This function makes usage of // $_GET, $_POST, etc... variables // completly safe in SQL queries function sql_safe($s) { if (get_magic_quotes_gpc()) $s = stripslashes($s); return mysql_real_escape_string($s); } // If user pressed submit in one of the forms if ($_SERVER['REQUEST_METHOD'] == 'POST') { // cleaning title field $title = trim(sql_safe($_POST['title'])); if ($title == '') // if title is not set $title = '(empty title)';// use (empty title) string if ($_POST['password'] != $password) // cheking passwors $msg = 'Error: wrong upload password'; else { if (isset($_FILES['photo'])) { @list(, , $imtype, ) = getimagesize($_FILES['photo']['tmp_name']); // Get image type. // We use @ to omit errors if ($imtype == 3) // cheking image type $ext="png"; // to use it later in HTTP headers elseif ($imtype == 2) $ext="jpeg"; elseif ($imtype == 1) $ext="gif"; else $msg = 'Error: unknown file format'; if (!isset($msg)) // If there was no error { $data = file_get_contents($_FILES['photo']['tmp_name']); $data = mysql_real_escape_string($data); // Preparing data to be used in MySQL query mysql_query("INSERT INTO {$table} SET ext='$ext', title='$title', data='$data'"); $msg = 'Success: image uploaded'; } } elseif (isset($_GET['title'])) // isset(..title) needed $msg = 'Error: file not loaded';// to make sure we've using // upload form, not form // for deletion if (isset($_POST['del'])) // If used selected some photo to delete { // in 'uploaded images form'; $id = intval($_POST['del']); mysql_query("DELETE FROM {$table} WHERE id=$id"); $msg = 'Photo deleted'; } } } elseif (isset($_GET['show'])) { $id = intval($_GET['show']); $result = mysql_query("SELECT ext, UNIX_TIMESTAMP(image_time), data FROM {$table} WHERE id=$id LIMIT 1"); if (mysql_num_rows($result) == 0) die('no image'); list($ext, $image_time, $data) = mysql_fetch_row($result); $send_304 = false; if (php_sapi_name() == 'apache') { // if our web server is apache // we get check HTTP // If-Modified-Since header // and do not send image // if there is a cached version $ar = apache_request_headers(); if (isset($ar['If-Modified-Since']) && // If-Modified-Since should exists ($ar['If-Modified-Since'] != '') && // not empty (strtotime($ar['If-Modified-Since']) >= $image_time)) // and grater than $send_304 = true; // image_time } if ($send_304) { // Sending 304 response to browser // "Browser, your cached version of image is OK // we're not sending anything new to you" header('Last-Modified: '.gmdate('D, d M Y H:i:s', $ts).' GMT', true, 304); exit(); // bye-bye } // outputing Last-Modified header header('Last-Modified: '.gmdate('D, d M Y H:i:s', $image_time).' GMT', true, 200); // Set expiration time +1 year // We do not have any photo re-uploading // so, browser may cache this photo for quite a long time header('Expires: '.gmdate('D, d M Y H:i:s', $image_time + 86400*365).' GMT', true, 200); // outputing HTTP headers header('Content-Length: '.strlen($data)); header("Content-type: image/{$ext}"); // outputing image echo $data; exit(); } ?> <html><head> <title>MySQL Blob Image Gallery Example</title> </head> <body> <?php if (isset($msg)) // this is special section for // outputing message { ?> <p style="font-weight: bold;"><?=$msg?> <br> <a href="<?=$PHP_SELF?>">reload page</a> <!-- I've added reloading link, because refreshing POST queries is not good idea --> </p> <?php } ?> <h1>Blob image gallery</h1> <h2>Uploaded images:</h2> <form action="<?=$PHP_SELF?>" method="post"> <!-- This form is used for image deletion --> <?php $result = mysql_query("SELECT id, image_time, title FROM {$table} ORDER BY id DESC"); if (mysql_num_rows($result) == 0) // table is empty echo '<ul><li>No images loaded</li></ul>'; else { echo '<ul>'; while(list($id, $image_time, $title) = mysql_fetch_row($result)) { // outputing list echo "<li><input type='radio' name='del' value='{$id}'>"; echo "<a href='{$PHP_SELF}?show={$id}'>{$title}</a> – "; echo "<small>{$image_time}</small></li>"; } echo '</ul>'; echo '<label for="password">Password:</label><br>'; echo '<input type="password" name="password" id="password"><br><br>'; echo '<input type="submit" value="Delete selected">'; } ?> </form> <h2>Upload new image:</h2> <form action="<?=$PHP_SELF?>" method="POST" enctype="multipart/form-data"> <label for="title">Title:</label><br> <input type="text" name="title" id="title" size="64"><br><br> <label for="photo">Photo:</label><br> <input type="file" name="photo" id="photo"><br><br> <label for="password">Password:</label><br> <input type="password" name="password" id="password"><br><br> <input type="submit" value="upload"> </form> </body> </html>
  8. AHHHHA!!! got it! lol thanks for your help I just added <?php $deleteproduct=$_GET['deleteproduct'] ?> above the first php statement and it works perfectly! thank you very much i should have been able to solve this myself lol need to get some more practice in b4 uni starts up again this semester! thanks again! regards Casey
  9. could you show me where to put $_GET['deleteproduct'] in my code in order to get this to work as my command over the php syantax is a little rusty. Thanks for all the help you have given me its greatly appreciated.
  10. Took a while for me to understand what you mean but I think i get it now. there is already a link next to each database entry heres the code for that. while ( $row = mysql_fetch_array($result) ) { $ID = $row["partID"]; $text = $row["Name"]; echo("<P>$text " . "<A HREF='$PHP_SELF?deleteproduct=$ID'>" . "Delete this product</A></P>"); so deleteproduct gets the $ID value which is set just above it with the row in my databse 'PartID' as you can see the link then reloads the page if pressed. However the page loads when a link is clicked but nothing is deleted i assume because the $ID value never makes it to if (isset($deleteproduct)) { $sql = "DELETE FROM products " . "WHERE partID=$deleteproduct"; shouldnt $deleteproduct already have $ID value by this point?
  11. Sorry about that initially i was going to have a septate file DELETE.php where the delete functionality would be, but after realizing i could use a simple if else statement and keep all the code on one page i decided to do that, however have left the link there to the old file, sorry about that. by my mind i thought if (isset($deleteproduct)) { $sql = "DELETE FROM products " . "WHERE partID=$deleteproduct"; is where the id is given its value to delete?
  12. Hi there im currently writing my first back end to a website where I enable myself to add new items to my database and delete them. I followed a Mysql tutorial to get myself started and have done some php at uni but im still pretty new so am finding it hard to solve the problem i am having. Basicly everything works correctly I.E. connect to the database and all items that are currently in the database are presented but then when i click the delete this product link nothing happens. here is my code thank you for taking you time to help me. <html> <head> <title> MTS Controll panle </title> <link rel="stylesheet" type="text/css" href="http://127.0.0.1/mts/css/backend.css" /> </head> <body> <div id="wrap"> <div id="header"></div> <div id="nav"></div> <div id="sidebar"> <!-- start of controll links --> <a href="../backend.html">Insert new Products</a></br> <a href="Delete.php">Delete Products</a> <!-- controll links end here --> </div> <div id="main"> <!-- controll panel start here --> <?php // If the user wants to add a product if (isset($addproduct)): ?> <FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST> <P>Type your Product here:<BR> <TEXTAREA NAME="producttext" ROWS=10 COLS=40 WRAP> </TEXTAREA><BR> <INPUT TYPE=SUBMIT NAME="submitproduct" VALUE="SUBMIT"> </FORM> <?php else: // Connect to the database server $dbcnx = @mysql_connect( "localhost", "root", "secretpass"); if (!$dbcnx) { echo( "<P>Unable to connect to the " . "database server at this time.</P>" ); exit(); } // Select the mtsproducts database if (! @mysql_select_db("mtsproducts") ) { echo( "<P>Unable to locate the products " . "database at this time.</P>" ); exit(); } // If a product has been submitted, // add it to the database. if ("SUBMIT" == $submitproduct) { $sql = "INSERT INTO products SET " . "productText='$producttext', " ; if (mysql_query($sql)) { echo("<P>Your product has been added.</P>"); } else { echo("<P>Error adding submitted product: " . mysql_error() . "</P>"); } } // If a product has been deleted, // remove it from the database. if (isset($deleteproduct)) { $sql = "DELETE FROM products " . "WHERE partID=$deleteproduct"; if (mysql_query($sql)) { echo("<P>The product has been deleted.</P>"); } else { echo("<P>Error deleting product: " . mysql_error() . "</P>"); } } echo("<P> Here are all the products " . "in our database: </P>"); // Request the ID and text of all the products $result = mysql_query( "SELECT partID, Name FROM products"); if (!$result) { echo("<P>Error performing query: " . mysql_error() . "</P>"); exit(); } // Display the text of each product in a paragraph // with a "Delete this product" link next to each. while ( $row = mysql_fetch_array($result) ) { $ID = $row["partID"]; $text = $row["Name"]; echo("<P>$text " . "<A HREF='$PHP_SELF?deleteproduct=$ID'>" . "Delete this product</A></P>"); } // When clicked, this link will load this page // with the product submission form displayed. echo("<P><A HREF='$PHP_SELF?addproduct=1'>" . "Add a product!</A></P>"); endif; ?> <!--controllpanel links start here --> </div> <div align="center"> <div id="footer">Controll Panel Developed by Casey Smith</div> </div> </div> </body> </html>
×
×
  • 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.