I'm uploading a file to my server using a form which enters some variables into a database. The user must type in their 'name' 'email' 'track' and select a file to upload and then click Submit. Once they click submit the file should be uploaded to the server and the entries for 'name' 'email' 'track' should be entered into the database along with the name of the file which was upload 'ufile'.
(i'm not storing the file within the database with blobs)
The code i'm using to process the html form is as follows:
<?php
include 'db.php';
//submiting to the db
$pname = $_POST['pname'];
$email = $_POST['email'];
$track = $_POST['track'];
$ufile = $_POST['ufile'];
$adm = mysql_num_rows(mysql_query("SELECT id FROM player"));
if ($adm == 0) {
$sql = mysql_query("INSERT INTO player (pname, email, track, ufile)
VALUES('$pname', '$email', '$track', '$ufile' ") or die ( mysql_error());
} else {
}
if($result){
echo 'There has been an error';
} else {
$id = mysql_insert_id();
//mail alert
$subject = "New Track Submited!";
$email_address = "cormacmoylan@gmail.com";
$message = "Hello, a new track has been added by $pname using the email address $email
$ufile
$track ";
mail($email_address, $subject, $message, "From: Link sumbmisson<cormac@mysite.com>\nX-Mailer: PHP/" . phpversion());
echo 'Thank you for submitting a link, Check back soon!';
}
//the upload part
$limit_size=100000;
$path= "upload/".$HTTP_POST_FILES['ufile']['name'];
if($ufile !=none)
{
$file_size=$HTTP_POST_FILES['ufile']['size'];
if($file_size >= $limit_size){
echo "Your file size is over limit<BR>";
echo "Your file size = ".$file_size;
echo " K";
echo "<BR>File size limit = 100000 k";
}
else {
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo "Successful<BR/>";
}
else
{
echo "Copy Error";
}
}
}
?>
When i try to upload a file. I get an error saying that i have an error in the mysql syntax on line 2.
CREATE TABLE player (
id int(8) NOT NULL auto_increment,
pname varchar(25) NOT NULL default '',
email varchar(30) NOT NULL default '',
track varchar(30) NOT NULL default '',
ufile varchar(30) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT='player' AUTO_INCREMENT=1 ;
is my myslq i'm using. As far as i can see there is no problem with it. It goes in smoothly into the database thru phpmyadmin.
Any help is greatly appriciated.