|
|
 |
October 15th, 2007, 11:57 AM
|
#1
|
|
Reputable Member
Join Date: Oct 2007
Location: Liverpool UK
Age: 30
Posts: 247
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
[SOLVED] Php/Mysql Image Problem
Hello!
I recently created a form that succesfully sends data input into it directly into a mysql database, everythink is working fine except one part.
The first option in my form allows the user to browse & upload a photo, i have set this feature up so the photo goes into the images folder located on the webserver to save clogging up the database, and the name of the photo is supposed to upload into the mysql database with the rest of the forms fields. My problem is that when i submit the forms input data the image goes successfully to the images folder, but the name of the image is not transfered to the database. I no its possible to perform this action because i posted my solution up here on request for someone else, i have had it working before, just seem to be having problems with my new form.
Cheers.
Heres my code, warning its alot
Code:
<?php require_once('Connections/dbprofile.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO tbl_customer_data (photo, name, age, sex, sexual_orientation, area, postcode, sexual_interests, who_id_like_to_meet, about_me, what_i_look_like, contact_email_address) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['photo'], "text"), GetSQLValueString($_POST['name'], "text"), GetSQLValueString($_POST['age'], "text"), GetSQLValueString($_POST['sex'], "text"), GetSQLValueString($_POST['sexual_orientation'], "text"), GetSQLValueString($_POST['area'], "text"), GetSQLValueString($_POST['postcode'], "text"), GetSQLValueString($_POST['sexual_interests'], "text"), GetSQLValueString($_POST['who_id_like_to_meet'], "text"), GetSQLValueString($_POST['about_me'], "text"), GetSQLValueString($_POST['what_i_look_like'], "text"), GetSQLValueString($_POST['contact_email_address'], "text")); mysql_select_db($database_dbprofile, $dbprofile); $Result1 = mysql_query($insertSQL, $dbprofile) or die(mysql_error()); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Instant Messiging Chat</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="css/1.css" type="text/css" media="screen,projection" /> <script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script> <style type="text/css"> <!-- .style1 {color: #FF33CC} --> </style> </head> <body> <div id="header"> <h1 class="right"> </h1> <h1> </h1> </div> <ul id="nav"> <li class="right"><input value="Search..." type="text" /></li> <li><a href="MainPage.php">Main Page</a></li> <li><a href="Login.php">LogIn</a></li> <li><a href="admin/Sign Up.php">SignUp</a></li> <li><a href="Contact.php">Contact</a></li> </ul> <div class="clear" /> <div id="sidebar"> <h2>Latest News or Comments</h2> <p class="news"><a href="#" class="more">Read More »</a> </p> <p class="news"><a href="#" class="more">Read More »</a> </p> <p class="news"><a href="#" class="more">Read More »</a> </p> <h2>Quick Links</h2> <ul> <li><a href="index.php">Introduction</a></li> <li><a href="AboutUs.php">About Us</a></li> <li><a href="admin/Sign Up.php">SignUp</a></li> <li><a href="MainPage.php">Main Page</a></li> </ul> <h2>Search</h2> <input name="" type="text" value="Search..." /> </div> <div id="content"> <h2><a href="#" id="intro"><u>Please Create Your Profile</u></a></h2> <p>Here you can create your profile for use with our site. The more effort & quality you insert into your profile, the more you enhance your chances of finding "who" your looking for, for "what" your looking for!</p> <p>Good luck! And remember this is your part of the site, so keep it up to date and accurate to ensure success in your naughty adventures.</p> <table width="847" height="714" border="0"> <tr> <td valign="top"><table width="842" height="709" border="1" bordercolor="#FF00FF"> <tr> <td height="87"><div align="center"> <script type="text/javascript"> AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','672','height','79','src','Create Profile animation 1/SWFAnimation1','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','Create Profile animation 1/SWFAnimation1' ); //end AC code </script> <noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="672" height="79"> <param name="movie" value="Create Profile animation 1/SWFAnimation1.swf" /> <param name="quality" value="high" /> <embed src="Create Profile animation 1/SWFAnimation1.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="672" height="79"></embed> </object> </noscript></div></td> </tr> <tr> <td valign="top"><table width="833" border="0"> <tr> <td width="400" height="612" valign="top"> <form name="form1" action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" id="form1"> <p class="style1">Please Upload A Recent Photo Of Yourself</p> <p> <label> <span class="style1">Photo:</span> <input type="file" name="photo"><br> </label> </p> <p> <label></label> </p> <p class="style1">Please Insert Your Name</p> <p> <label> <input type="text" name="name" id="name" /> </label> </p> <p class="style1">Please Insert Your Age</p> <p> <label> <select name="age" id="age"> <option>18</option> <option>19</option> <option>20</option> <option>21</option> <option>22</option> <option>23</option> <option>24</option> <option>25</option> <option>26</option> <option>27</option> <option>28</option> <option>29</option> <option>30</option> <option>31</option> <option>32</option> <option>33</option> <option>34</option> <option>35</option> <option>36</option> <option>37</option> <option>38</option> <option>39</option> <option>40</option> <option>41</option> <option>42</option> <option>43</option> <option>44</option> <option>45</option> <option>46</option> <option>47</option> <option>48</option> <option>49</option> <option>50</option> <option>51</option> <option>52</option> <option>53</option> <option>54</option> <option>55</option> <option>56</option> <option>57</option> <option>58</option> <option>59</option> <option>60</option> <option>61</option> <option>62</option> <option>63</option> <option>64</option> <option>65</option> <option>66</option> <option>67</option> <option>68</option> <option>69</option> <option>70</option> <option>71</option> <option>72</option> <option>73</option> <option>74</option> <option>75</option> <option>76</option> <option>77</option> <option>78</option> <option>79</option> <option>80</option> <option>81</option> <option>82</option> <option>83</option> <option>84</option> <option>85</option> <option>86</option> <option>87</option> </select> </label> </p> <p class="style1">Please Input Your Sex</p> <p> <label> <select name="sex" id="sex"> <option>Male</option> <option>Female</option> <option>Trans Male</option> <option>Trans Female</option> </select> </label> </p> <p class="style1">Please Insert Your Sexual Orientation</p> <p> <label> <select name="sexual_orientation" id="sexual_orientation"> <option>Straight Male</option> <option>Straight Female</option> <option>Bi Male</option> <option>Bi Female</option> <option>Gay Male</option> <option>Gay Female</option> </select> </label> </p> <p class="style1">Please Insert Your Area</p> <p> <label> <select name="area" id="area"> <option>England-Bath Avon</option> <option>England-Bedforshire</option> <option>England-Berkshire</option> <option>England-Brighton</option> <option>England-Bristol</option> <option>England-Buckinghamshire</option> <option>England-Cambridgeshire</option> <option>England-Channel Isles</option> <option>England-Cheshire</option> <option>England-Cornwall</option> <option>England-County Durham</option> <option>England-Cumbria</option> <option>England-Derbyshire</option> <option>England-Devon</option> <option>England-Dorset</option> <option>England-Essex</option> <option>England-Gloucestershire</option> <option>England-Hampshire</option> <option>England-Herefordshire</option> <option>England-Huntingdonshire</option> <option>England-Isle Of White</option> <option>England-Isle Of Sily</option> <option>England-Kent</option> <option>England-Lancashire</option> <option>England-Leicestershire</option> <option>England-Lincolnshire</option> <option>England-London</option> <option>England-Manchester</option> <option>England-Merseyside</option> <option>England-Middlesex</option> <option>England-Norfolk</option> <option>England-Northamptonshire</option> <option>England-Northumberland</option> <option>England-Nottinghamshire</option> <option>England-Oxfordshire</option> <option>England-Rutland</option> <option>England-Shropshire</option> <option>England-Somerset</option> <option>England-Staffordshire</option> <option>England-Suffolk</option> <option>England-Surrey</option> <option>England-Sussex</option> <option>England-Tyne & Wear</option> <option>England-Warwickshire</option> <option>England-West midlands</option> <option>England-Westmorland</option> <option>England-Wiltshire</option> <option>England-Worcestershire</option> <option>England-Yorkshire</option> <option>Isle Of Man</option> <option>N Ireland-Artrim</option> <option>N Ireland-Amagh</option> <option>N Ireland-Bellfast</option> <option>N Ireland-Down</option> <option>N-Ireland-Femanagh</option> <option>N-Ireland-Londondery</option> <option>N-Ireland-Tyrone</option> <option>Scotland-Aberdeenshire</option> <option>Scotland-Angus</option> <option>Scotland-Argylshire</option> <option>Scotland-Ayrshire</option> <option>Scotland-Banffshire</option> <option>Scotland-Berwicshire</option> <option>Scotland-Buteshire</option> <option>Scotland-Caithness</option> <option>Scotland-Clackmannanshire</option> <option>Scotland-Dumfriesshire</option> <option>Scotland-Dundee city</option> <option>Scotland-Edinburgh</option> <option>Scotland-Falkirk</option> <option>Scotland-Fife</option> <option>Scotland-Highland</option> <option>Scotland-Inverness-shire</option> <option>Scotland-Isle of Islay</option> <option>Scotland-Isle of Lewis</option> <option>Scotland-Isle of Skye</option> <option>Scotland-Kincarineshire</option> <option>Scotland-Kinross-shire</option> <option>Scotland-Kirkcudbrightshire</option> <option>Scotland-Lanarkshire</option> <option>Scotland-Midlothian</option> <option>Scotland-Morayshire</option> <option>Scotland-Naimshire</option> <option>Scotland-Orkney</option> <option>Scotland-Peeblesshire</option> <option>Scotland-Perthshire</option> <option>Scotland-Renfrewshire</option> <option>Scotland-Ross-shire</option> <option>Scotland-Roxburghshire</option> <option>Scotland-Selkirkshire</option> <option>Scotland-Shetland</option> <option>Scotland-Sterlingshire</option> <option>Scotland-Sutherland</option> <option>Scotland-West Lothiann</option> <option>Scotland-Western Isles</option> <option>Scotland-Wigtownshire</option> <option>Wales-Anglesey</option> <option>Wales-Brecknockshire</option> <option>Wales-Caemarfonshire</option> <option>Wales-Cardiff</option> <option>Wales-Cardiganshire</option> <option>Wales-Carmarthenshire</option> <option>Wales-Ceredigion</option> <option>Wales-Denbighshire</option> <option>Wales-Flintshire</option> <option>Wales-Glamorgan</option> <option>Wales-Gwynedd</option> <option>Wales-Merioneth</option> <option>Wales-Monmouthshire</option> <option>Wales-Montgomeryshire</option> <option>Wales-Newport</option> <option>Wales-Pembrokeshire</option> <option>Wales-Radnorshire</option> <option>Wales-Swansea</option> </select> </label> </p> <p class="style1">Please Insert Your Postcode (Capitals Only)</p> <p> <label> <input type="text" name="postcode" id="postcode" /> </label> </p> <p class="style1">Please Input Your Sexual Interests</p> <p> <label> <select name="sexual_interests" id="sexual_interests"> <option>1 on 1 Sexual Discreet Partner</option> <option>Group Sex</option> <option>Gay Male</option> <option>Gay Female</option> <option>Bi Male</option> <option>Bi Female</option> <option>Couples</option> <option>Transvestite</option> <option>BDSM\Fetish</option> </select> </label> </p> <p class="style1">Please Input Who You Would Like To Meet</p> <p> <label> <textarea name="who_id_like_to_meet" id="who_id_like_to_meet" cols="45" rows="5"></textarea> </label> </p> <p class="style1">Please Tell Us About Yourself</p> <p> <label> <textarea name="about_me" id="about_me" cols="45" rows="5"></textarea> </label> </p> <p class="style1">Please Describe What You Look LIke</p> <p> <label> <textarea name="what_i_look_like" id="what_i_look_like" cols="45" rows="5"></textarea> </label> </p> <p class="style1">Please Input A Discreet Email Address For Other members To Contact You About Your Naughty Interests</p> <p> <label> <input type="text" name="contact_email_address" id="contact_email_address" /> </label> </p> <p> <label> <input type="submit" name="submit" id="submit" value="Submit" /> </label> </p> <p class="style1">Remember Keep Your Emails Private &amp; Dont Get Caught Doing Anythink I Wouldnt Do & He He</p> <p> </p> <input type="hidden" name="MM_insert" value="form1" /> </form> <p> </p> <p> </p></td> <td width="210" valign="top"><table width="215" height="279" border="1" bordercolor="#FF00FF"> <tr> <td> </td> </tr> </table></td> <td width="201"> </td> </tr> </table></td> </tr> </table></td> </tr> </table> <p> </p> </div> <div id="footer"> <?php
$target = "images2/"; $target = $target . basename( $_FILES['photo']['name']); $pic=($_FILES['photo']['name']);
mysql_connect("localhost", "root", "longstand") or die(mysql_error()) ; mysql_select_db("dbprofile") or die(mysql_error()) ;
mysql_query("INSERT INTO `tbl_customer_data` VALUES ('$name', '$pic')") ;
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; } else {
echo "Sorry Andy There Was A Problem Uploading The File."; } ?> <?php $con = mysql_connect("localhost","root","longstand"); if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("dbprofile", $con);
echo $_POST[name]; echo "<br />"; echo $_POST[age]; echo "<br />"; echo $_POST[sex]; echo "<br />"; echo $_POST[sexual_orientation]; echo "<br />"; echo $_POST[area]; echo "<br />"; echo $_POST[postcode]; echo "<br />"; echo $_POST[sexual_interests]; echo "<br />"; echo $_POST[who_id_like_to_meet]; echo "<br />"; echo $_POST[about_me]; echo "<br />"; echo $_POST[what_i_look_like]; echo "<br />"; echo $_POST[contact_email_address]; echo "<br />"; $sql="INSERT INTO tbl_customer_data (name, age, sex, sexual_orientation, area, postcode, sexual_interests, who_id_like_to_meet, about_me, what_i_look_like, contact_email_address) VALUES ('$_POST[name]','$_POST[age]'.'$_POST[sex]','$_POST[sexual_orientation]','$_POST[area]','$_POST[postcode]','$_POST[sexual_interests]','$_POST[who_id_like_to_meet]','$_POST[about_me]','$_POST[what_i_look_like]','$_POST[contact_email_address]')";
if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } mysql_close($con); ?> <p>Site Design by <a href="">AJL Online Services Business Developement Specialists</a>.<br /> <!-- you can delete below here --> © All copyrights reserved.</p> </div> </body> </html>
Heres what my database looks like:
CREATE DATABASE IF NOT EXISTS dbprofile;
USE dbprofile;
CREATE TABLE tbl_customer_data (photo VARCHAR(30), name VARCHAR(25), age VARCHAR(4), sex VARCHAR(30), sexual_orientation VARCHAR(40), area VARCHAR(50), postcode VARCHAR(20), sexual_interests VARCHAR(150), who_id_like_to_meet VARCHAR(1000), about_me VARCHAR(1000), what_i_look_like VARCHAR(1000), contact_email_address VARCHAR(40));
|
|
|
October 15th, 2007, 12:22 PM
|
#2
|
|
Highly Reputable Member
Join Date: Dec 2006
Location: Norwich
Posts: 731
Thanks: 6
Thanked 2 Times in 2 Posts
Rep Altering Power: 0
|
Re: Php/Mysql Image Problem
IF you ask AlexGeek he did this for me a week a go.
|
|
|
October 15th, 2007, 02:43 PM
|
#3
|
|
Reputable Member
Join Date: Oct 2007
Location: Liverpool UK
Age: 30
Posts: 247
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
Re: Php/Mysql Image Problem
AlexGeek? How do i contact him?
|
|
|
October 15th, 2007, 04:04 PM
|
#4
|
|
Reputable Member
Join Date: Apr 2007
Location: Scotland
Age: 18
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
Re: Php/Mysql Image Problem
Don't worry.
He's never far away 
|
|
|
October 15th, 2007, 04:08 PM
|
#5
|
|
Elite Veteran
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 16
Posts: 3,802
Thanks: 2
Thanked 3 Times in 3 Posts
|
Re: Php/Mysql Image Problem
Hello Longstand,
Everyone seems to think I can help you!
But I don't really understand some parts are trying to do,
such as the editformaction etc. And I won't be able to understand without reading all of your scripts I'm sure.
To me it seems overcomplicated for something so simple.
Maybe Rakuli can help! Sorry.
|
|
|
October 15th, 2007, 05:41 PM
|
#6
|
|
Highly Reputable Member
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
Re: Php/Mysql Image Problem
I have done this and it's not that difficult. If you have got the image to upload, that is the bit that people have problems with so you are most of the way there.
What you have does look overly complicated. I have had a closer look at you code and $name has no value and i won't swear to it but I use this as a SQL insert query
Code:
$query = "INSERT INTO image VALUES ('','$pic','$pic','$gallery')"; mysql_query($query);
You really need to escape all user input and not trust anything the user enters into the form becuase you could get a malicious user take control of your database (called SQL injection attacks). Do what i showed you the other day and use mysql_real_escape_string on all your POST variables.
My upload script
Code:
<?php $idir = "../images/gallery/full/"; // Path To Images Directory $tdir = "../images/gallery/thumbs/"; // Path To Thumbnails Directory $twidth = "100"; // Maximum Width For Thumbnail Images $theight = "75"; // Maximum Height For Thumbnail Images $pic=($_FILES['imagefile']['name']); $gallery = $_POST['gallery']; if (!isset($_POST['gallery'])) { ?> <fieldset> <legend><b>Image Gallery Upload</b></legend> <form enctype="multipart/form-data" action="<? $_SERVER['PHP_SELF']; ?>" method="post"> <p style="margin-left:10px;">Gallery to upload to:<br /> <select name="gallery" size="1"> <option value="jack">Jack</option> <option value="honeylands">Honeylands</option> <option value="events">Events</option> <option value="art">Art Auction</option> </select> <p style="margin-left:10px;">Image to upload:<br /> <input type="file" name="imagefile" style="width:450px" /><br /> <P><input type="submit" name="submit" value="Upload Image" class="submit-button" style="margin-left:10px;" /></p> </form> </fieldset><br /> <?} else { // Uploading/Resizing Script $url = $_FILES['imagefile']['name']; // Set $url To Equal The Filename For Later Use if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") { $file_ext = strrchr($_FILES['imagefile']['name'], '.'); // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php $copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . $_FILES['imagefile']['name']); // Move Image From Temporary Location To Permanent Location if ($copy) { // If The Script Was Able To Copy The Image To It's Permanent Location print 'Image uploaded successfully.<br />'; // Was Able To Successfully Upload Image //insert the image names into the database include_once "../includes/connection.php"; $query = "INSERT INTO image VALUES ('','$pic','$pic','$gallery')"; mysql_query($query); mysql_close(); $simg = imagecreatefromjpeg("$idir" . $url); // Make A New Temporary Image To Create The Thumbanil From $currwidth = imagesx($simg); // Current Image Width $currheight = imagesy($simg); // Current Image Height if ($currheight > $currwidth) { // If Height Is Greater Than Width $zoom = $twidth / $currheight; // Length Ratio For Width $newheight = $theight; // Height Is Equal To Max Height $newwidth = $currwidth * $zoom; // Creates The New Width } else { // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height) $zoom = $twidth / $currwidth; // Length Ratio For Height $newwidth = $twidth; // Width Is Equal To Max Width $newheight = $currheight * $zoom; // Creates The New Height } $dimg = imagecreate($newwidth, $newheight); // Make New Image For Thumbnail imagetruecolortopalette($simg, false, 256); // Create New Color Pallete $palsize = ImageColorsTotal($simg); for ($i = 0; $i < $palsize; $i++) { // Counting Colors In The Image $colors = ImageColorsForIndex($simg, $i); // Number Of Colors Used ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']); // Tell The Server What Colors This Image Will Use } imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight); // Copy Resized Image To The New Image (So We Can Save It) imagejpeg($dimg, "$tdir" . $url); // Saving The Image imagedestroy($simg); // Destroying The Temporary Image imagedestroy($dimg); // Destroying The Other Temporary Image print 'Image thumbnail created successfully.'; // Resize successful } else { print '<font color="#FF0000">ERROR: Unable to upload image.</font>'; // Error Message If Upload Failed } } ?>
|
|
|
October 17th, 2007, 01:27 PM
|
#7
|
|
Elite Veteran
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 16
Posts: 3,802
Thanks: 2
Thanked 3 Times in 3 Posts
|
Re: Php/Mysql Image Problem
He has it working now
The code he used was:
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>Untitled Document</title> </head> <body> <form enctype="multipart/form-data" action="add.php" method="POST"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name = "email"><br> Phone: <input type="text" name = "phone"><br> Photo: <input type="file" name="photo"><br> <input type="submit" value="Add"> </form> </body> <?php //This is the directory where images will be saved $target = "http://www.webforumz.com/images/"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $name=$_POST['name']; $email=$_POST['email']; $phone=$_POST['phone']; $pic=($_FILES['photo']['name']); // Connects to your Database mysql_connect("localhost", "root", "longstand") or die(mysql_error()) ; mysql_select_db("dblearn") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$pic')") ; //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry Andy There Was A Problem Uploading The File."; } ?> </html>
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|