I’m working on an upload file that will allow me to upload a file to “images/’ directory, and at the same time, put in info into the database ‘images’ name, location (taken from the file upload), month taken, and rel. link.
I want all these to be text so I can pull then into hmtl code, e.g <img> tags, or hyperlinks.
What I’ve done is create a form which has name, month, link and file upload in it. The file upload goes to images/ , and the name, month, link and location of the file upload goes to a database along with and automated ID.
This is the html form:
[code=html]<form method=”post” action=”upload.php” enctype=”multipart/form-data”>
Name: (100 characters)<br>
<input type=”text” name=”name_given” size=”80″ maxlength=”60″>
<br>Month:<br>
<input type=”text” name=”month” size=”30″>
<br>Link:<br>
<input type=”text” name=”link” size=”30″>
<input type=”hidden” name=”MAX_FILE_SIZE” value=”1500000″>
<br>File to upload:<br>
<input type=”file” name=”userfile” size=”40″>
<p><input type=”submit” name=”submit” value=”Submit”>
</form>
This is my php code so far:
[code=php]<?php
mysql_connect(“******”,”******”,”*****”) or die(mysql_error());
mysql_select_db(“*************”) or die(mysql_error());
$uploaddir = ‘images/’;
$uploadfile = $uploaddir.$_FILES[‘userfile’][‘name’];
$userfile =$_FILES[‘userfile’][‘name’];
$name=$_POST[‘name_given’];
$month=$_POST[‘month’];
$link=$_POST[‘link’];
$result = MYSQL_QUERY(“INSERT INTO `images` (‘name’,’location’,’month’,’link’) “. “VALUES (‘$name’,’$uploadfile’,’$month’,’$link’)”);
$id= mysql_insert_id();
if (move_uploaded_file($_FILES[‘userfile’][‘tmp_name’],$uploadfile)){
print “<p>File ID: <b>$id</b><br>”;
print “Name: <b>$name</b><br>”;
print “Location: <b>$uploadfile</b><br>”;
print “Month: <b>$month</b><br>”;
print “Featured Link: <b>$link</b><br></p>”;
echo ‘<center>The file <strong>”‘.$_FILES[‘userfile’][‘name’].'”</strong> successfully uploaded to <a href=”‘.$uploadfile.'” target=”_blank”>link</a>’;
}
else {
print “<center><font color=red><strong>Something is wrong, please try again!</font>”;
}
?>
When I use it, the image gets uploaded fine, but the mySQL data doesn’t go anywhere.
It shows as:
id: 0
name: [name of picture given]
month: [month field]
link: [link field]
file got uploaded successfully to [link]
When I go and check the database, it’s not go anything, “0 rows”
Can I please have some help on finding out what’s wrong?