Melkien Posted December 19, 2011 Share Posted December 19, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/253473-simple-php-mysql-upload-script/ Share on other sites More sharing options...
Muddy_Funster Posted December 19, 2011 Share Posted December 19, 2011 $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. Quote Link to comment https://forums.phpfreaks.com/topic/253473-simple-php-mysql-upload-script/#findComment-1299308 Share on other sites More sharing options...
Melkien Posted December 19, 2011 Author Share Posted December 19, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/253473-simple-php-mysql-upload-script/#findComment-1299331 Share on other sites More sharing options...
scootstah Posted December 19, 2011 Share Posted December 19, 2011 You are missing single quotes around some of your variables. Quote Link to comment https://forums.phpfreaks.com/topic/253473-simple-php-mysql-upload-script/#findComment-1299353 Share on other sites More sharing options...
Melkien Posted December 19, 2011 Author Share Posted December 19, 2011 Oh, I posted 4 different ways I used to try and fix the problem, seems none work Quote Link to comment https://forums.phpfreaks.com/topic/253473-simple-php-mysql-upload-script/#findComment-1299541 Share on other sites More sharing options...
Pikachu2000 Posted December 19, 2011 Share Posted December 19, 2011 Look at them again. Pay close attention to the single quotes around the values. Quote Link to comment https://forums.phpfreaks.com/topic/253473-simple-php-mysql-upload-script/#findComment-1299548 Share on other sites More sharing options...
Melkien Posted December 20, 2011 Author Share Posted December 20, 2011 Wow, such a stupid error haha, thanks guys! Quote Link to comment https://forums.phpfreaks.com/topic/253473-simple-php-mysql-upload-script/#findComment-1299558 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.