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

Link to comment
Share on other sites

} 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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.