FangerZero Posted October 30, 2009 Share Posted October 30, 2009 I've tried looking online before actually asking for help, but I've been looking for about the past 3-5 hours and have found nothing that'll help me. This is a project for school, and well I have to use Access as a database. I am using PHP for coding, and I'm fairly new to PHP. Now for the problem... When I type in a Name in my Text Field all is good, I hit submit it works, if I hit reset it resets. My issue happens after I hit submit once the item is added, then if I refresh the page the item is added again, and it happens as many times as I hit refresh. I've tried numerous ways to make my text fields clear. I'm not coming up with anything. I started out having two files a PHP and HTML, I combined them hoping I could figure out a way to fix this, but to no avail. If you look at my code you'll find that "odbc_exec($conn,$input);" is missing I took it out cause I have no idea where to put it, or what to do with it, or how to clear the fields upon having that executed. If anyone could help me even the tiniest bit that'd be great <?php $conn=odbc_connect('database','',''); if (!$conn) {exit("Connection Failed: " . $conn);} $Name = $_POST["Name"]; $Submit = $_POST["Submit"]; $Reset = $_POST["Reset"]; $input="INSERT INTO Registry (FirstName) VALUES('$Name')"; $sql="SELECT * FROM Registry"; $rs=odbc_exec($conn,$sql); ?> <html> <body> <form name="TestForm" method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>"> Name: <input type="text" name="Name" maxlength=50/> <p> <input type="submit" name="Submit" value="Submit"> <input type="reset" name="Reset" value="Reset"> </form> </body> </html> <?php if (!$rs) {exit("Error in SQL");} echo "<table><tr>"; echo "<th>FirstName</th>"; echo "<th>LastName</th></tr>"; //Writes Table Values while (odbc_fetch_row($rs)) { $firstname=odbc_result($rs,"FirstName"); $lastname=odbc_result($rs,"LastName"); echo "<tr><td>$firstname</td>"; echo "<td>$lastname</td></tr>"; } odbc_close($conn); echo "</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/179593-issues-php-forms-clearing/ Share on other sites More sharing options...
WolfRage Posted October 30, 2009 Share Posted October 30, 2009 An easy possible fix is to assign a session to the user. Then when the form is submitted mark a variable as true. If that variable is true do not let them submit the form again. Now you could say that a user might delete there cookies and then submit the form yet again, although unlikely. If you want to account for this possibility then assign a hidden input field to the form and upon submitting the form add this semi random though non repeating value to the table with the input form. Then the value cannot be accidently added even if the user deletes their cookies. Just remember which ever method you implement you need to undo that action if they choose to delete the value from the database; so that they may again post a value. Link to comment https://forums.phpfreaks.com/topic/179593-issues-php-forms-clearing/#findComment-947676 Share on other sites More sharing options...
FangerZero Posted October 30, 2009 Author Share Posted October 30, 2009 I think you missed the part that I'm new w/ PHP O.O I kind of understand Session but not really. Link to comment https://forums.phpfreaks.com/topic/179593-issues-php-forms-clearing/#findComment-948092 Share on other sites More sharing options...
FangerZero Posted October 31, 2009 Author Share Posted October 31, 2009 I think you missed the part that I'm new w/ PHP O.O I kind of understand Session but not really. Another way to put what I need. I need something to clear upon refreshing that is easy for me to understand. Why use something if it makes no sense. So something in the background I DO NOT WANT A BUTTON. Link to comment https://forums.phpfreaks.com/topic/179593-issues-php-forms-clearing/#findComment-948206 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.