Uploader help

Hello, lately I have been working on a shop system for website, all is fine until it comes to uploading things, here’s my code:

[php]

Nicron / Upload item
Upload Shop Item
<?php include("conn.php"); session_start(); $iname = mysql_real_escape_string(strip_tags($_POST['iname'])); $idesc = mysql_real_escape_string(strip_tags($_POST['idesc'])); $price = mysql_real_escape_string(strip_tags($_POST['price'])); if(isset($_POST['submit'])){ if (($_FILES["file"]["type"] == "image/png") && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "
"; } else {
if (file_exists("upload/" . $_FILES["file"]["name"]))
  {
  echo $_FILES["file"]["name"] . " already exists. ";
  }
else
  {
  move_uploaded_file($_FILES["file"]["tmp_name"],
  "avatars/" . $_FILES["file"]["name"]);
  echo "Stored in: " . "avatars/" . $_FILES["file"]["name"];
  echo "Item awaiting approval!";
  mysql_query("INSERT INTO oitems VALUES('$iname', '$idesc', '$price', 'http://nicron.x10.mx/avatars/' . $_FILES[file][name], '$_SESSION[username]')");
  }
}

}
else
{
echo “Invalid file”;
}
}
else{
?>

Item Name:
Price:
Description:

<?php } ?>

Return [/php]

The file uploads, but the script refuses to write to the database.

Thanks for any help!

on the line after your input to the table put echo mysql_error(); this will tell you any error that is accuring and will show nothing if there is no error

Hiya,

Try this:

[php] mysql_query(“INSERT INTO oitems VALUES(’$iname’,’$idesc’,’$price’,‘http://nicron.x10.mx/avatars/’,’$_FILES[file][name]’,’$_SESSION[username]’)”);[/php]

That should work.

Still not working, thanks for trying :confused:

Try this:
[php]mysql_query(“INSERT INTO oitems VALUES(’$iname’, ‘$idesc’, ‘$price’, ‘http://nicron.x10.mx/avatars/".mysql_real_escape_string($_FILES[‘file’][‘name’])."’, '”.mysql_real_escape_string($_SESSION[‘username’])."’)");[/php]

But I would suggest to use full syntax with fields, so that you’re not missing anything (like id field), and also have correct fields order in your query. Like this:
[php]mysql_query(“INSERT INTO tablename (field1,field2,field3) VALUES(’$value1’,$value2’,’$value3’)”);[/php]

And also if you want to check if there is some problem in your query, just do this after your query:
[php]echo mysql_error();[/php]

phphelp, correctomundo.

Use full syntax. It will work better.

Your a life saver, phphelp!

I fully appreciate your assistance!

Sponsor our Newsletter | Privacy Policy | Terms of Service