Go Back   SitePoint Forums > Forum Index > Program Your Site > PHP
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old Oct 29, 2009, 01:16   #1
hoxr.com
SitePoint Member
 
hoxr.com's Avatar
 
Join Date: Oct 2009
Posts: 6
Help on form reload problem

Dear all, I am writing a very simple code which involve HTML, PHP and Mysql, here is what I have done and the Help I need:

the 1st file: index.php
PHP Code:

<!DOCTYPE html>
<html lang="en">
<head>  
<title>Testing Site <?php echo $_GET[id];?></title>
</head>
<body>
    <?php
    
if($_GET[id]){
     require_once(
$_GET[id].'.html.php');
    }else{
     require_once(
'bb.html.php');
    }
    
?>
         <?php require_once('comments.php'); ?>
          <a href = 'index.php?id=aa'> goto aa </a><br/>
    <a href = 'index.php?id=bb'> goto bb </a>
</body>
</html>
the 2nd file aa.html.php
PHP Code:

<p>Hi...I am aa</p> 

the 3rd file bb.html.php
PHP Code:

<p>Hi...I am bb</p> 

the 4th file comments.php
PHP Code:

<form name="form" method="post" action="./index.php?id=<?php echo $_GET[id];?>">
    Name:<input name="user" type="text" size=20 id="user"><br>
    Comments:<input name="comments" type="text" size=30 id="comments"><br>
    <input type="submit" size=20 value="submit"><br>
</form>
<?php
//connect db
$conn = mysql_connect("localhost","root","") or die ("cannot connection");
mysql_select_db("mydb",$conn) or die ("cannot open db");
//if post, then start process data
if ($_POST){
$user = $_POST["user"];
$comments = $_POST["comments"];
$query = "INSERT INTO comments (user, comments) VALUES('$user','$comments')";  
$result = mysql_query($query);
}
//no matter, loop and Show all record to the user
$selectall = "select * from comments";  
$showall = mysql_query($selectall);
while (
$row = mysql_fetch_array($showall)){
echo
'user:'.$row[user].'comments:'.$row['comments'].'<br />';
}
?>
the DB/table related:
I have a DB named mydb in MySQL, which have on table, comments:
Code:
CREATE TABLE IF NOT EXISTS `comments` (
  `user` varchar(30) NOT NULL,
  `comments` varchar(80) DEFAULT NULL,
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 ;
run the scripts:

load index.php after you creat the table using above sql..and jump between index.php?id=aa and index.php?id=bb, and u can submit the form and see the comments imm showing after ur submit...

it looks great, BUT

My problem:

if user click the reload or refresh in IE, there is a warning window popup, and remind user not re-submit, but if some user really resubmit, my table will have duplicate record...

HELP is need, with no change on my entire scripts stucture, means I must use above ?id=$_GET(id) tech to jumping between the aa file and bb file, and I must include both form and insert process in same file, the user expriense should not been impact........

what I need is while user click the reload, no pop window, no duplicate record been insert

thanks in advance for what ever help you can provide...but I already try to search solution, so, pls don't just give me very generical hints..

I am total lost....need real help
hoxr.com is offline   Reply With Quote
 

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 08:42.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved