Jump to content

[SOLVED] Uploading information into a database


dark22horse

Recommended Posts

Hi

 

I have had this working a some stage, but I am unsure what I have changed.

 

This is my form

 

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Price<input type="text" name="price" length="20" /><br/>
description<textarea name="description" rows="5" cols="35"></textarea><br/>
Choose a file to upload: <input name="photo" type="file" /><input type="submit" value="Upload File" /><br />

 

This is my uploader.php

 


<? 
require_once("mysql_config.php");

$target_path = $target_path . basename( $_FILES['photo']['name']); 
$_FILES['photo']['tmp_name'];

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['photo']['name']); 

if(move_uploaded_file($_FILES['photo']['tmp_name'], $target_path)) {


    echo "The file ".  basename( $_FILES['photo']['name']). " has been uploaded";

$sql_string = "INSERT INTO car(price, description, photo) VALUES ('".$_POST['price']."', '".$_POST['description']."', '".$_FILES['photo']['name']."')";

echo "<br/>SQL STRING WE WANT TO RUN: ".$sql_string;

echo "db connection: ".$dbconn;
echo "table connection: ".$table;

$ok = mysql_query($sql_string);

echo "OK: ".$ok;

if($ok){
	echo "<h2>all is good, upload another</h2>";
} else {
	echo "<h2>check the string".$sql_string."</h2>";
}

} else{

   echo "There was an error uploading the file, please try again!";

}

?>

 

It brings up this error message "There was an error uploading the file, please try again!"

 

Cheers

} else{

   echo "There was an error uploading the file, please try again!";

}

 

change to:

 

}// else{

  // echo "There was an error uploading the file, please try again!";

//}

and when you open the page in a browser it should return an error

 

K didnt get an error message as such, but this came up

 

[photo] => Array

        (

            [name] =>

            [type] =>

            [tmp_name] =>

            [error] => 4

            => 0

        )

 

Not sure what this means.

Thats seems fine, it is in the folder with it.  Maybe it is the Form??

 

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Price<input type="text" name="price" length="20" /><br/>
description<textarea name="description" rows="5" cols="35"></textarea><br/>
Choose a file to upload: <input name="photo" type="file" /><input type="submit" value="Upload File" /><br />

 

Is that k?

I was referring to

[pre]

[photo] => Array

        (

            [name] =>

            [type] =>

            [tmp_name] =>

            [error] => 4

            => 0

        )

[/pre]

I thought you were, guess what!! I am a newbie php person :). Its sorted now.  I had deleted the </form> at the end.  HAHA this took me 3 days to work out! I suck, but cheers for all the help! you guys have helped me a lot, if only i could repay the favour.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.