Merdok Posted April 18, 2007 Share Posted April 18, 2007 Hi Guys, I'm sure this is really simple but I am not brilliant at PHP and I cant figure it out... I basically need to create an edit/delete record page for my website and I cant figure out how to do it! You guys have been a great help before so I was hoping one of you might be able to help me this time... here is the contents of the insert item script. <?php require_once('../../Connections/stockCONN.php'); $page_title = "Validate Data"; require_once('../../header.php'); // Include the error function include('../includes/error.php'); function clean($input, $maxlength){ $input = substr($input, 0, $maxlength); $input = addslashes($input); return ($input); } //-------------------------------------------------------- INITIALISE AN ERROR STRING ------------------------------- $errorString = ""; //------------------------------- GET THE POSTED VALUES, CLEAN AND TRIM -------------------------------------- foreach($HTTP_POST_VARS as $varname => $value) $formVars[$varname] = trim(clean($value, 500)); //---------------------------------------------Validation for the image uploader //------------ Description ------------------------------------------------------------------------- //The Super Global Variable $_FILES is used in PHP 4.x.x. //$_FILES['upload']['size'] ==> Get the Size of the File in Bytes. //$_FILES['upload']['tmp_name'] ==> Returns the Temporary Name of the File. //$_FILES['upload']['name'] ==> Returns the Actual Name of the File. //$_FILES['upload']['type'] ==> Returns the Type of the File. //So if I filetoupload the file 'test.doc', the $_FILES['upload']['name'] //would be 'phptut.doc' and $_FILES['upload']['type'] would be 'application/msword'. //------------------------------------------------------------------------------------------------------ // this is the upload dir where files will go. //Don't remove the / //Chmod it (777) //---------------------- Change to whatever you want.--------------------------------------------------- $upload_dir = "../images/"; //----------------------- Files less than 1MB ------------------------------------------------------------- $size_bytes = 1048576; //bytes will be uploaded //-------------------------Check if the directory exists or not -------------------------------------------- if (!is_dir("$upload_dir")) { die ("The directory <b>($upload_dir)</b> doesn't exist"); } // ------------------ Check if the directory is writable. --------------------------------------------------- if (!is_writeable("$upload_dir")) { die ("The directory <b>($upload_dir)</b> is NOT writable, Please Chmod (777)"); } //------------------------- Check first if a file has been selected //------------------------- is_filetoupload_file('filename') returns true if //------------------------- a file was filetoupload via HTTP POST. Returns false otherwise. if (is_uploaded_file($_FILES['image']['tmp_name'])) { //------------------------------- Get the Size of the File ------------------------------------------------- $size = $_FILES['image']['size']; //----------------Make sure that $size is less than 1MB (1000000 bytes)-------------------------------------- if ($size > $size_bytes) { echo "File Too Large. Please try again."; exit(); } //-------------- $filename will hold the value of the file name submitted from the form.---------------------- $filename = $_FILES['image']['name']; //--------------------- Check if file is Already EXISTS.------------------------------------------------------ if(file_exists($upload_dir.$filename)) { echo "The file named <b>$filename </b>already exists"; exit(); } //------------- Move the File to the Directory of your choice ----------------------------------------------- //--------------Move_filetoupload_file('filename','destination') Moves an filetoupload file to a new location. if (move_uploaded_file($_FILES['image']['tmp_name'],$upload_dir.$filename)) { // puts the filename in the image variable for use later $formVars["image"] = $_FILES['image']['name']; //-------------- Tell the user that the file has been filetoupload --------------------------------------------- // echo "File (<a href=$upload_dir$filename>$filename</a>) uploaded!"; // // exit(); } // else { // //----------------------------Print error ----------------------------------------------------------------------- echo "There was a problem moving your file"; exit(); } } //----------------- VALIDATION NOW FINISHED. CHECK IF THERE WERE ANY ERRORS --------------------- // if (!empty($errorString)) { ?> <!-------------------------------------------------------------- SHOW THE USER ERRORS --------------------------------------> <h1>Data Validation error!</h1> <?=$errorString?> <br> <!-------------------------------------------------- RETURN THE USER BACK TO THE FORM ----------------------------> <a href="index.php">Add Another Cabin</a> or <a href="../index.php">Return to the Stocklist</a> <!--------------------------------EXIT IF THERE IS AN ERROR IN THE CUSTOMER FORM --------------------------> <?php exit; } else { //--------------------------------------------------------------------- DATA IS VALID ------------------------------------------------- //--------------------------------- INSERT DATA FROM USER QUERY ------------------------------------------ $dateAdded = $formVars["dateAdded"]; $title = $formVars["title"]; $description = $formVars["description"]; $price = $formVars["price"]; $cabinRange = $formVars["cabinRange"]; $image = $formVars["image"]; $query = "INSERT INTO stocklist(dateAdded, title, description, price, cabinRange, image) VALUES ('$dateAdded', '$title', '$description', '$price', '$cabinRange', '$image')"; //------------------------------------------------- RUN THE QUERY ---------------------------------------------------------------- if (!(@ mysql_query ($query, $dbh))) showerror(); //---------------------------------------------------------- CLOSE THE CONNECTION -------------------------------------------- mysql_close($dbh); //----------------------------------------------------------- CONFIRM CUSTOMER QUERY -------------------------------------- if($query) { echo "<br /><br /><h2>Thank you!</h2> <br /><br />$title has been entered into the stocklist.<br /><br />\n"; } } ?> <a href="index.php">Add Another Cabin</a> or <a href="../index.php">Return to the stocklist</a> <?php require_once('../../footer.php'); ?> from what I've seen on other websites this code can be edited to create the edit/delete functions but I dont know how. Any ideas? Link to comment https://forums.phpfreaks.com/topic/47642-edit-delete/ Share on other sites More sharing options...
Merdok Posted April 20, 2007 Author Share Posted April 20, 2007 bump Link to comment https://forums.phpfreaks.com/topic/47642-edit-delete/#findComment-234136 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.