/    Sign up×
Community /Pin to ProfileBookmark

Problems with mysql INSERT query and an image* upload file

I am working on this form, that is meant for only site owners and crew to use, so i didn’t run any checks on the input, i trust the discretion of the users.

It’s a basic application that adds a product into the database, a name, the description, and also a small logo, unique to each product.

Instead of storing the image in a blob on the database, which will significantly increase the resource consumption of the site, i decide to upload it to a directory in my website files, and save the path to the image in the database, and later on use it to preview it as html.

There are two problems with this app.

One is that it doesn’t add the new item to the table.

And another is that it fails to upload the image.

Please help me guys.

You can see how the app behaves here:
[url]http://www.opend4u.net/Oleg/Temp/addproduct.php[/url]

I made it print the query to make the debugging easier.

Source:

[code=php]
<?php
if(isset($_POST[‘name’]) and isset($_POST[‘assessment’]) and $_FILES[‘logo’][‘size’]!=0)
{
print(phpversion());
$link2k=mysql_connect(localhost, REMOVED, REMOVED);
mysql_select_db(nitay_oleg, $link2k);

$uploaddir = “Temp/img/”;
$uploadfile = $uploaddir . basename($_FILES[‘logo’][‘name’]);
print($uploadfile);
if (move_uploaded_file($_FILES[‘logo’][‘tmp_name’], $uploadfile)) {
echo “File is valid, and was successfully uploaded.n”;
}
else{
print(“File failed to be uploaded.n”);
}
$query=”INSERT INTO ‘product’ (‘name’, ‘logo’, ‘assessment’) VALUES (‘”.$_POST[‘name’].”‘, ‘”.$uploadfile.”‘, ‘”.$_POST[‘assessment’].”‘)”;
$result=mysql_query($query, $link2k);
print($query);
}
?>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Add new product</title>
</head>
<body>
<form method=”post” dir=”rtl” target=”_self” action=”addproduct.php” enctype=”multipart/form-data”>
<input type=”hidden” name=”MAX_FILE_SIZE” value=”15000″ />
<table align=”right” width=”30%”>
<tr><td>Product name:</td><td><input type=”text” name=”name” align=”right” size=”20″ maxlength=”20″/></td></tr>
<tr><td>Product logo:</td><td><input type=”file” name=”logo” size=”20″ /></td></tr>
<tr><td rowspan=”0″></td></tr>
<tr><td>Product features(html):</td></tr>
<tr><td rowspan=”0″></td></tr>
</table>
<br><br><br><br><br><br><br><br><br><br>
<div align=”right” valign=”buttom”>
<textarea cols=”50″ name=”assessment” rows=”5″></textarea>
</div>
<br><br><br><br><br>
<div align=”right” valign=”buttom”>
<input type=”submit” />
</div>
</form>
</body>
</html>
[/code]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @HellgY 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.20,
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,
)...