calvinschools Posted May 6, 2011 Share Posted May 6, 2011 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <?php $hostname='xxx'; $username='xxx'; $password='xxx'; $dbname='xxx; $usertable=xxx; $myconn=mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.'); if ((($_FILES["file"]["type"] =="image/gif") || ($_FILES["file"]["type"] =="image/jpeg") || ($_FILES["file"]["type"] == "image/png")) && ($_FILES["file"]["size"]< 200000)) { if ($_FILES["file"]["error"] >0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br/>"; } else { if (file_exists("uploads/" . $_FILES["file"]["name"])) { echo "File already exists. Choose another name."; } else { move_uploaded_file($_FILES["file"]["tmp_name"],"uploads/" . $_FILES["file"]["name"]); } } } else { echo "Invalid file"; } $path="uploads/" . $_FILES["file"]["name"]; $desc=$_POST["desc"]; if (!myconn) { die ('Could not connect: ' . $mysql_error()); } $db_selected=mysql_select_db('xxx',$myconn); if (!$db_selected) { die ('Can\'t use xxxx : ' . mysql_error()); } mysql_query("INSERT INTO partners (desc,photopath,state) VALUES ('$desc','$path','$state')"); mysql_close($myconn); ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/235665-files-upload-to-temp-folder-but-not-databse/ Share on other sites More sharing options...
fugix Posted May 6, 2011 Share Posted May 6, 2011 what errors do you receive..do you have an auto incrementing id field of some sort? Link to comment https://forums.phpfreaks.com/topic/235665-files-upload-to-temp-folder-but-not-databse/#findComment-1211269 Share on other sites More sharing options...
calvinschools Posted May 6, 2011 Author Share Posted May 6, 2011 I receive no errors. My id field is auto increment. After you hit submit the file goes to its temp folder location but never makes it into the database. Link to comment https://forums.phpfreaks.com/topic/235665-files-upload-to-temp-folder-but-not-databse/#findComment-1211270 Share on other sites More sharing options...
fugix Posted May 6, 2011 Share Posted May 6, 2011 if you have an id field, you must also call it out in your query mysql_query("INSERT INTO partners (id,desc,photopath,state) VALUES ('', '$desc','$path','$state')"); Link to comment https://forums.phpfreaks.com/topic/235665-files-upload-to-temp-folder-but-not-databse/#findComment-1211272 Share on other sites More sharing options...
calvinschools Posted May 6, 2011 Author Share Posted May 6, 2011 really? i thought you didn't have to because it would increment regardless. Let me try. Link to comment https://forums.phpfreaks.com/topic/235665-files-upload-to-temp-folder-but-not-databse/#findComment-1211273 Share on other sites More sharing options...
fugix Posted May 6, 2011 Share Posted May 6, 2011 it will increment yeah, but if you dont call it out in your query, your query will fail Link to comment https://forums.phpfreaks.com/topic/235665-files-upload-to-temp-folder-but-not-databse/#findComment-1211275 Share on other sites More sharing options...
calvinschools Posted May 6, 2011 Author Share Posted May 6, 2011 called it and nothing. Link to comment https://forums.phpfreaks.com/topic/235665-files-upload-to-temp-folder-but-not-databse/#findComment-1211276 Share on other sites More sharing options...
fugix Posted May 6, 2011 Share Posted May 6, 2011 okay, write this onto your query mysql_query("INSERT INTO partners (desc,photopath,state) VALUES ('$desc','$path','$state')") or die(mysql_error()); and tell me what happens Link to comment https://forums.phpfreaks.com/topic/235665-files-upload-to-temp-folder-but-not-databse/#findComment-1211277 Share on other sites More sharing options...
calvinschools Posted May 6, 2011 Author Share Posted May 6, 2011 ran it and received this 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 'desc,photopath,state) VALUES ('james','uploads/Screen shot 2011-04-28 at 9.19.37' at line 1 Link to comment https://forums.phpfreaks.com/topic/235665-files-upload-to-temp-folder-but-not-databse/#findComment-1211278 Share on other sites More sharing options...
fugix Posted May 6, 2011 Share Posted May 6, 2011 where in your code is you $state var specified? Link to comment https://forums.phpfreaks.com/topic/235665-files-upload-to-temp-folder-but-not-databse/#findComment-1211283 Share on other sites More sharing options...
calvinschools Posted May 6, 2011 Author Share Posted May 6, 2011 here in the upload form; </style> </head> <body> <div id="wrapper"><h1></h1><div id="Photos"> <form id="form1" name= "form1" method="POST" action="photo_table.php" enctype="multipart/form-data"> <table width="50%" cellpapdding="5" cellspacing="0" bgcolor="#999999"> <tr> <th height="37" colspan="2" bgcolor="" scope="row"><span class="style1"><h2>Photo Upload</h2></span></th> </tr> <tr> <th bordercolor="" scope="row"><div align="right" class="style1"><h1>Photo</h1></div></th> <td bgcolor="#FFFFFF"><label> <input name="file" type="file"/> </label></td> </tr> <tr> <th bordercolor="999999" scope="row"><div align="right" class="style1"><h3>Name(first and last)</h3></div></th> <td bgcolor="#FFFFFF"><label> <input name="desc" type="text"/> </label></td> </tr> <tr> <th bordercolor="" scope="row"><div align="right" class="style1"><h3>State</h3></div></th> <td bgcolor="#FFFFFF"><label> <input name="state" type="text"/> </label></td> </tr> <tr> <th bgcolor="))" scope="row"> </th> <td bgcolor=""><label> <input type="submit" value="submit"/> <input type= "reset" value="Reset" name="reset" /> </label></td> </tr> </table> <input type="hidden" name="NM_insert" value="form1" /> </form> </div></div></div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/235665-files-upload-to-temp-folder-but-not-databse/#findComment-1211287 Share on other sites More sharing options...
Pikachu2000 Posted May 6, 2011 Share Posted May 6, 2011 `desc` is a MySQL reserved word, and as such you should either change the name of the field, or enclose desc in `backticks` whenever it is used as a reference to a field/table/database name. Note that `backticks` are not the same as 'single quotes' . . . Link to comment https://forums.phpfreaks.com/topic/235665-files-upload-to-temp-folder-but-not-databse/#findComment-1211288 Share on other sites More sharing options...
fugix Posted May 6, 2011 Share Posted May 6, 2011 i really need to memorize the reserved words.. :-\ Link to comment https://forums.phpfreaks.com/topic/235665-files-upload-to-temp-folder-but-not-databse/#findComment-1211289 Share on other sites More sharing options...
calvinschools Posted May 6, 2011 Author Share Posted May 6, 2011 Wow. did not know that. Trying it now. Link to comment https://forums.phpfreaks.com/topic/235665-files-upload-to-temp-folder-but-not-databse/#findComment-1211297 Share on other sites More sharing options...
calvinschools Posted May 6, 2011 Author Share Posted May 6, 2011 alright. The image is coming through to the db now but the name and state are not. Link to comment https://forums.phpfreaks.com/topic/235665-files-upload-to-temp-folder-but-not-databse/#findComment-1211300 Share on other sites More sharing options...
fugix Posted May 6, 2011 Share Posted May 6, 2011 if your state is coming from the form, wouldnt you need to have $_POST['state']; set up? i dont see if in your php code Link to comment https://forums.phpfreaks.com/topic/235665-files-upload-to-temp-folder-but-not-databse/#findComment-1211302 Share on other sites More sharing options...
calvinschools Posted May 6, 2011 Author Share Posted May 6, 2011 nevermind. fugix you were right about the state var and I just missed one "desc". Changed it to name and works like a charm. Thanks both. Next I want to put a comment system on each file that is uploaded so you may hear from me in a little bit. Link to comment https://forums.phpfreaks.com/topic/235665-files-upload-to-temp-folder-but-not-databse/#findComment-1211303 Share on other sites More sharing options...
Pikachu2000 Posted May 6, 2011 Share Posted May 6, 2011 I don't see where name and state are defined. Post the current revision of your code. Link to comment https://forums.phpfreaks.com/topic/235665-files-upload-to-temp-folder-but-not-databse/#findComment-1211307 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.