[SOLVED] Php/Mysql Image Problem

This is a discussion on "[SOLVED] Php/Mysql Image Problem" within the PHP Forum section. This forum, and the thread "[SOLVED] Php/Mysql Image Problem are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Oct 15th, 2007, 15:57
Reputable Member
Join Date: Oct 2007
Location: Liverpool UK
Age: 29
Posts: 216
Thanks: 0
Thanked 0 Times in 0 Posts
[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

PHP: Select all

<?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/xhtmlxml: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">&nbsp;</h1>
   <h1>&nbsp;</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 &amp; quality you insert into your profile, the more you enhance your chances of finding &quot;who&quot; your looking for, for &quot;what&quot; 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 &amp; 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;amp; Dont Get Caught Doing Anythink I Wouldnt Do &amp; He He</p>
                    <p>&nbsp;</p>
                    <input type="hidden" name="MM_insert" value="form1" />
</form>
                    <p>&nbsp;</p>
                  <p>&nbsp;</p></td>
                  <td width="210" valign="top"><table width="215" height="279" border="1" bordercolor="#FF00FF">
                    <tr>
                      <td>&nbsp;</td>
                    </tr>
                  </table></td>
                  <td width="201">&nbsp;</td>
                </tr>
              </table></td>
            </tr>
          </table></td>
        </tr>
      </table>
      <p>&nbsp;</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));
Reply With Quote

  #2 (permalink)  
Old Oct 15th, 2007, 16:22
simonb's Avatar
Blog Moderator

Join Date: Dec 2006
Location: Norwich
Posts: 675
Blog Entries: 4
Thanks: 4
Thanked 2 Times in 2 Posts
Send a message via Skype™ to simonb
Re: Php/Mysql Image Problem

IF you ask AlexGeek he did this for me a week a go.
Last Blog Entry: Whats your Niche? (Jun 10th, 2008)
Reply With Quote
  #3 (permalink)  
Old Oct 15th, 2007, 18:43
Reputable Member
Join Date: Oct 2007
Location: Liverpool UK
Age: 29
Posts: 216
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Php/Mysql Image Problem

AlexGeek? How do i contact him?
Reply With Quote
  #4 (permalink)  
Old Oct 15th, 2007, 20:04