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 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2010
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 Posts

    image path name problem

    I am trying to write the image path to a database, but why is it the path name on the database is different from the path name on the folder where the actual image is stored? And why the path on the database does not concat the .jpg.

    add_data.php
    PHP Code:

    mysql_query
    ("insert room set roomnumber='$room_number'");
     
    if (
    is_uploaded_file($_FILES['photos']['tmp_name']))
     {
        
    $newname uniqid("whc").".jpg";
    move_uploaded_file($_FILES['photos']['tmp_name'],
    "photos/bal/$newname");
    mysql_query("update room SET image_link='photos/bal/$newname'  WHERE roomnumber='" $_POST['room_number'] . "'  "
        or die(
    mysql_error()); 

     } 
    html
    Code:
    <FORM NAME="myform" enctype="multipart/form-data"  ACTION="add_data.php" METHOD="post">
    <INPUT TYPE="text" NAME="room_number" VALUE="">
    <input type="file" name="photos">
    <input type="submit" name="submit">
    </form>

  • #2
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    try to change this part
    PHP Code:
    move_uploaded_file($_FILES['photos']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . "/photos/bal/$newname");
    mysql_query("update room SET image_link='/photos/bal/$newname'  WHERE roomnumber='" $_POST['room_number'] . "'  "


  •  

    Posting Permissions

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