473,398 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

POST data & Refreshing

hi there! This is actually my first post over here.. I thought i'd register since most answers to my common problems that i google up turn up to be in this site.. however I have a problem myself now.

This is the source code: (PHP)

[php]if(mysql_error()) { // was there an error ?
//yes, issue warning
echo "Sorry, your comment was <b>not</b> added due to a database error!";
}
else { // no, print success and link
echo "<meta http-equiv='refresh' content='0'>";
}[/php]


what am i trying to do over here? basically i'm working on a site where visitors can post comments. Now since i'm using POST data, we all know that if a user refreshes the page it gets reposted. I know that your browser gives you an error, but let's face it -- the common user doesn't even know what POST data is, moreover what the error generated by the browser means.

now onto my problem. the code runs the mysql query with tha data that has been submitted in the comment form (after being validated) As shown in the source code, if there was a mysql error, it will display an error to the user. else it is supposed to refresh by echo'ing a meta tag. Just a couple of weeks ago, just after coding this thing, it worked flawlessly. But now it doesn't! I checked that it is actually refreshing by setting the number of seconds to 5 and checked that it is being refreshed.. but still the POST data is still there, because when I hit the refresh button, it displays the POST data error.

If you have any idea why this is happening please let me know.. cos it's driving me nuts, especially when I know that a couple of weeks ago it worked flawlessly :/

thanks guys,

ninuhadida.
Jul 16 '07 #1
8 3900
sorry guys, I just found out I posted this thing in the articles section! & I can't find a way to delete my post. If an admin can move this thing to the questions section / delete it, i would greatly appreciate it.

..sorry for being a nuisance!
Jul 16 '07 #2
pbmods
5,821 Expert 4TB
Heya, ninuhadida. Welcome to TSDN!

sorry guys, I just found out I posted this thing in the articles section! & I can't find a way to delete my post. If an admin can move this thing to the questions section / delete it, i would greatly appreciate it.

..sorry for being a nuisance!
No problem. Happens all the time.

Unfortunately.

But it's no biggie. I'll move your thread over to the correct spot so we can get some Experts right on it.
Jul 16 '07 #3
Is the comment bit in a frame or something? i.e. does the whole page not change anyway when they submit the comment? Or is it a facebook-style thing where it submits the post but the page itself doesn't change? If so, if the meta tag isn't working could you use javascript?

[HTML]<script type="text/javascript">
window.location="url_of_the_page.php"; //I think that's right!
</script>[/HTML]

I'm not hot on the intricacies of html, but doesn't a meta tag have to go in the <head> section?
Jul 17 '07 #4
Is the comment bit in a frame or something? i.e. does the whole page not change anyway when they submit the comment? Or is it a facebook-style thing where it submits the post but the page itself doesn't change? If so, if the meta tag isn't working could you use javascript?

[HTML]<script type="text/javascript">
window.location="url_of_the_page.php"; //I think that's right!
</script>[/HTML]

I'm not hot on the intricacies of html, but doesn't a meta tag have to go in the <head> section?
first off, thanks pbmods for moving my question. Sorry again for the unneeded trouble!

thanks adamalton for your reply. The page doesn't have any frames at all. the meta tag is printed in a <div> element. I know that it ain't valid xhtml since it's not in the <head> section. but i have a problem since the head section is already printed out before the the script goes into action and decides whether to refresh or not. What pisses me off here is that just 2 weeks ago it worked flawlessly & now that it isn't working, the page is still being refreshed = meaning that the meta tag is working, but the browser still keeps POST data.

