0

How do i insert this into my sql database? I have tried a few things like putting the array bracks on the upload file. when i do this it saves the image location but doesnt upload the image.
This is my upload snippet

for ($i=0;$i<4;$i++)
  {
   if($_FILES['userfile']['name'][$i])
   {
    $uploadfile = $uploaddir . basename($_FILES['userfile']['name'][$i]);
    $ext = strtolower(substr($uploadfile,strlen($uploadfile)-3,3));
    if (preg_match("/(jpg|gif|png|bmp)/",$ext))
    {
     if (move_uploaded_file($_FILES['userfile']['tmp_name'][$i], $uploadfile)) 
     }

My insert snippet looks like this;

  $qry = "INSERT INTO properties(photourl,photourl2) VALUES('$userfile[1]','$userfile[0]')";
    $result = @mysql_query($qry);

    //Check whether the query was successful or not
    if($result) {
        header("location: register-success.php");
        exit();
    }else {
        die("Query WTF failed");
    }

as it is now i get no error , but the fields are empty .

2
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by realworldmedia
0

What do you get if you echo $userfile[0] and $userfile[1]? Here I don't see how those variables are set.
Also remove @ from mysql_query and add or die(mysql_error()); at the end, so you can see what is wrong with your query.

Edited by cereal

0

when i echo that the lines are just empty...when i use.... $uploadfile[0] and $uploadfile[1] and putt the [] bracket on $uploadfile[] = $uploaddir . basename($_FILES['userfile']['name'][$i]);

i get the correct names but it stops uploading the images

0

THis is what i am saves the image name and location but stops actually uploading the image

for ($i=0;$i<4;$i++)
  {
   if($_FILES['userfile']['name'][$i])
   {
    $uploadfile[] = $uploaddir . basename($_FILES['userfile']['name'][$i]);
    $ext = strtolower(substr($uploadfile,strlen($uploadfile)-3,3));
    if (preg_match("/(jpg|gif|png|bmp)/",$ext))
    {
     if (move_uploaded_file($_FILES['userfile']['tmp_name'][$i], $uploadfile)) 
     }

INSERT QUERY

  $qry = "INSERT INTO properties(photourl,photourl2) VALUES('$uploadfile[1]','$uploadfile[0]')";
    $result = @mysql_query($qry);

    //Check whether the query was successful or not
    if($result) {
        header("location: register-success.php");
        exit();
    }else {
        die("Query WTF failed");
    }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.