crochk Posted October 29, 2008 Share Posted October 29, 2008 I have a form to submit information on an event, including a logo (file). This information would then be submitted into a MySQL database. When the form is filled out, an "empty query" error is returned. But the file is put into the correct directory, just nothing is submitted into the database. Here is my php code for processing the form: <?php if (isset($_POST['submit'])) { if ($_FILES['file']['size'] > 0) { $con = mysql_connect("localhost","XXXXXXXXXX","XXXXXXXXXXX"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("XXXXXXXXXXXX", $con); //Delcarations putenv("TZ=US/Eastern"); $uploadDir = '/XXXXXXXXXXXXXXXXXXXX/htdocs/events/images/logos/'; $ip=$_SERVER['REMOTE_ADDR']; $date=date("d-M-Y h:i:s A"); //POSTS $name = $_POST['name']; $where = $_POST['where']; $when = $_POST['when']; $age = $_POST['age']; $price = $_POST['price']; $description = $_POST['description']; $minidescription = $_POST['minidescription']; $facebook = $_POST['facebook']; $dateorder = $_POST['dateorder']; //File $filename = $_FILES['file']['name']; $tmpname = $_FILES['file']['tmp_name']; $filesize = $_FILES['file']['size']; $filetype = $_FILES['file']['type']; $file=$_POST[file]; $ext = substr(strrchr($filename, "."), 1); $randName = md5(rand() * time()); $filepath = $uploadDir . $randName . '.' . $ext; $result = move_uploaded_file($tmpname, $filepath); if(!get_magic_quotes_gpc()) { $filename = addslashes($filename); $filepath = addslashes($filepath); } $usePath="http://XXXXXXXXXXXXXXXX/events/images/logos/" . $randName . '.' . $ext; //Insert into DB $sql=mysql_query("INSERT INTO events (name, where, when, age, price, description, minidescription, facebook, dateorder, filepath, filename, filetype, filesize, ip, date) VALUES ('$name','$where','$when','$age','$price','$description','$minidescription','$facebook','$dateorder','$usePath','$fileName','$fileType','$fileSize','$ip','$date')"); if (!mysql_query($sql1,$con)) { die('<p><strong>Event:</strong> Error Uploading</p><p>Error: ' . mysql_error() . '</p>'); } echo "<p><strong>" . $name . " Submitted</strong></p>"; } else { die("No Logo Submitted"); } } else { ?> Thanx Quote Link to comment Share on other sites More sharing options...
DarkWater Posted October 29, 2008 Share Posted October 29, 2008 Did you even read your code? >_< You have $sql being set to the results of a mysql_query(), and then you try to do a mysql_query() with the non-existant $sql1 variable. Quote Link to comment Share on other sites More sharing options...
crochk Posted October 29, 2008 Author Share Posted October 29, 2008 That was a stupid mistake, but it was a minor one that would not fix anything. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted October 29, 2008 Share Posted October 29, 2008 Uhh, except for the fact that it would fix it, tell me why it wouldn't fix it. =/ Quote Link to comment Share on other sites More sharing options...
crochk Posted October 29, 2008 Author Share Posted October 29, 2008 I did try it, so unless I missunderstood your correction, it still doesnt work here is the corrected code: <?php if (isset($_POST['submit'])) { if ($_FILES['file']['size'] > 0) { $con = mysql_connect("localhost","XXXXXXXXXX","XXXXXXXXXXX"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("XXXXXXXXXXXX", $con); //Delcarations putenv("TZ=US/Eastern"); $uploadDir = '/XXXXXXXXXXXXXXXXXXXX/htdocs/events/images/logos/'; $ip=$_SERVER['REMOTE_ADDR']; $date=date("d-M-Y h:i:s A"); //POSTS $name = $_POST['name']; $where = $_POST['where']; $when = $_POST['when']; $age = $_POST['age']; $price = $_POST['price']; $description = $_POST['description']; $minidescription = $_POST['minidescription']; $facebook = $_POST['facebook']; $dateorder = $_POST['dateorder']; //File $filename = $_FILES['file']['name']; $tmpname = $_FILES['file']['tmp_name']; $filesize = $_FILES['file']['size']; $filetype = $_FILES['file']['type']; $file=$_POST[file]; $ext = substr(strrchr($filename, "."), 1); $randName = md5(rand() * time()); $filepath = $uploadDir . $randName . '.' . $ext; $result = move_uploaded_file($tmpname, $filepath); if(!get_magic_quotes_gpc()) { $filename = addslashes($filename); $filepath = addslashes($filepath); } $usePath="http://XXXXXXXXXXXXXXXX/events/images/logos/" . $randName . '.' . $ext; //Insert into DB $sql=mysql_query("INSERT INTO events (name, where, when, age, price, description, minidescription, facebook, dateorder, filepath, filename, filetype, filesize, ip, date) VALUES ('$name','$where','$when','$age','$price','$description','$minidescription','$facebook','$dateorder','$usePath','$fileName','$fileType','$fileSize','$ip','$date')"); if (!mysql_query($sql,$con)) { die('<p><strong>Event:</strong> Error Uploading this event</p><p>Error: ' . mysql_error() . '</p>'); } echo "<p><strong>" . $name . " Submitted</strong></p>"; } else { die("No Logo Submitted"); } } else { ?> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted October 29, 2008 Share Posted October 29, 2008 ...You see that you're already calling mysql_query(), correct? Remove the first call to mysql_query() so it's just a simple string assignment... =/ Quote Link to comment Share on other sites More sharing options...
crochk Posted October 29, 2008 Author Share Posted October 29, 2008 I understand what you are saying, but I am still getting another error: 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 'where, when, age, price, description, minidescription, facebook, dateorder, file' at line 1 New code: <?php if (isset($_POST['submit'])) { if ($_FILES['file']['size'] > 0) { $con = mysql_connect("localhost","XXXXXXXXXX","XXXXXXXXXXX"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("XXXXXXXXXXXX", $con); //Delcarations putenv("TZ=US/Eastern"); $uploadDir = '/XXXXXXXXXXXXXXXXXXXX/htdocs/events/images/logos/'; $ip=$_SERVER['REMOTE_ADDR']; $date=date("d-M-Y h:i:s A"); //POSTS $name = $_POST['name']; $where = $_POST['where']; $when = $_POST['when']; $age = $_POST['age']; $price = $_POST['price']; $description = $_POST['description']; $minidescription = $_POST['minidescription']; $facebook = $_POST['facebook']; $dateorder = $_POST['dateorder']; //File $filename = $_FILES['file']['name']; $tmpname = $_FILES['file']['tmp_name']; $filesize = $_FILES['file']['size']; $filetype = $_FILES['file']['type']; $file=$_POST[file]; $ext = substr(strrchr($filename, "."), 1); $randName = md5(rand() * time()); $filepath = $uploadDir . $randName . '.' . $ext; $result = move_uploaded_file($tmpname, $filepath); if(!get_magic_quotes_gpc()) { $filename = addslashes($filename); $filepath = addslashes($filepath); } $usePath="http://XXXXXXXXXXXXXXXX/events/images/logos/" . $randName . '.' . $ext; //Insert into DB $sql=mysql_query("INSERT INTO events (name, where, when, age, price, description, minidescription, facebook, dateorder, filepath, filename, filetype, filesize, ip, date) VALUES ('$name','$where','$when','$age','$price','$description','$minidescription','$facebook','$dateorder','$usePath','$fileName','$fileType','$fileSize','$ip','$date')"); if (!$sql) { die('<p><strong>Event:</strong> Error Uploading</p><p>Error: ' . mysql_error() . '</p>'); } echo "<p><strong>" . $name . " Submitted</strong></p>"; } else { die("No Logo Submitted"); } } else { ?> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted October 29, 2008 Share Posted October 29, 2008 You can't have a column named where. Change the column name. EDIT: At least I think. >_< Quote Link to comment Share on other sites More sharing options...
crochk Posted October 29, 2008 Author Share Posted October 29, 2008 I changed the column name both in the php and database, yet no change in the error. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted October 29, 2008 Share Posted October 29, 2008 when is also a reserved word. Quote Link to comment Share on other sites More sharing options...
crochk Posted October 29, 2008 Author Share Posted October 29, 2008 OOOOOOOOOOO It worked!!!!!!! Thanx :D :D :D Quote Link to comment Share on other sites More sharing options...
DarkWater Posted October 29, 2008 Share Posted October 29, 2008 No problem. Quote Link to comment 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.