about your little javascript snippet, I try to keep js code to the minimum as possible, since a simple turn off javascript for the browser options means a breakdown of how the website works.. and you mentioned that facebook (i don't use that site.. never even browsed it.. :/) adds your comments without the page being refresh at all. I would love to have something like that but I guess that means you need to have some kind of AJAX code, and I never written js/xml code myself. I certainly want to learn that but for now php/xhtml/css/mysql is already too much to take in at once!

thanks again,

regards

ninuhadida.
Jul 17 '07 #5
Yeah, I have no idea how facebook manages to post things without refreshing the page, and so far I've never needed to know....so I don't!

Don't get me started on w3c web standards and 'valid' html. Some of it is such pointless crap that just means your pages are full of useless code! (Like images having to have alt="".) GRRRRRRR!!!!!!!!

But anyway...if your meta tag is as you have it at the moment then you are telling your browser to refresh the page, i.e. reload it, and therefore send the POST data as well. But if you change it to this;
<meta http-equiv='refresh' content='0; url=http://www.yoursite.com/samepage.php'>"
then it will 'redirect' your browser, i.e. make it think it's going somewhere else, and so it shouldn't send the POST data again, even though you are just redirecting it to the page it's already on!
Jul 17 '07 #6
pbmods
5,821 Expert 4TB
Heya, ninuhadida.

The way I always tackle this problem is to do my backend stuff on a different page than my frontend stuff.

In other words, when the User submits the form on somepage.php, it goes to dbi/somepage.php. If the DBI ('DataBase Interaction') script hits an error, it redirects back to the form so that the User can fix his errors. On success, it redirects to the success page.
Jul 17 '07 #7
hey pbmods & adamalton,

thanks for your suggestions, i will try your suggestions tommorrow, since i had a long day today and i'm tired. hope i'll have time to code something tommorrow!

BTW, the meta tag that redirectes, i already used it in another section (the contact us) and it worked perfectly. so i hope it does the same with the comment thing.

will let you know about the outcome soon :)

thanks again,

regards,

ninu.
Jul 18 '07 #8
henryrhenryr
103 100+
Hello ninuhadida

Quick note about the alt="" concern - if your visitor is blind and can't see your picture then their screen-reader should be able to read out the alt attribute - ie at least get a better idea of your content. I think it helps for SEO too.

For the refresh problem - I think two methods already mentioned - handle forms on a seperate page (ie don't use :
Expand|Select|Wrap|Line Numbers
  1. action="<?php echo $_SERVER['PHP_SELF']?>"
  2.  
). And you can keep track of form submissions in your database by having it write a unique number to a table and check that number on every submit of the form.

My method is to use sessions (also works with cookies). You have the page check the form, run DB stuff then save the data, messages, whatever in the $_SESSION array. Then you use
Expand|Select|Wrap|Line Numbers
  1. <?php header('Location: www.mysite.com/page.php'); exit(); ?>
to reload the page to itself a second time (make sure you use absolute link in header() and put exit() to prevent the rest of the script running).

When this page reloads for the second time, the $_POST data is gone so a browser refresh won't re-submit it!
Jul 19 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Nomen Nescio | last post by:
can anyone be so kind as to look at http://www.mysolution.ws/HYPOCRITE.php and let me know why it isn't passing the form data to http://www.mysolution.ws/insertHYPOCRITES.php for the most...
11
by: brendan | last post by:
Sorry this isnt a cross post .. i just didnt get any help from alt.php. I have a website which utilises post forms for navigation in some areas. Problem is, when *some* users hit the BACK button...
2
by: Dave | last post by:
Greetings. Ive been trying to figure out how I can write to a file from an HTTP post while it is being uploaded. So far ive realized that my script isn't getting the data until the browser is...
3
by: Troy | last post by:
Hello- I have a website that uses a custom built webserver to serve the pages. (Please don't ask me why my boss had his own web server written). I am displaying a log of information that is an...
4
by: k.mitz | last post by:
Hi, I have a PHP application that allows users to generate a .pdf report of their database content. Normally, I've had to refresh a page to call the script to generate the report, so there's a...
1
by: Jennyfer J Barco | last post by:
Hello I have a datagrid and a linkbuttom in the datagrid that says Picture, every time I click on the link "Picture" my program opens a popup window showing a picture of the item the selected and...
15
by: tmax | last post by:
PHP Pros: I have a simple html form that submits data to a php script, which processes it, and then redisplays the same page, but with a "thank you" message in place of the html form. This is...
23
by: Bjorn | last post by:
Hi. Every time i post data in a form the contents are being checked for validity. When i click the back-button, all data is gone and i have to retype it. It's obvious that only a few or none of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.