Jump to content

Simple PHP-Mysql Upload Script


Melkien

Recommended Posts

Hey guys! I'm not that good with PHP, and I really need to finish this script. I'm having a hard time finding the problem..it keeps saying Error, query failed and I've also checked the database info, connectivity info and even tried a connection and database selection verification to see if that was working. Is there any other error you guys can find in the script that may be causing the message?

 

Edit: The files I want to be able to upload should be pdf's, txts, docs, etc. Would that be possible with this script?

 

Thanks!!

 

<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr> 
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="104857600"></td>
<td width="80"> </td>
</tr>
</table>
<p>Archivo: 
  <input name="userfile" type="file" id="userfile" />
</p>
<p>Nombre:
  <label for="name"></label>
<input type="text" name="nombrelista" id="nombrelista" />
</p>
<p>Password (para luego borrar si necesario): 
  <input type="text" name="pass" id="pass" />
</p>
<p>
  <input name="upload" type="submit" class="box" id="upload" value=" Upload " />
</p>

<?php
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$filePass = $_POST['pass'];
$nombreLista = $_POST['nombrelista'];



$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

$host_db = "localhost";
$user_db = "melkien_rudesa";
$pass_db = "jorlan2407";
$base_db = "melkien_rudesa";



$link = mysql_connect($host_db, $user_db, $pass_db);
if (!$link) {
    die('Could not connect: ' . mysql_error());
mysql_close($link); 
}

mysql_select_db($base_db, $link) or die(mysql_error());



if(!get_magic_quotes_gpc())
{
   $fileName = addslashes($fileName);
}


$query = "INSERT INTO 'upload'('nombrelista', 'name', 'pass', 'size', 'type', 'content' ) VALUES ('$nombreLista', $fileName', '$filePass', $fileSize', '$fileType', '$content')";


mysql_query($query) or die('Error, query failed'); 


echo "<br>File $fileName uploaded<br>";

mysql_close($link); 

}



?>


</form>

Link to comment
Share on other sites

$query = "INSERT INTO 'upload'('nombrelista', 'name', 'pass', 'size', 'type', 'content' ) VALUES ('$nombreLista', $fileName', '$filePass', $fileSize', '$fileType', '$content')";

 

 

mysql_query($query) or die('Error, query failed');

 

Don't quote your table or field names.  You are getting quotes mixed up with backticks, they are not the same thing and perform totaly different functions.

 

If you change your error checking to

mysql_query($query) or die('Error, query failed : <br /> <br />'.mysql_error()); 

Then I expect you will get the message 'Unkown Field "Upload".....'  Or something else equaly as helpful in identifying the issue.

Link to comment
Share on other sites

I am getting this error:

 

"Error, query failed :

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'cosas de ti.txt', 'TestPassword', text/plain', '436', 'Yo se de ti 11 cosas. 1)' at line 1"

 

Any clue about what I can do about it? I understand there is an error in the SQL syntax but I cant understand where. I tried:

 

$query = "INSERT INTO `upload` (`nombrelista`, `name`, `pass`, `type`, `size`, `content`) VALUES ('$nombreLista', $fileName', '$filePass', $fileType', '$fileSize', '$content')";

$query = "INSERT INTO `upload` (nombrelista, name, pass, type, size, content) VALUES ('$nombreLista', $fileName', '$filePass', $fileType', '$fileSize', '$content')";

$query = "INSERT INTO upload (`nombrelista`, `name`, `pass`, `type`, `size`, `content`) VALUES ('$nombreLista', $fileName', '$filePass', $fileType', '$fileSize', '$content')";

$query = "INSERT INTO upload (nombrelista, name, pass, type, size, content) VALUES ('$nombreLista', $fileName', '$filePass', $fileType', '$fileSize', '$content')";

 

Thanks in advance!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.