Jump to content

[SOLVED] How to reload a form after submitting


php_beginner_83

Recommended Posts

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

.....
.....
// 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

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)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.