www.webdeveloper.com
Results 1 to 3 of 3

Thread: PHP image upload

Hybrid View

  1. #1
    Join Date
    Mar 2013
    Location
    Winnipeg, Canada
    Posts
    12

    PHP image upload

    Hi everyone, I am new here and new to php. I am working on a form with a image upload. I have to upload the image to the image folder and then write the image name to a mysql database. I am able to upload the image but I am unable to write the image name to the database.

    PHP:
    <?php include("db_connect.php");?>
    <?php // select the database in which to add a table
    mysql_select_db("final_exam_db",$con);



    $sql ="INSERT INTO drivers_0115061 (ln,fn,month,day,year,img,email)
    VALUES ('".$_POST["ln"]."',
    '".$_POST["fn"]."',
    '".$_POST["month"]."',
    '".$_POST["day"]."',
    '".$_POST["year"]."',
    '".$_POST['img']['img']."',
    '".$_POST["email"]."'
    )";

    //$sql="INSERT INTO people (fn,ln,dob,city,prov,pc,gender,hc,nod) VALUES ('steve','douglas',1234567,'winnipeg','manitoba','r3p 6g5','m','grey',2)";

    //echo $sql;


    mysql_query($sql, $con);
    echo mysql_error();
    ?>

    <?php
    $target_folder="images/";
    $target_file=$target_folder.basename($_FILES["img"]["img"]);
    // if(move_uploaded_file($_FILES["img"]["tmp_name"],$target_file))
    // {
    // echo "It Worked!";
    // echo "<a href='".$target_file."'target='_blank'/>".$target_file."</a>";
    // }
    // else
    // {
    // echo "Crap No Go!";
    // }
    ?>

    <?php include("db_close.php");?>

    html form (snippet):
    <td>
    Picture
    </td>
    <td>
    <input type="hidden" name="MAX_FILE_SIZE" value="10000000"/>
    <input type="file" id="img" name="img"/>
    </td>


    If anyone can help me out I would be forever grateful.

    Thanks in advance,
    Vince

  2. #2
    Join Date
    Mar 2013
    Location
    Denmark
    Posts
    14
    Hello Vince.
    You could try inserting values without the "post" since it might affect something without being sure
    you could try something like this:
    Code:
    $ln = $_POST['ln'];
    $sql = "INSERT INTO drivers_0115061 VALUES ($ln, '$fn', '$month', '$day', '$year', '$img' '$email')";
    Hope it helps

  3. #3
    Join Date
    Mar 2013
    Location
    Winnipeg, Canada
    Posts
    12
    I tried it and nothing worked. I also noticed that the image no longer uploads to the images folder. One other question. When I look at the database table it seems to be skipping record rows. It only uploads to every 2nd line. Any ideas?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles