Thanks flabbyrabbit,
the redirecting method works especially if you are posting like entering your name etc, but when you are uploading it is a little different.
I tried it for both and it seems to be working fine for posting when I use this code
- Code: Select all
header("Location: " . $_SERVER['PHP_SELF']);
after the insert to the database code. After doing this when I refresh, it doesn't post what was posted before twice. and when I got rid of this code, it does.
But when I do this for picture upload, it is a bit more difficult to do I guess because the complexity of the code.
here is why:
assume the form is created, database is created and connected. Here is the sample code:
- Code: Select all
if(isset($_POST['submit'])){
$caption=$_POST['caption'];
mysql_query("insert into upload3(photo, caption) values('$fileName','$caption')");
header("Location: " . $_SERVER['PHP_SELF']);
}
//if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
move_uploaded_file($_FILES['uploaded']['tmp_name'], $target);
//{
echo "The file ".basename( $_FILES['uploaded']['name']). " has been uploaded<br>";
//}
//else
//{
//echo "Sorry, there was a problem uploading your file.";
//}
$data = mysql_query("SELECT * FROM upload3") or die(mysql_error());
while($info = mysql_fetch_array( $data ))
{
Echo"$info[pid]";
Echo "<img src=$dir".$info[photo]." width=200 height=200> <br>";
print"$info[photo]";
}
if I use if(isset($_POST['submit'])){
and have --->}
all the way at the end of the program then header("Location: " . $_SERVER['PHP_SELF']); doesn't work, but if I have it right after inserting the values into the database then I
CAN'T upload the pix and view the pic in my browser like how I have the code right now posted.
So do you know how I can solved this?
thanks --