how can i write that code...

Discussion in 'PHP' started by Alidad, Sep 27, 2010.

  1. #1
    i just found basic tutorial for myself to learn i still have trouble of how to create that insert data into the database along with images files path.
    Please take look at the code and see the line where it said "$pic=($_FILES['photo']['name'])";" that for inserting images file path name, is this correct code where to put for insert images file path name! if not , how can i correct, of what code to write!

    [syntax=php]<?php
    //connect to database. Username and password need to be changed
    mysql_connect("localhost", "root", "");

    //Select database, database_name needs to be changed
    mysql_select_db("events");


    $target = "images/"; $target = $target . basename( $_FILES['photo']['name']);

    $sql="INSERT INTO movie (title, state, location, date, trailer, photo)
    VALUES
    ('$_POST[title]','$_POST[state]','$_POST[location]', '$_POST[ldate]','$_POST[trailer]',$pic=($_FILES['photo']['name'])";

    if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }
    echo "1 record added";

    mysql_close($con)
    ?> [/syntax]
     
    Alidad, Sep 27, 2010 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    use concatinate

    $sql="INSERT INTO movie (title, state, location, date, trailer, photo)
    VALUES
    ('$_POST[title]','$_POST[state]','$_POST[location]', '$_POST[ldate]','$_POST[trailer]','".$_FILES['photo']['name']."'";
     
    bartolay13, Sep 28, 2010 IP
  3. WoRLDLiFE

    WoRLDLiFE Peon

    Messages:
    116
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If you want to insert image path saved on your server then try using this :

    <?php
    //connect to database. Username and password need to be changed
    mysql_connect("localhost", "root", "");

    //Select database, database_name needs to be changed
    mysql_select_db("events");


    $target = "images/"; $target = $target . basename( $_FILES['photo']['name']);

    $sql="INSERT INTO movie (title, state, location, date, trailer, photo)
    VALUES
    ('$_POST[title]','$_POST[state]','$_POST[location]', '$_POST[ldate]','$_POST[trailer]','$target')";

    if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }
    echo "1 record added";

    mysql_close($con)
    ?>
     
    WoRLDLiFE, Sep 28, 2010 IP