batstanggt Posted August 8, 2011 Share Posted August 8, 2011 Hey guys Im currently using this script to upload pictures to a table in my database. However it doesnt seem to be working from the standpoint that after submitting the form nothing appears to be happening, and certianly no inserting is going on (when I check the table in phpMyadmin its empty). Anyways I was hoping someone here may be able to tell me what im doing wrong. </head> <body> <h2>Please Choose a File and click Submit</h2> <form enctype="multipart/form-data" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="99999999" /> <div>Title: <input name="pic_name" type="text" /></div> <div>Description: <input name="pic_desc" type="text" /></div> <div>Picture to Upload<input name="picture" type="file" /></div> <div>yes or no question </div> <div>Yes: <input name="group" type="radio" value="y" /> No: <input name="group" type="radio" value="n" /> </div> <div><input type="submit" value="Submit" /></div> </form> <?php /*** check if a file was submitted ***/ if(!isset($_FILES['picture'])) { echo '<p>Please select a file</p>'; } else { try { upload(); /*** give praise and thanks to the php gods ***/ echo '<p>Thank you for submitting</p>'; } catch(Exception $e) { echo '<h4>'.$e->getMessage().'</h4>'; } } ?> <?php /** * * the upload function * * @access public * * @return void * */ function upload(){ /*** check if a file was uploaded ***/ if(is_uploaded_file($_FILES['picture']['tmp_name']) && getimagesize($_FILES['picture']['tmp_name']) != false) { /*** get the image info. ***/ $size = getimagesize($_FILES['picture']['tmp_name']); /*** assign our variables ***/ $type = $size['mime']; $imgfp = fopen($_FILES['picture']['tmp_name'], 'rb'); $size = $size[3]; $pic_name = $_FILES['picture']['pic_name']; $pic_desc = $_POST['pic_desc']; $sixval = $_POST['group']; $maxsize = 99999999; /*** check the file is less than the maximum file size ***/ if($_FILES['picture']['size'] < $maxsize ) { /*** connect to db ***/ $dbh = new PDO("mysql:host=localhost;dbname=dbname", 'mysqlusername', 'mysqlpassword'); /*** set the error mode ***/ $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); /*** our sql query ***/ $stmt = $dbh->prepare("INSERT INTO mypictures (pic_type , picture, pic_size, pic_name, pic_desc, sixval) VALUES (? ,?, ?, ?, ?, ?)"); /*** bind the params ***/ $stmt->bindParam(1, $type); $stmt->bindParam(2, $imgfp, PDO::PARAM_LOB); $stmt->bindParam(3, $size); $stmt->bindParam(4, $pic_name); $stmt->bindParam(5, $pic_desc); $stmt->bindParam(6, $sixval); /*** execute the query ***/ $stmt->execute(); } else { /*** throw an exception is image is not of type ***/ throw new Exception("File Size Error"); } } else { // if the file is not less than the maximum allowed, print an error throw new Exception("Unsupported Image Format!"); } } ?> </body></html> Any suggestions? -SB Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 8, 2011 Share Posted August 8, 2011 please turn on your error reporting and post the exact error here. thank you. Quote Link to comment Share on other sites More sharing options...
batstanggt Posted August 8, 2011 Author Share Posted August 8, 2011 How do I turn error reporting on ? And assuming that it is a piece of script where do I place it? Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 8, 2011 Share Posted August 8, 2011 place at beginning of file ini_set('display_errors', 'On'); ini_set('display_startup_errors', 'On'); error_reporting(-1); Quote Link to comment Share on other sites More sharing options...
batstanggt Posted August 8, 2011 Author Share Posted August 8, 2011 Thanks buddy. Ill try that as soon as I get home from work in approx 4 hours. If you wouldnt mind checking back around then, and Ill have the error message that I am getting posted and maybe you could help me out a lil bit more. Thank you again. -SB Quote Link to comment Share on other sites More sharing options...
batstanggt Posted August 9, 2011 Author Share Posted August 9, 2011 OK so i tried inserting that and its doing the same thing. Screen just goes blank. Could it have something to do with the : or the / in the file name when using the browse button? -SB Quote Link to comment Share on other sites More sharing options...
batstanggt Posted August 9, 2011 Author Share Posted August 9, 2011 C'mon guys work with the kid.... -SB Quote Link to comment Share on other sites More sharing options...
batstanggt Posted August 9, 2011 Author Share Posted August 9, 2011 Theres seriously noone here that knows how to rectify this situation? -SB Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 9, 2011 Share Posted August 9, 2011 this: $stmt = $dbh->prepare("INSERT INTO mypictures (pic_type , picture, pic_size, pic_name, pic_desc, sixval) VALUES (? ,?, ?, ?, ?, ?)"); is obviously incomplete. you need to put in your variables instead of the question marks. Quote Link to comment Share on other sites More sharing options...
batstanggt Posted August 10, 2011 Author Share Posted August 10, 2011 Guys i got it to throw an error! here it is ... Notice: Undefined index: pic_name in /var/www/newpictureupload.php on line 41 Thank you for submitting What does this mean ? Quote Link to comment Share on other sites More sharing options...
jcbones Posted August 10, 2011 Share Posted August 10, 2011 this: $stmt = $dbh->prepare("INSERT INTO mypictures (pic_type , picture, pic_size, pic_name, pic_desc, sixval) VALUES (? ,?, ?, ?, ?, ?)"); is obviously incomplete. you need to put in your variables instead of the question marks. He does, through the bindParam() function inside of the PDO class. Quote Link to comment Share on other sites More sharing options...
batstanggt Posted August 10, 2011 Author Share Posted August 10, 2011 figured it out. in the form i was $_post'ing the pic_name and i was also trying to send $_files['pic_name'] to the same pic_name in the table. Thanks for everyones help will that error script work on every php file? 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.