Uploading a file

SpaceshipSpaceship
SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
Watch

asgsoft

VIP Member
Impact
9
Hi

I am making a script that will allow me to upload an image and then add the file name to a db. I use this form:

PHP:
<form method="post" action="addsand.php" enctype="multipart/form-data"> 
<p>Insert A new Sandwich to our Menu.</p>
<p>name:
<input name="name" type="text" id="name">
</p>
  <p>Contents: 
    <textarea name="contents" id="contents"></textarea>
</p>
  <p>Extra Info: 
    <input name="extrainfo" type="text" id="extrainfo" >
</p>
  <p>Image<em>(ONLY JPEG,GIF,PNG)</em> 
    <input type="file" name="userfile" />
  </p>
  <p>Price: 
    <input name="Price" type="text" id="Price" >
  </p>
  <p> </p>  <p> </p>
<p>
<input type="submit" value="Add New Sandwitch" name="register">
</p>
</form>

and then addsand.php has:

PHP:
<?php
$type = $_FILES['userfile']['type'];
if ( ($type == 'image/png' ) || ($type == 'image/gif' ) || ($type == 'image/jpeg' ) ) {
move_uploaded_file($_FILES['userfile']['tmp_name'], "Upload/" . $_FILES['userfile']['name']);
echo "Upload Complete!";
}
else {
     die ("Invalid file type");
}
$name = $_POST['name'];
$contents = $_POST['contents'];
$extrainfo = $_POST['extrainfo'];
$price = £;
$price .= $_POST['price'];
$image_dir = $image_dir = $_FILES['userfile']['name'];

$errors = 0;
$emessage = "<center><font face=\"Verdana\">Sorry, we enounctered the following errors when processing your registration:<br /><ul>";

if(empty($name) || empty($contents)|| empty($extrainfo)|| empty($price))
{
$errors = 1;
$emessage .= "<li>Sorry, you must fill in <strong>all</strong> fields.  Please go back and try again.</li>";
}


if($errors != 0)
{
$emessage .= "</font></center>";
die("$emessage");
}


mysql_connect("localhost", "root", "") or die(mysql_error());

mysql_select_db("sam") or die(mysql_error());

mysql_query("INSERT INTO food (name,contents,extrainfo,imgurl,price) VALUES ('$name','$contents','$extrainfo','$image_dir')") or die(mysql_error());
echo("<center><font face=\"Verdana\">Sandwich Added. Click <a href='index.php'>here</a></p> to go back to admin area</font></center>");

?>

when i upload it says :

PHP:
Warning: move_uploaded_file(Upload/Catering_2.JPG) [function.move-uploaded-file]: failed to open stream: No such file or directory in c:\asgsoft\www\sam\admin\addsand.php on line 38

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'c:/asgsoft/tmp\php7F.tmp' to 'Upload/Catering_2.JPG' in c:\asgsoft\www\sam\admin\addsand.php on line 38
Upload Complete!Column count doesn't match value count at row 1

Can anyone help me out.
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
You need a \ after c:
 
0
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Filters for activity feeds
Your news feed, Latest activity, and the activity tab on profiles now have filter buttons: All, Posts, Quick replies, and Other. Your...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back