gibsonfan Posted June 14, 2010 Share Posted June 14, 2010 Hi, I'm having an issue uploading this image into my server and updating the table row where is stored. Here is my code, right now, all the fields are being inserted into the database with the exception of the image field. the image comes from a field form <input type="file" name="image"> the php that does the submit is: <?php include ('../../includes/db_fns.php'); $conn = db_connect(); $time = time(); if ( ($html) && (dirname($html_type) == "text") ) { $fp = fopen($html, "r"); $story_text = addslashes(fread($fp, filesize($html))); fclose($fp); } $sql = "insert into events (location, type, created, modified, published) values ('$_POST[location]', '$_POST[type]', '$time', '$time', '$time')"; $result = mysql_query($sql, $conn); if (!$result) { print "There was an error in the database while executing <PRE>$sql</PRE>"; print mysql_error(); exit; } if ( ($_POST[image]) && ($_POST[image] != "none") ) { echo "<br>You have an image uploaded<br>"; if (!$story) $story = mysql_insert_id(); $type = basename($image_type); switch ($type) { case "jpeg": case "pjpeg": $fileurl = "../../../../images/events/$story.jpg"; copy ($image, $fileurl); $filename = "../../../../images/events/$story.jpg"; $sql = "update events set image = '$filename' where id = $story"; $result = mysql_query($sql, $conn); break; default: print "Invalid image format: $image_type"; } } else { echo "<br>You didn't have an image to upload<br>"; } echo "Done"; ?> right now, all the fields are being inserted into the database with the exception of the image field. thanks for helping me I appreciate feedback since I'm learning this Link to comment https://forums.phpfreaks.com/topic/204740-image-upload-submit/ Share on other sites More sharing options...
kenrbnsn Posted June 14, 2010 Share Posted June 14, 2010 Can you post the form that you're using? Link to comment https://forums.phpfreaks.com/topic/204740-image-upload-submit/#findComment-1071912 Share on other sites More sharing options...
gibsonfan Posted June 14, 2010 Author Share Posted June 14, 2010 Here is the form: <html> <head> <title>Create Events</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#CCCCCC"> <div align="center"><img src="../images/topheader.jpg" width="1000" height="120"> </div> <?php include('validador.inc'); ?> <FORM ACTION="events-submit.php" METHOD=POST ENCTYPE="multipart/form-data" name="FrontPage_Form1" id="FrontPage_Form1" onsubmit="return FrontPage_Form1_Validator(this)" language="JavaScript"> <table width="800" border="0" cellspacing="5" cellpadding="5" align="center" bgcolor="#FFFFFF"> <tr> <td colspan="2" height="13"> <div align="center"> <p><font face="Arial, Helvetica, sans-serif" size="4">Create Eevnts</font> </p> <p><font face="Arial, Helvetica, sans-serif" size="2"><a href="home.html">Back</a></font></p> </div> </td> </tr> <tr> <td> <div align="right"><font face="Arial, Helvetica, sans-serif" size="2">Location</font></div> </td> <td> <select name="location"> <option value="" selected>Select</option> <option value="Miami">Miami</option> <option value="NY City">NY City</option> <option value="London">London</option> <option value="Paris">Paris</option> </select> </td> </tr> <tr> <td> <div align="right"><font face="Arial, Helvetica, sans-serif" size="2">Type</font></div> </td> <td> <select name="type"> <option value="" selected>Select</option> <option value="Online">Online</option> <option value="Onsite">Onsite</option> </select> </td> </tr> <tr> <td> <div align="right"><font face="Arial, Helvetica, sans-serif" size="2">Image</font></div> </td> <td> <input type="file" name="image"> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> <input type="submit" name="Submit" value="Submit"> </td> </tr> </table> <p> </p> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/204740-image-upload-submit/#findComment-1071942 Share on other sites More sharing options...
kenrbnsn Posted June 14, 2010 Share Posted June 14, 2010 You will find the uploaded file information in the $_FILES array not the $_POST array. Ken Link to comment https://forums.phpfreaks.com/topic/204740-image-upload-submit/#findComment-1071945 Share on other sites More sharing options...
gibsonfan Posted June 14, 2010 Author Share Posted June 14, 2010 I ran phpinfo and this is what I got _FILES["image"] Array ( [name] => event-image.jpg [type] => image/jpeg [tmp_name] => /tmp/php4TRmGR [error] => 0 => 94417 ) I fixed $_POST to $_FILE . still not getting neither an upload nor insert in the database Link to comment https://forums.phpfreaks.com/topic/204740-image-upload-submit/#findComment-1071953 Share on other sites More sharing options...
gibsonfan Posted June 14, 2010 Author Share Posted June 14, 2010 woops, FILES not FILE ok, now I'm getting an Invalid image format error.... maybe case jpg instead of pjpeg ? Link to comment https://forums.phpfreaks.com/topic/204740-image-upload-submit/#findComment-1071956 Share on other sites More sharing options...
gibsonfan Posted June 14, 2010 Author Share Posted June 14, 2010 fixed , wrong path in the server. SOLVED Link to comment https://forums.phpfreaks.com/topic/204740-image-upload-submit/#findComment-1072019 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.