Php script problem, I need help

Discussion in 'PHP' started by floriano, Jun 3, 2009.

  1. #1
    This application must upload in the server and write the image name in db table but not write, why, where I mistake?
    I have problems with the application?

    <?php 
    include('conexiune.php'); 
     
    $target = "imagini/"; 
    $target = $target . basename( $_FILES['imagine']['name']); 
    
    $pic=($_FILES['imagine']['name']); 
    
    mysql_query("INSERT INTO imagine VALUES (id, imagine) VALUES(0, '$pic',"); 
    
    if(move_uploaded_file($_FILES['imagine']['tmp_name'], $target)) 
    { 
    
    echo "Image upload was successful"; 
    } 
    else { 
    
    echo "Sorry, but the image could not be uploaded on the server"; 
    } 
    ?>
    Code (markup):
    Or anyone knows a script that load the image on the server and saved name in the database?

    Thanks in advance.

    Best Regards,
    Floriano
     
    floriano, Jun 3, 2009 IP
  2. jnugroho73

    jnugroho73 Peon

    Messages:
    77
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2

    Is this line is correct?
    mysql_query("INSERT INTO imagine VALUES (id, imagine) VALUES(0, '$pic',");

    If it is, then you should remove the last comma and close it with )
    mysql_query("INSERT INTO imagine VALUES (id, imagine) VALUES(0, '$pic')");
     
    jnugroho73, Jun 4, 2009 IP
  3. floriano

    floriano Well-Known Member

    Messages:
    74
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    113
    #3
    Is not this problem, I change but not work.

    Regards,
    Floriano
     
    floriano, Jun 4, 2009 IP
  4. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #4
    try this one

    
    <?php 
    include('conexiune.php'); 
     
    $target = "imagini/"; 
    $target = $target . basename( $_FILES['imagine']['name']); 
    
    $pic=($_FILES['imagine']['name']); 
    
    mysql_query("INSERT INTO imagine (id, imagine) VALUES (0, '$pic')"); // look at this 
    
    if(move_uploaded_file($_FILES['imagine']['tmp_name'], $target)) 
    { 
    
    echo "Image upload was successful"; 
    } 
    else { 
    
    echo "Sorry, but the image could not be uploaded on the server"; 
    } 
    
    
    PHP:
     
    crivion, Jun 4, 2009 IP
  5. floriano

    floriano Well-Known Member

    Messages:
    74
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    113
    #5
    Thanks very much "crivion" for help, is work now(is good, upload image)

    but another question, now not intro date in table: name, location, number

    If someone can help me

    Thank in advance,
    Floriano
     
    floriano, Jun 4, 2009 IP
  6. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #6
    "bai nenea, invata php"

    
    <?php
    include('conexiune.php');
    $target = "imagini/";
    $target = $target . basename( $_FILES['imagine']['name']);
    $pic=($_FILES['imagine']['name']);
    mysql_query("INSERT INTO imagine (id, imagine, name, location, number) VALUES (0, '$pic', '$_POST[name]', '$_POST[location]', '$_POST[number]')");
    if(move_uploaded_file($_FILES['imagine']['tmp_name'], $target))
    {
    echo "Image upload was successful";
    }
    else { echo "Sorry, but the image could not be uploaded on the server";
    }
    ?>
    
    <form enctype="multipart/form-data" action="upload.php" method="POST">
    <BR>Nume:
    <BR><INPUT TYPE="TEXT" NAME="name">
    <BR>Location:
    <BR> <INPUT TYPE="TEXT" NAME="location">
    <BR>Number:
    <BR><INPUT TYPE="TEXT" NAME="number">
    
    Imaginea: <input type="file" name="imagine">
    <input type="submit" value="Upload">
    </form> <br /> 
    
    PHP:
     
    crivion, Jun 4, 2009 IP
  7. floriano

    floriano Well-Known Member

    Messages:
    74
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    113
    #7
    Thanks "crivion" for your help.

    Multumesc din suflet pentru ajutorul tau. :)
     
    floriano, Jun 4, 2009 IP
  8. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #8
    My pleasure to help others where I can

    goodluck
     
    crivion, Jun 4, 2009 IP