Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP/MySQL Image Issues

    I have a free listing website that includes an image.
    I have the code that inserts the text and then a seperate page that should upload an image and insert the URL into the database as an UPDATE.

    The code uploads the image, but doesn't add the url to the database.
    The message I recieve when testing it tells me that it has been uploaded and added to the database...which obviously it's not!

    Can anyone tell me what I'm missing here?

    Here is the code for the form...
    Code:
    <form method="post" action="addImage.php" enctype="multipart/form-data">
        <p>
        <table width="98%" border="0" cellspacing="4" cellpadding="0">
          <tr>
            <td colspan="2"><input name="id" type="hidden" />
            Please upload an image to compliment your listing in gif or jpeg format. The file name should be named after the with your company name. If the same file name is uploaded twice it will be overwritten! Maxium size of File is 35kb. </td>
          </tr>
          <tr>
            <td width="26%">Image:</td>
            <td width="74%"> <input type="hidden" name="size" value="350000">
                <input type="file" name="photo"></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td><label>
              <input type="submit" name="insert_email" id="insert_email" value="Submit Image" />
            </label></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
        </table>
        </form>
    Here is my PHP code...
    PHP Code:
    <?php

    //This is the directory where images will be saved
    $target "images/";
    $target $target basename$_FILES['photo']['name']);

    //This gets all the other information from the form
    $id=$_POST['id'];
    $image=($_FILES['photo']['name']);


    // Connects to your Database
    mysql_connect("10.8.11.72""CommBizGuide""Abcd1234") or die(mysql_error()) ;
    mysql_select_db("CommBizGuide") or die(mysql_error()) ;

    //Writes the information to the database
    mysql_query("UPDATE CommBizGuide (id, photo)
    VALUES ('$id','$image')"
    ) ;

    //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, there was a problem uploading your file.";
    }
    ?>
    Thanks in advance for your help!!!

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Try changing
    Code:
    mysql_query("UPDATE CommBizGuide (id, photo)
    VALUES ('$id','$image')") ;
    to
    Code:
    mysql_query("UPDATE CommBizGuide (id, photo)
    VALUES ('$id','$image')") or die(mysql_error()) ;
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,959
    Thanks
    2
    Thanked 304 Times in 296 Posts
    The syntax of your UPDATE query is not correct. Please check the manual or a good tutorial for the correct syntax - http://dev.mysql.com/doc/refman/5.0/en/update.html
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •