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 Quote Link to comment 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 Quote Link to comment 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) Quote Link to comment Share on other sites More sharing options...
php_beginner_83 Posted September 17, 2009 Author Share Posted September 17, 2009 Thanks. Worked a treat 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.