SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Refreshing DATA

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    United Kingdom
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool Refreshing DATA

    Hello,
    I have a PHP script which collects asset information from my company. When the script is run and someone enters the information they press Submit and all works ok. It brings up another page saying that the information was successfully entered. However if you now press refresh, it still only displays the successful page, and then enteres the information twice. The only way to go back and enter the data is to close the browser and then reopen it and type the link again. then it will come up with the data entry page. Can anyone tell me how I can make it so that when the user refreshes the page, it allows them to enter more information. I am still new to PHP and so I dont really understand what this doing wrong.


    Here is the script.



    PHP Code:
     <html>

        <head>
            <title>Asset Register</title>
            

    <BODY>
    <?php
    if ( !isset( $_POST['submit'] ) )
    {
    echo <<< EOF
    <FORM ACTION="{$_SERVER['PHP_SELF']}" METHOD="post">
    <center><TABLE width = "500">
    <TR>
    <TD ALIGN="LEFT" VALIGN="TOP"  COLSPAN=2>
    <h1>EMEA Asset Register</h1><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
    Please enter the required(*) information so that we can keep a record of your data.  <br><br>
    <br>
         Please DO NOT ENTER ANY PRINTERS ETC, ONLY LAPTOPS and Pc's <BR>

    <tr>
    <td colspan="2" valign="middle" bgcolor="#0066cc"><font color="white"><b><img src="http://localhost/meet/images/spacer.gif" height="10" width="10"><br>
    <img src="http://localhost/meet/images/spacer.gif" height="2" width="20">Your Details</b></font></td>
                        </tr></TD>
    </TR>
    <TR>
    <TD ALIGN="LEFT" VALIGN="TOP"  COLSPAN=1>
    <div align="right">*Full Name:</div></TD>
    <TD ALIGN="LEFT" VALIGN="TOP"  COLSPAN=1>
    <INPUT TYPE=TEXT NAME="fullname" VALUE="" SIZE="27" MAXLENGTH="30">&nbsp;</TD>
    </TR>
    <TR>
    <TD ALIGN="LEFT" VALIGN="TOP"  COLSPAN=1>
    <div align="right">*Location:</div></TD>
    <TD ALIGN="LEFT" VALIGN="TOP"  COLSPAN=1>
    <INPUT TYPE=TEXT NAME="location" VALUE="" SIZE="27" MAXLENGTH="80">&nbsp;</TD>
    </TR>
    <TR>
    <TD ALIGN="LEFT" VALIGN="TOP"  COLSPAN=1>
    <div align="right">*Machine Make:</div></TD>
    <TD ALIGN="LEFT" VALIGN="TOP"  COLSPAN=1>
    <INPUT TYPE=TEXT NAME="machinemake" VALUE="" SIZE="27" MAXLENGTH="40">&nbsp;</TD>
    </TR>
    <TR>
    <TD ALIGN="LEFT" VALIGN="TOP"  COLSPAN=1>
    <div align="right">*Machine Type:</div></TD>
    <TD ALIGN="LEFT" VALIGN="TOP"  COLSPAN=1>
    <INPUT TYPE=TEXT NAME="machinetype" VALUE="" SIZE="27" MAXLENGTH="100">&nbsp;</TD>
    </TR>
    <TR>
    <TD ALIGN="LEFT" VALIGN="TOP"  COLSPAN=1>
    <div align="right">*Asset Number:</div></TD>
    <TD ALIGN="LEFT" VALIGN="TOP"  COLSPAN=1>
    <INPUT TYPE=TEXT NAME="assetnum" VALUE="" SIZE="27" MAXLENGTH="40">&nbsp;</TD>
    </TR>
    <TR>
    <TD ALIGN="LEFT" VALIGN="TOP"  COLSPAN=1>
    <div align="right">*Serial Number:</div></TD>
    <TD ALIGN="LEFT" VALIGN="TOP"  COLSPAN=1>
    <INPUT TYPE=TEXT NAME="serialnum" VALUE="" SIZE="27" MAXLENGTH="40">&nbsp;</TD>
    </TR>
    <TR>
    <TD ALIGN="LEFT" VALIGN="TOP"  COLSPAN=2>
    <br>
    <tr>
    <TD ALIGN="LEFT" VALIGN="TOP"  COLSPAN=2>
    <input type="submit" name="submit" value="Submit!"> <INPUT TYPE="reset" value ="Reset">
    </FORM></center>

        
    EOF;
    }
    else
    {

    $ipaddress getenv("REMOTE_ADDR" );
    $fullname trim$_POST['fullname'] );
    $location trim$_POST['location'] );
    $machinetype trim$_POST['machinetype'] );
    $machinemake trim$_POST['machinemake'] );
    $assetnum trim$_POST['assetnum'] );
    $serialnum trim$_POST['serialnum'] );


    if(!
    $_POST['fullname']) //<----
    $error_message .= "Full Name cannot be BLANK </BR> "


    if(!
    $_POST['location']) // <----
    $error_message .= "Location cannot be BLANK. </BR> "


    if(!
    $_POST['machinetype']) // <----
    $error_message .= "Machine Type cannot be BLANK.  </BR>"


    if(!
    $_POST['machinemake']) // <----
    $error_message .= "Machine Make cannot be BLANK</BR> "


    if(!
    $_POST['assetnum']) // <----
    $error_message .= "Asset Number  cannot be BLANK. </BR> "


    if(!
    $_POST['serialnum']) // <----
    $error_message .= "Serial Number cannot be BLANK </BR> "





    $cnx mysql_connect("localhost""root""" ) or die("connection error" );
    mysql_select_db("emeaasset"$cnx) or die("DB error" );

    $query "INSERT into asset VALUES ('$fullname', '$location', '$machinetype', '$machinemake', '$assetnum', '$serialnum')";


    if(!
    $error_message) {
    mysql_query($query) or die("There has been an error with executing the query. Your informarion has NOT been saved. Please contact the system administrator for further informartion  the error is - query error" );

    echo 
    "<B><h3>Thankyou for submitting your information. It has been recorded in the database.</h3></B>";
    }
    else
        echo 
    $error_message;
    }
    ?>
    </BODY>
    </HTML>

  2. #2
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I don't know if I'm wrong but after you submit the data on any form and get a confirmation page, if you refresh it the information will be submitted again because the browser still has the variables that were passed from the original form and when you refresh it, it will sent those variables again.

    If this bothers you too much, you could add a "click here to submit more asset info again" link or something like under the thank you message.
    Community Guidelines | Community FAQ

    "He that is kind is free, though he is a slave;
    he that is evil is a slave, though he be a king." - St. Augustine

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    United Kingdom
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok that does not really help. because when I put a link in and refer it back to my page which is called Asset.php. It still goes back to the "Thankyou..." page. Can you tell me how to do it so that I can refresh the page.

  4. #4
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think you can by refreshing the page because of what I already wrote in the first post. Besides, after someone submits a form and then want to submit it again, they won't hit refresh because that simply isn't logic. They will hit the back button.

    Remember that they don't know you are using one single page to display the form and submit the information.

    You could use two separate pages but you still won't be able to refresh the page and get the form. Maybe someone else can help you out on this one.
    Community Guidelines | Community FAQ

    "He that is kind is free, though he is a slave;
    he that is evil is a slave, though he be a king." - St. Augustine


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •