php_beginner_83 Posted September 17, 2009 Share Posted September 17, 2009 Hi All I need some help with how to reload a webpage after submitting a form. My page is being used to add information to a database. Once the user has clicked submit, the info is added and then a blank screen is displayed. I would like the upload form to display again. Can anyone help me with this please. This is my code so far... <div id="image"> <h3>Add New Image</h3></br> <form action="uploadPictures.php" method="post"> Image Description:<br/> <textarea cols="50" rows="4" name="imageDescription"> </textarea><br/> Path:<br/> <input type="file" name="path"/><br/> Select Album:<br/> <?php $sql = "SELECT ID, Title FROM albums"; $result = mysql_query($sql) or die(mysql_error()); echo '<select name="albumMenu">'; while($row = mysql_fetch_assoc($result)) { printf('<option value="%s">%s</option>', htmlspecialchars($row['ID']), htmlspecialchars($row['Titles'])); } echo '</select>'; ?> <br/><br/> <input type="submit" value="Add New Image"/> </form> </div> and this is uploadPictures.php... ..... ..... // get last ID in 'pictures' table $result = mysql_query("SELECT * FROM pictures ORDER BY ID desc limit 1") or die('order images error'); $row = mysql_fetch_array($result); $newID = $row['ID'] + 1; // insert new image into 'pictures' table $insert = "INSERT INTO pictures (ID, Description, Path) VALUES ($newID, '{$_POST['imageDescription']}', '{$_POST['path']}')"; mysql_query($insert) or die(mysql_error()); // insert record into 'pics_in_albums' table $insert2 = "INSERT INTO pics_in_album (PicID, AlbumID) " . "VALUES ($newID, '{$_POST['albumMenu']}')"; mysql_query($insert2) or die('insert into pics_in_album errors'); Thank you Link to comment https://forums.phpfreaks.com/topic/174633-solved-how-to-reload-a-form-after-submitting/ Share on other sites More sharing options...
mikesta707 Posted September 17, 2009 Share Posted September 17, 2009 ..... ..... // get last ID in 'pictures' table $result = mysql_query("SELECT * FROM pictures ORDER BY ID desc limit 1") or die('order images error'); $row = mysql_fetch_array($result); $newID = $row['ID'] + 1; // insert new image into 'pictures' table $insert = "INSERT INTO pictures (ID, Description, Path) VALUES ($newID, '{$_POST['imageDescription']}', '{$_POST['path']}')"; mysql_query($insert) or die(mysql_error()); // insert record into 'pics_in_albums' table $insert2 = "INSERT INTO pics_in_album (PicID, AlbumID) " . "VALUES ($newID, '{$_POST['albumMenu']}')"; mysql_query($insert2) or die('insert into pics_in_album errors'); header("Location: mypage.php");//this redirects Link to comment https://forums.phpfreaks.com/topic/174633-solved-how-to-reload-a-form-after-submitting/#findComment-920326 Share on other sites More sharing options...
kratsg Posted September 17, 2009 Share Posted September 17, 2009 There are three methods: 1: On uploadPictures.php, you use include('form_page.php') or w/e to include the form again upon successful submission. 2: On uploadPictures.php, you use a header('form_page.php') or w/e to redirect the page back to the form again. (see previous post) 3: You use a conditional and have it post to the same page.. see below: if(isset($_POST)){ //may not want to use this exact conditional, but something similar to check if they posted the form //run uploadPictures.php code in this section } //include your form here (IE: if they posted or didn't post, the form shows) Link to comment https://forums.phpfreaks.com/topic/174633-solved-how-to-reload-a-form-after-submitting/#findComment-920328 Share on other sites More sharing options...
php_beginner_83 Posted September 17, 2009 Author Share Posted September 17, 2009 Thanks. Worked a treat Link to comment https://forums.phpfreaks.com/topic/174633-solved-how-to-reload-a-form-after-submitting/#findComment-920351 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.