Results 1 to 3 of 3

Thread: PHP Form submitting to database with a file upload field help

  1. #1
    Join Date
    May 2013

    PHP Form submitting to database with a file upload field help

    hello, so basically what I am trying to do is add an image and file upload field to an existing form.

    i have a database

    Field Type Collation Attributes Null Default Extra Action
    id int(11) No auto_increment
    first varchar(50) latin1_general_ci No
    last varchar(50) latin1_general_ci No
    phone int(10) No
    country varchar(30) latin1_general_ci No
    city varchar(30) latin1_general_ci No
    age smallint(2) No
    gender varchar(40) latin1_general_ci No
    image blob BINARY No

    and here is the code that i have:

    PHP Code:

    if (!
    'Could not connect: ' mysql_error());
    $sql="INSERT INTO person (first, last, phone, country, city, age, gender) VALUES (' $_POST[first] ','$_POST[last]','$_POST[phone]','$_POST[country]','$_POST[city]','$_POST[age]','$_POST[gender]')";

    if (!
    'Error: ' mysql_error());

    if (isset(
    $_FILES[$column]) && $_FILES[$column]['size'] > 0) {
    $tmpName $_FILES[$column]['tmp_name'];
    $fp      fopen($tmpName'r');
    $data fread($fpfilesize($tmpName));
    $data addslashes($data);

    $query "INSERT INTO $table ";
    $query .= "($column) VALUES ('$data')";
    $results mysql_query($query$link);
    "Thank you, Your Image has been uploaded. DONT FORGET  to add the image into your profile! ";
        else {
    "No image selected/uploaded. Make sure that you have not exceeded the max file size!";


    so what i want is people be able to submit application with an image or file and (store in the database )other people to search the people and the info would be displayed with the info ( get info from database ) is there any way to achieve this
    all i need is a few explanations on what to focus on studying to create things like that, real estate websites and such.

    is it possible to add this option now?

    Thank you

  2. #2
    Join Date
    Feb 2012
    Pensacola, FL
    In my experience, the image isn't stored in the database but rather uploaded to a directory and the path saved in the database. Then when called there is a link or img tag that points to the path in the DB.

  3. #3
    Join Date
    Mar 2009
    Basically you would change your insert into something like this. you have to make a column in the database to hold the file name for the image after the image is uploaded.

    PHP Code:
    ="INSERT INTO person (first, last, phone, country, city, age, gender, image) VALUES (' $_POST[first] ','$_POST[last]','$_POST[phone]','$_POST[country]','$_POST[city]','$_POST[age]','$_POST[gender]', '$data')"

    Does this help any?
    Samantha Morrison
    Knock-Out Web Designs
    Website Developer/Designer

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