/    Sign up×
Community /Pin to ProfileBookmark

Image Upload Script Problem…help

Alright the following script is supposed to allow a user to upload an image to a folder (art) on the server, and the path is stored in the db along with an id, the image name, type, and size…..but the script is not working…

here it is artuploadform.php:

[code=php]
<?php

// code that will be executed if the form has been submitted:

if ($submit) {

// connect to the database

require_once(‘dbconnect.php’);
$conn = db_connect();
mysql_select_db(“user_art”);

$updir = “art/”;
$finame = $_FILES[‘form_data’][‘name’];
$path = $updir.$finame;

move_uploaded_file($_FILES[‘form_data’][‘tmp_name’], $path)
or die(‘Could not move the file <br> ‘ . $_FILES[‘form_data’][‘error’] .’ ‘); // Good to have error checking.

$descript = $_POST[‘form_description’];
$fisize = $_FILES[‘form_data’][‘size’];
$fitype = $_FILES[‘form_data’][‘type’];

$result = mysql_query(“INSERT INTO user_art (description, path, filename, filesize, filetype)
VALUES (‘” . $descript . “‘, ‘” . $path . “‘, ‘” . $finame . “‘, ‘” . $fisize . “‘, ‘” . $fitype . “‘)”);

if($result) {
$id= mysql_insert_id();
print “<p>This file has the following Database ID: <b>$id</b>”;
}

mysql_close();

} else {

// else show the form to submit new data:
?>

<form method=”post” action=”<?php echo $PHP_SELF; ?>” enctype=”multipart/form-data”>
File Description:<br>
<input type=”text” name=”form_description” size=”40″>
<input type=”hidden” name=”MAX_FILE_SIZE” value=”1000000″>
<br>File to upload/store in database:<br>
<input type=”file” name=”form_data” size=”40″>
<p><input type=”submit” name=”submit” value=”submit”>
</form>

<?php

}

?>
[/code]

it is not showing me the id of the image, hence the query is not working, or something similar to that…..what is wrong?

thank you in advance.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@chazzyApr 07.2006 — you didn't do any error checking for your query.
[code=php]
$result = mysql_query("INSERT INTO user_art (description, path, filename, filesize, filetype)
VALUES ('" . $descript . "', '" . $path . "', '" . $finame . "', '" . $fisize . "', '" . $fitype . "')") or die("Unable to insert image details - ".mysql_error());
[/code]
×

Success!

Help @Viajero spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.12,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...