Jump to content

kevwood

Members
  • Posts

    28
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

kevwood's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. i feel like taking a long walk off a short pier haha. why does it always end u being something so small haha. i have fixed that and updated the code so the insert is actually part of the upload script now. here is the updated script which is working fine now. <?php echo "<pre>"; echo "POST:"; print_r($_POST); echo "FILES:"; var_dump($_FILES); echo "</pre>"; $name = $_POST['name']; $desc = $_POST['description']; $price = $_POST['price']; $image = $_POST['image']; $prod_type = $_POST['prod_type']; $made = $_POST['made']; $dist = $_POST['distribute']; $servername = "xxxxxxxxxxxxxxxxx"; $db = "xxxxxxxxxxxxx"; $user_name = "xxxxxxxxxxx"; $password = "xxxxxxxxx"; $target_dir = "uploads/"; $target_file = $target_dir . basename($_FILES["image"]["name"]); $uploadOk = 1; $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); // Check if image file is a actual image or fake image if(isset($_POST["prod_sub"]) && isset($_FILES["image"])) { $check = getimagesize($_FILES["image"]["tmp_name"]); if($check !== false) { echo "File is an image - " . $check["mime"] . "."; $uploadOk = 1; } else { echo "File is not an image."; $uploadOk = 0; } } // Check if file already exists if (file_exists($target_file)) { echo "Sorry, file already exists."; $uploadOk = 0; } // Check file size if ($_FILES["image"]["size"] > 500000) { echo "Sorry, your file is too large."; $uploadOk = 0; } // Allow certain file formats if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) { echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "Sorry, your file was not uploaded."; // if everything is ok, try to upload file } else { if (move_uploaded_file($_FILES["image"]["tmp_name"], $target_file)) { echo "The file ". basename( $_FILES["image"]["name"]). " has been uploaded."; // create connection to db try { $conn = new PDO("mysql:host=$servername;dbname=$db", $user_name, $password); // PDO error mode set to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connected to database <br /> <br />"; } // Set veriable to catch error created catch(PDOException $error) { echo "Connection failed: <br /> <br />" . $error->getMessage(); } try{ $stmt = $conn->prepare("INSERT INTO Products(NAME, DESCRIPTION, PRICE, IMAGES, TYPE, MADE, DISTRIBUTE) VALUES (:name, :desc, :price, :image, :prod_type, :made, :dist)"); $stmt->bindParam(':name', $name); $stmt->bindParam(':desc', $desc); $stmt->bindParam(':price', $price); $stmt->bindParam(':image', $target_file); $stmt->bindParam(':prod_type', $prod_type); $stmt->bindParam(':made', $made); $stmt->bindParam(':dist', $dist); $stmt->execute(); $conn->exec($sql); echo "New record added"; } catch(PDOException $error) { echo $sql . "<br />" . $error->getMessage(); } } else { echo "Sorry, there was an error uploading your file."; } } ?> thanks for the help on this.
  2. I have created to parts of code that work independently of each other but when i try combine them the upload part stops working! here is my html form code <!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=utf-8" /> <title>Sonc Hydro -Mammoth Pro Tents</title> <link rel="stylesheet" type="text/css" href="css/main_styles.css" /> <link rel="stylesheet" type="text/css" href="css/main_layout.css" /> <script type="text/javascript" src="scripts/image.js"></script> </head> <body bgcolor="#4d6821" onLoad="switchImage('slideImg')"> <div id="admin_container"> <div id="admin_body"> <h1>Upload Page</h1> <div class="admin_select"> <h2>Pleas select which action to take</h2> <form id="selection"> <select onchange="window.open(this.options[this.selectedIndex].value,'_top')"> <option>Please Select..</option> <option value="test_add.php">Add Prod</option> <option value="test_edit.php">Edit Prod</option> <option value="test_del.php">Delete Prod</option> </select> </form> </div> <div class="admin_select"> <form id="prod" action="insert3.php" method="post" enctype="multipart/form-data"> Name:<br /> <input type="text" name="name" id="name" /> <br /> <br /> Desctiption:<br /> <textarea id="description" name="description" rows="25" cols="100"></textarea> <br /> <br /> Price: (do not put £ symbol in)<br /> <input type="text" name="price" id="price" /> <br /> <br /> Image: <input type="file" name"image" id="image" /> <br /> <br /> Type: <select id="prod_type" name="prod_type" > <option value="lighting">Lighting</option> <option value="systems">Systems</option> <option value="filters/fans">Filters/Fans</option> <option value="tents">Tents</option> <option value="nutrient">Nutrient</option> <option value="sheeting">Sheeting</option> <option value="accessories">Accessories</option> </select> <br /> <br /> Made by:<br /> <input type="text" name="made" id="made" /> <br /> <br /> Distributed by:<br /> <input type="text" name="distribute" id="distribute" /> <br /> <br /> <input type="submit" name="prod_sub" id="prod_sub" value="add to DB" /> </form> </div> </div> </div> </body> </html> and here is the php script insert3.php <?php $name = $_POST['name']; $desc = $_POST['description']; $price = $_POST['price']; $prod_type = $_POST['prod_type']; $made = $_POST['made']; $dist = $_POST['distribute']; $servername = "xxxxxxxxxx"; $db = "xxxxxxxxxxx"; $user_name = "xxxxxxxxxx"; $password = "xxxxxxxxx"; $target_dir = "uploads/"; $target_file = $target_dir . basename($_FILES["image"]["name"]); $uploadOk = 1; $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); // Check if image file is a actual image or fake image if(isset($_POST["prod_sub"]) && isset($_FILES["image"])) { $check = getimagesize($_FILES["image"]["tmp_name"]); if($check !== false) { echo "File is an image - " . $check["mime"] . "."; $uploadOk = 1; } else { echo "File is not an image."; $uploadOk = 0; } } // Check if file already exists if (file_exists($target_file)) { echo "Sorry, file already exists."; $uploadOk = 0; } // Check file size if ($_FILES["image"]["size"] > 500000) { echo "Sorry, your file is too large."; $uploadOk = 0; } // Allow certain file formats if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) { echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "Sorry, your file was not uploaded."; // if everything is ok, try to upload file } else { if (move_uploaded_file($_FILES["image"]["tmp_name"], $target_file)) { echo "The file ". basename( $_FILES["image"]["name"]). " has been uploaded."; } else { echo "Sorry, there was an error uploading your file."; } } // create connection to db try { $conn = new PDO("mysql:host=$servername;dbname=$db", $user_name, $password); // PDO error mode set to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connected to database <br /> <br />"; } // Set veriable to catch error created catch(PDOException $error) { echo "Connection failed: <br /> <br />" . $error->getMessage(); } try{ $stmt = $conn->prepare("INSERT INTO Products(NAME, DESCRIPTION, PRICE, IMAGES, TYPE, MADE, DISTRIBUTE) VALUES (:name, :desc, :price, :image, :prod_type, :made, :dist)"); $stmt->bindParam(':name', $name); $stmt->bindParam(':desc', $desc); $stmt->bindParam(':price', $price); $stmt->bindParam(':image', $target_file); $stmt->bindParam(':prod_type', $prod_type); $stmt->bindParam(':made', $made); $stmt->bindParam(':dist', $dist); $stmt->execute(); $conn->exec($sql); echo "New record added"; } catch(PDOException $error) { echo $sql . "<br />" . $error->getMessage(); } ?> as i mentioned if i take the code out for the file upload it works fine (apart from storing the image how i want) and the upload script works fine to upload an image but they do to work together. the information is added to the db but the file is not uploaded and every echo message i have is displayed. any other information need please ask, i can give you a link to the testing site if needed.
  3. thanks for the replies, i thought the prepare was a function or predefined statement within mysql lol. it has been a long time since i messed about with any of this. who do i give the best answer to haha.
  4. Hello all, I am trying to setup parameterised queries to prevent sql injection from a html from when adding data to my database. I have been doing some reading on W3schools website about it. the code i have been looking at i tried to combine with my request to insert but with no joy. here is the code i was looking at $stmt = $dbh->prepare("INSERT INTO Customers (CustomerName,Address,City) VALUES (:nam, :add, :cit)"); $stmt->bindParam(':nam', $txtNam); $stmt->bindParam(':add', $txtAdd); $stmt->bindParam(':cit', $txtCit); $stmt->execute(); and here is the code i have created from the code i was looking above <?php $name = $_POST['name']; $desc = $_POST['description']; $price = $_POST['price']; $image = $_POST['image']; $prod_type = $_POST['prod_type']; $made = $_POST['made']; $dist = $_POST['distribute']; $servername = "mysql5.000webhost.com"; $db = "a6382499_product"; $user_name = "a6382499_sonic"; $password = "phpfreaks1"; global $conn; // create connection to db try { $conn = new PDO("mysql:host=$servername;$db", $user_name, $password); // PDO error mode set to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connected to database"; } // Set veriable to catch error created catch(PDOException $error) { echo "Connection failed: " . $error->getMessage(); } try{ $stmt = $db->prepare("INSERT INTO Products(NAME, DESCRIPTION, PRICE, IMAGE, TYPE, MADE, DISTRIBUTE) VALUES (:name, :desc, :price, :image, :prod_type, :made, :dist)"); $stmt->bindParam(':name', $name); $stmt->bindParam(':desc', $desc); $stmt->bindParam(':price', $price); $stmt->bindParam(':image', $image); $stmt->bindParam(':prod_type', $prod_type); $stmt->bindParam(':made', $made); $stmt->bindParam(':dist', $dist); $stmt->exec(); $conn->exec($sql); echo "New record added"; } catch(PDOException $error) { echo $sql . "<br />" . $error->getMessage(); } ?> the error message i am getting is and line 32 in the code is $stmt = $db->prepare("INSERT INTO Products(NAME, DESCRIPTION, PRICE, IMAGE, TYPE, MADE, DISTRIBUTE) any help would be much appreciated.
  5. thanks for the reply, i have found something that i may be able to manipulate how i would like. i will see how i go with this, i will no doubt be on looking for help depending how much comes back to me lol. a lot has changed in 7 years!!
  6. yeah i would rather learn it (again lol) rather than just ask for the script
  7. a few years ago i created a script that upload images to the file directory and stored the file location in a mysql db. i cannot find this script anywhere and it really annoying me haha. i know this script would be useless now due to the changes with the code but it would have at least been a starter for me. what i am looking for is a link to a good tutorial that will aid me in building this, i understand it may be a case of doing two different ones and combing. all i have searched for up to now is not bringing anything of use up really. just looking for a good base start to work from, any help at all would be greatly appreciated.
  8. it was a problem with the server name, i had to specify the name of the server my db was being held on. is this simply because it is a free hosting site and my site and database are being held on different servers?
  9. i have checked the user name and password a number of times and even changed the password to phpfreaks1 while i was uploading it on here for security reasons even though it only for testing anyway.
  10. thanks for the reply. i have updated my code with this (this is the PDO correct way i think, please correct me if i am wrong). // create connection to db try { $conn = new PDO("mysql:host=$servername;$db", $user_name, $password); // PDO error mode set to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connected to database"; } // Set veriable to catch error created catch(PDOException $error) { echo "Connection failed: " . $error->getMessage(); } and i am getting this message my password and user name are 100% correct i have re entered them and updated them a few times to make sure of this
  11. Hello all, Been a while since i have been on here since he lack of using my degree lol. but i am dusting the cob webs of the brain an realising it has all drastically changed since i last used php and mysql. any enough with the blabbing here is my problem! i am trying to establish a connection with a database i have set up on a free hosting server. when i run the code i am getting conflicting messages. here is my code <?php $name = "name"; $desc = "description"; $price = "price"; $image = "image"; $prod_type = "prod_type"; $made = "made"; $dist = "distribute"; $server = "localhost"; $db = "a6382499_product"; $user_name = "a6382499_sonic"; $password = "phpfreaks1"; // create connection to db $conn = new MySQLi($server, $user_name, $password); // check connection if (!$conn->connect_error) { die("Connection failed: " . $conn->connect_error()); } echo "Connect successful"; ?> it is giving me this error message when i run the code but then i am getting the message that i am connected to the db successfully . any help with this would be great.
  12. i have been playing with the code some more and now have managed to get everything to sit virtually on top of each of. i think i am having problems with using the code i have written as the container div i load the three sections of information into is a class and reused to load further bits of information into down the page. i am trying to build it so it has fluidity to the design so the panel which holds the information can stretch to fit the available space between the div's i have floated left and right (which i am struggling to achieve at the min). but firstly i want to just get the look of the panel worked out. this is what my code looks like now .body_panel{ position:relative; overflow:visible; background-color : #FFF; border : solid #45bf55; border-width : 3px; margin-bottom:30px; } .body_img{ position : absolute; width : 200px; height : 200px; background-color : #e0e0e0; text-align : center; display : table-cell; vertical-align : middle; margin-right : 25px; } .body_text{ position:absolute; left:25%; width : 230px; } .body_link{ position : absolute; right : 0; margin-right : 3px; padding-top : 90px; } it is just sitting all the individual panels on top of each starting the top of the next panel 30px down from the last. at least my images are now centered to the img div lol.
  13. ok so my code now looks like this .body_panel{ overflow : hidden; width : auto; background-color : #FFF; border : solid #45bf55; border-width : 3px; margin-bottom:30px; } .body_text{ position:relative; top:0; left:200px; width : 230px; } .body_img{ position : relative; width : 200px; height : 200px; background-color : #e0e0e0; text-align : center; display : table-cell; vertical-align : middle; margin-right : 25px; padding-top : 10px; } .body_link{ float : right; margin-right : 3px; padding-top : 90px; } i have got my image to appear in the center of the div now but i cannot get my other two divs sit next to them now. i need the body_img, the body_text then the body link to now appear all next to each other but they are now all underneath each other. would i need to set a width on the body panel and not set it to auto? the reason i set it to auto was to try to get it to fill the space in the middle of the page. ideally the body panel would stretch to fit the gap between the left and right divs on the page with a margin of 30 px between each side. One problem at a time though. so how do i go about getting the divs to sit how i need them to now. i have tried floating to the right but had no joy and tried to set the relative position with a left margin of 200px but it still just placed it underneath the image but to the right and most of the text is not visible.
  14. so from what i have read i would need to use a relative positioned div then have an absolute div placed in the center of the second div to load the image into this. would this not just give the same problem though as the images that are being loaded in are of different sizes. at the min i have it set up with a container div holding three separate div to hold the information. i have floated the first to divs left and the the third right. i am just loading the images into the first div. if i now set the first div to be relative to the container div it would then sit it in the top left corner of the container. i would then need to position the next div to be absolute and give it some margins from the top and left to move this towards the center. i will try this code out now (or something similar) #container_panel { position : relative; } #img_panel { position : absolute; top : 20px; left : 20px; width : 200px; } #text_panel{ float : right; } #link_panel{ float : right; }
×
×
  • 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.