sandbudd Posted November 24, 2009 Share Posted November 24, 2009 I am getting an error when trying to do an update on a image...here is the error i am getting... Notice: Undefined index: header in /update_display.php on line 25 File not uploaded. here is line 25 if (is_uploaded_file ($_FILES['header']['tmp_name'])) please help I am desperate. <?php error_reporting(E_ALL); ini_set('display_errors', '1'); ?> <?php // Connect database. $host=""; // Host name. $db_user=""; // MySQL username. $db_password=""; // MySQL password. $database=""; // Database name. mysql_connect($host,$db_user,$db_password); mysql_select_db($database); // ***** This part will process when you Click on "Submit" button ***** // Check, if you clicked "Submit" button if (isset ($_POST['Submit'])) { if (!empty ($_POST['header'])) { if (is_uploaded_file ($_FILES['header']['tmp_name'])) { //This is the directory where images will be saved $target = 'uploaded_files/'.$_FILES['header']['name']; //This gets all the other information from the form $header = $_FILES['header']['name']; //Writes the photo to the server move_uploaded_file ($_FILES['header']['tmp_name'], $target) or die ('File not moved.'); } else die ('File not uploaded.'); } $_POST = array_map ('mysql_real_escape_string', $_POST); $id = $_POST['id']; $header = $_POST['header']; $header2 = $_POST['header2']; $header3 = $_POST['header3']; $footer = $_POST['footer']; $footer2 = $_POST['footer2']; $footer3 = $_POST['footer3']; // Do update statement. $sql = mysql_query(" update `ads` set `header`='{$header}', `header2`='{$header2}', `header3`='{$header3}', `footer`='{$footer}', `footer2`='{$footer2}', `footer3`='{$footer3}' where `id`='{$id}' ") or trigger_error (mysql_error()); if ($sql) { header("location:display.php"); exit (0); } } else { // ************* End update part ************* // *** Select data to show on text fields in form. *** // Get id parameter (GET method) $id = ((isset ($_GET['id']) && (ctype_digit ($_GET['id']))) ? mysql_real_escape_string ($_GET['id']) : ''); if (!empty ($id)) { // Get records in all columns from table where column id equal in $id and put it in $result. $result = mysql_query(" select * from ads where id='".$id."' "); // Split records in $result by table rows and put them in $row. $row = mysql_fetch_array ($result); // Close database connection. mysql_close(); } ?> <!-- END OF PHP CODES AND START HTML TAGS --> <html> <script type="text/javascript"> <!-- function MM_goToURL() { //v3.0 var i, args=MM_goToURL.arguments; document.MM_returnValue = false; for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'"); } //--> </script> <body> <!-- set this form to POST method and target this form to itself ($PHP_SELF;)--> <form id="form1" name="form1" method="post" action=""> <input type="hidden" name="id" value="<?php echo $id; ?>" /> <input name="header" type="file" id="header" value="<?php echo $row['header']; ?>" size="50" /> <table width="707" border="1" cellpadding="3" cellspacing="0" class="appfields"> <tr> <td width="25%"><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Header</span></td> <td width="25%"> </td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Header 2<br> </span></td> <td><input name="header2" type="text" id="header2" value="<?php echo $row['header2']; ?>"/></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Header 3<strong><br> </strong></span></td> <td><strong> <input name="header3" type="text" id="header3" value="<?php echo $row['header3']; ?>"/> </strong></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Footer<strong><br> </strong></span></td> <td><strong> <input name="footer" type="text" id="footer" value="<?php echo $row['footer']; ?>"/> </strong></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Footer 2<br> </span></td> <td><strong> <input name="footer2" type="text" id="footer2" value="<?php echo $row['footer2']; ?>"/> </strong></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Footer 3<br> </span></td> <td><strong> <input name="footer3" type="text" id="footer3" value="<?php echo $row['footer3']; ?>"/> </strong></td> </tr> </table> <br> <br> <table width="707" border="0" cellspacing="0" cellpadding="0"> <tr> <td><input type="submit" name="Submit" value="Submit" /></td> <td><div align="right"> <input name="Cancel" type="submit" id="Cancel" onClick="MM_goToURL('parent','display.php');return document.MM_returnValue" value="Cancel"> </div></td> </tr> </table> </form> </body> </html> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/ Share on other sites More sharing options...
sandbudd Posted November 24, 2009 Author Share Posted November 24, 2009 added this but didn't make a difference <form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/#findComment-964462 Share on other sites More sharing options...
mikesta707 Posted November 24, 2009 Share Posted November 24, 2009 you should just leave the action attribute out if you want to submit the form to itself. action="<?php echo $_SERVER['PHP_SELF']; ?>" leaves a vulnerability to XSS attacks in your form. Try doing a print_r on the POST array, and see what it has in it. That will probably help locate where the problem is Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/#findComment-964463 Share on other sites More sharing options...
sandbudd Posted November 24, 2009 Author Share Posted November 24, 2009 I just add this echo print_r($_POST); correct? Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/#findComment-964469 Share on other sites More sharing options...
Alex Posted November 24, 2009 Share Posted November 24, 2009 There's no need for the echo as print_r prints the results by default. Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/#findComment-964471 Share on other sites More sharing options...
sandbudd Posted November 24, 2009 Author Share Posted November 24, 2009 alexWD don't mean to sound like an idiot do I put that in any particle place or just at the end of the code? or could you give me an example to insure that I do it correctly Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/#findComment-964473 Share on other sites More sharing options...
Alex Posted November 24, 2009 Share Posted November 24, 2009 Right above: if (isset ($_POST['Submit'])) { Would probably be best, so that it's sure to run. Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/#findComment-964474 Share on other sites More sharing options...
sandbudd Posted November 24, 2009 Author Share Posted November 24, 2009 this is what I got Array ( [id] => 1 [header] => 025.JPG [header2] => test [header3] => 100_2343.JPG [footer] => 12.gif [footer2] => [footer3] => [submit] => Submit ) Notice: Undefined index: header in /update_display.php on line 27 File not uploaded. Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/#findComment-964477 Share on other sites More sharing options...
Alex Posted November 24, 2009 Share Posted November 24, 2009 Oh wait , you should be print_r'ing the $_FILES array, since that's the one that's giving you trouble. But I think I found your problem.. You forgot to set an enctype in your form. Inside your <form > element add enctype="multipart/form-data". Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/#findComment-964478 Share on other sites More sharing options...
sandbudd Posted November 24, 2009 Author Share Posted November 24, 2009 Well that stopped the errors but it is not uploading the file nor populating the db? Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/#findComment-964482 Share on other sites More sharing options...
Alex Posted November 24, 2009 Share Posted November 24, 2009 Do you get any of your error messages like 'File not moved'? Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/#findComment-964483 Share on other sites More sharing options...
sandbudd Posted November 24, 2009 Author Share Posted November 24, 2009 the text fields populate the database but not the upload Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/#findComment-964484 Share on other sites More sharing options...
sandbudd Posted November 24, 2009 Author Share Posted November 24, 2009 no AlexWD I do not...redirects like it should...it is delaying as if it is uploading the file when looked it is not there? Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/#findComment-964485 Share on other sites More sharing options...
sandbudd Posted November 24, 2009 Author Share Posted November 24, 2009 oh oh I think AlexWD bailed on me...lol Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/#findComment-964487 Share on other sites More sharing options...
Alex Posted November 24, 2009 Share Posted November 24, 2009 No, I'm still here Well, your error handling indicates that it did upload successfully.. I know this might sound stupid.. but can you double check to make sure it wasn't uploaded? (Perhaps refresh FTP if that's what you're using to view the directory). Edit: It might be because of this: if (!empty ($_POST['header'])) You should really be checking $_FILES['header'] Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/#findComment-964488 Share on other sites More sharing options...
sandbudd Posted November 24, 2009 Author Share Posted November 24, 2009 I thought of that and checked the db directly and then went to the webshell rather than the ftp and it was not in either place Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/#findComment-964490 Share on other sites More sharing options...
sandbudd Posted November 24, 2009 Author Share Posted November 24, 2009 how do i edit this if (!empty ($_POST['header'])) Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/#findComment-964491 Share on other sites More sharing options...
sandbudd Posted November 24, 2009 Author Share Posted November 24, 2009 okay commented out that line and it uploaded it to the server but did not populate the database...getting closer Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/#findComment-964492 Share on other sites More sharing options...
Alex Posted November 24, 2009 Share Posted November 24, 2009 Any errors messages? Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/#findComment-964493 Share on other sites More sharing options...
sandbudd Posted November 24, 2009 Author Share Posted November 24, 2009 no sir redirects like it is supposed to...like I said it is writing to server just need it to display it in the database? Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/#findComment-964495 Share on other sites More sharing options...
sandbudd Posted November 24, 2009 Author Share Posted November 24, 2009 now if I try one of the text fields I get this File not uploaded. Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/#findComment-964499 Share on other sites More sharing options...
sandbudd Posted November 24, 2009 Author Share Posted November 24, 2009 but if I uncomment it out it won't upload the file but will populate the database with the text fields Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/#findComment-964504 Share on other sites More sharing options...
sandbudd Posted November 24, 2009 Author Share Posted November 24, 2009 any ideas? we are so close. Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/#findComment-964755 Share on other sites More sharing options...
mrMarcus Posted November 24, 2009 Share Posted November 24, 2009 No, I'm still here Well, your error handling indicates that it did upload successfully.. I know this might sound stupid.. but can you double check to make sure it wasn't uploaded? (Perhaps refresh FTP if that's what you're using to view the directory). Edit: It might be because of this: if (!empty ($_POST['header'])) You should really be checking $_FILES['header'] ya, my bad (i wrote this code for him). should be: if (!empty ($_FILES['header'])) EDIT: where do you stand now. what is the script doing and not doing. give a recap. Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/#findComment-964764 Share on other sites More sharing options...
sandbudd Posted November 24, 2009 Author Share Posted November 24, 2009 Hello mrMarcus, This does upload the file but does not populate the database? Here is the code I now have. <?php error_reporting(E_ALL); ini_set('display_errors', '1'); ?> <?php // Connect database. $host="mysql509.hostexcellence.com"; // Host name. $db_user=""; // MySQL username. $db_password=""; // MySQL password. $database=""; // Database name. mysql_connect($host,$db_user,$db_password); mysql_select_db($database); // ***** This part will process when you Click on "Submit" button ***** // Check, if you clicked "Submit" button if (isset ($_POST['Submit'])) { if (!empty ($_FILES['header'])) { if (is_uploaded_file($_FILES['header']['tmp_name'])) { //This is the directory where images will be saved $target = 'images/'.$_FILES['header']['name']; //This gets all the other information from the form $header = $_FILES['header']['name']; //Writes the photo to the server move_uploaded_file ($_FILES['header']['tmp_name'], $target) or die ('File not moved.'); } else die ('File not uploaded.'); } $_POST = array_map ('mysql_real_escape_string', $_POST); $id = $_POST['id']; $header = $_POST['header']; $header2 = $_POST['header2']; $header3 = $_POST['header3']; $footer = $_POST['footer']; $footer2 = $_POST['footer2']; $footer3 = $_POST['footer3']; // Do update statement. $sql = mysql_query(" update `ads` set `header`='{$header}', `header2`='{$header2}', `header3`='{$header3}', `footer`='{$footer}', `footer2`='{$footer2}', `footer3`='{$footer3}' where `id`='{$id}' ") or trigger_error (mysql_error()); if ($sql) { header("location:display.php"); exit (0); } } else { // ************* End update part ************* // *** Select data to show on text fields in form. *** // Get id parameter (GET method) $id = ((isset ($_GET['id']) && (ctype_digit ($_GET['id']))) ? mysql_real_escape_string ($_GET['id']) : ''); if (!empty ($id)) { // Get records in all columns from table where column id equal in $id and put it in $result. $result = mysql_query(" select * from ads where id='".$id."' "); // Split records in $result by table rows and put them in $row. $row = mysql_fetch_array ($result); // Close database connection. mysql_close(); } ?> <!-- END OF PHP CODES AND START HTML TAGS --> <html> <script type="text/javascript"> <!-- function MM_goToURL() { //v3.0 var i, args=MM_goToURL.arguments; document.MM_returnValue = false; for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'"); } //--> </script> <body> <!-- set this form to POST method and target this form to itself ($PHP_SELF;)--> <form id="form1" name="form1" method="post" action="" enctype="multipart/form-data"> <input type="hidden" name="id" value="<?php echo $id; ?>" /> <input name="header" type="file" id="header" value="<?php echo $row['header']; ?>" size="50" /> <table width="707" border="1" cellpadding="3" cellspacing="0" class="appfields"> <tr> <td width="25%"><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Header</span></td> <td width="25%"> </td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Header 2<br> </span></td> <td><input name="header2" type="file" id="header2" value="<?php echo $row['header2']; ?>"/></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Header 3<strong><br> </strong></span></td> <td><strong> <input name="header3" type="text" id="header3" value="<?php echo $row['header3']; ?>"/> </strong></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Footer<strong><br> </strong></span></td> <td><strong> <input name="footer" type="text" id="footer" value="<?php echo $row['footer']; ?>"/> </strong></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Footer 2<br> </span></td> <td><strong> <input name="footer2" type="text" id="footer2" value="<?php echo $row['footer2']; ?>"/> </strong></td> </tr> <tr> <td><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14">Footer 3<br> </span></td> <td><strong> <input name="footer3" type="text" id="footer3" value="<?php echo $row['footer3']; ?>"/> </strong></td> </tr> </table> <br> <br> <table width="707" border="0" cellspacing="0" cellpadding="0"> <tr> <td><input type="submit" name="Submit" value="Submit" /></td> <td><div align="right"> <input name="Cancel" type="submit" id="Cancel" onClick="MM_goToURL('parent','display.php');return document.MM_returnValue" value="Cancel"> </div></td> </tr> </table> </form> </body> </html> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/182734-getting-error-on-submit/#findComment-964774 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.