Jump to content

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)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.