PHP - Keeping Vars Through Multiple Submits
Hello, I am having an issue where PHP nulls the donation amount after multiple form submits. Here is a synopsis of what is happening.
1: User enters donation amount and clicks 'submit' 2: Is taken to a confirmation page where they must agree to terms 3: User fails to agree to the terms, the page is reloaded with an error message, and the donation amount is set to null I want to make the donation amount display despite multiple confirm page reloads. How would I do this? Here is the site to test it yourself. Ignore the steamid input and check "do not change my rank upon donation" to test. http://forums.stgdarkrp.org/donate2/check.php Please note: If you use IE, the formatting is messed up, that is a problem I will look into later Similar Tutorialshave a form with three list/menu items. Each one when selected acts a filter. I would like to submit the form when the user changes the value on each list.menu: I have tried adding an onchange="this.form.submit()" command on each list/menu but only the first one works. I guess the form only recognises one submit item. Is there a way to get the form to submit on each of the three list/menu items ? Many thanks, code ... <body> <form id="form1" name="form1" method="post" action=""> <label>Team <select name="myTeam" id="myTeam" onchange="this.form.submit()"> <?php do { ?> <option value="<?php echo $row_myTeam['title']?>"<?php if (!(strcmp($row_myTeam['title'], $_POST['myTeam']))) {echo "selected=\"selected\"";} ?>><?php echo $row_myTeam['title']?></option> <?php } while ($row_myTeam = mysql_fetch_assoc($myTeam)); $rows = mysql_num_rows($myTeam); if($rows > 0) { mysql_data_seek($myTeam, 0); $row_myTeam = mysql_fetch_assoc($myTeam); } ?> </select> </label> <label>Qct <select name="myQCT" id="myQCT" onchange="this.form.submit()"> <?php do { ?> <option value="<?php echo $row_chooseQCT['name']?>"<?php if (!(strcmp($row_chooseQCT['name'], $_POST['myQCT']))) {echo "selected=\"selected\"";} ?>><?php echo $row_chooseQCT['name']?></option> <?php } while ($row_chooseQCT = mysql_fetch_assoc($chooseQCT)); $rows = mysql_num_rows($chooseQCT); if($rows > 0) { mysql_data_seek($chooseQCT, 0); $row_chooseQCT = mysql_fetch_assoc($chooseQCT); } ?> </select> </label> <label>Year <select name="myYear" id="myYear" onchange="this.form.submit()"> <?php do { ?> <option value="<?php echo $row_myYear['year']?>"<?php if (!(strcmp($row_myYear['year'], $_POST['myYear']))) {echo "selected=\"selected\"";} ?>><?php echo $row_myYear['year']?></option> <?php } while ($row_myYear = mysql_fetch_assoc($myYear)); $rows = mysql_num_rows($myYear); if($rows > 0) { mysql_data_seek($myYear, 0); $row_myYear = mysql_fetch_assoc($myYear); } ?> </select> </label> </form> </body> I generated a table from the database, and at the end of each row there are two submits, one for save and another for delete. The values are generated as either text and select box input. Right now, I have all the submits named differently (ends a number), so I can loop through all available submits based on the number to check which row needs to be updated, and to retrieve the values during form processing, then only perform the query. I have also hidden input in each row to send the "primary key" that is used during query. Is there a better approach than to have so many different names for the buttons, not having to loop through all of them each time, and still keep a similar layout? I'm trying to avoid anything else than PHP. The table looks something like: col1____| col2_______| col3____|__________________ txt input | select input | txt input |save bttn | delete bttn txt input | select input | txt input |save bttn | delete bttn Hey guys, im new to php and have become stuck with having more than one html form/submit that will relays to another piece of code to view something At the moment my first form works but once i submit my second form it relays back to the first form how can i prevent this so i can have many submit forms on one php page? Thanks Code: [Select] <?php $dbname = $_POST['dbname']; $tblname = $_POST['tblname']; checksubmit( $dbname); function checksubmit( $dbname){ if(isset($_POST['enter'])) { checkform( $dbname); } else { page1( $dbname); } } function checkform ($dbname){ if(empty($_POST['dbname'])){ echo 'fill out database name'; } else page2( $dbname ); } function page1( $dbname){ echo " <form method='post' action=''> <table> <tr> <td>Database name:</td><td><input type='text' name='dbname' /></td> </tr><tr> <td colspan='2' align='right'><input type='submit' name='enter' value='enter' /></td> </tr> </table> </form> "; } function page2( $dbname ){ echo " <form method='post' action=''> <table> <tr> <td>Table Name:</td><td><input type='text' name='tblname' /></td> </tr><tr> <td colspan='2' align='right'><input type='submit' name='return' value='return' /></td> </tr> </table> </form> "; if(isset($_POST['return'])) { page3( $dbname ); } } function page3( $dbname ) { echo 'I want to make it here'; } ?> Hello, I've looked around at some previous posts and can't seem to get them to work for me. I'm occasionally receiving blank emails from my contact form, i.e. Name: Email: Subject: Message: with no fields filled out. No doubt the cause is my form. It has validation, and I'm aware that with JS turned off, the validation won't work, but I find it hard to believe that people are just submitting blank forms, I'm confused, and am worried that I'm getting emails and not realizing it! My code is below, if you can point me in the right direction or point out the problem area that would be great! website is: www.ed-yu.com Code: [Select] <div id="contact_box"> <h3>Questions?<br />Comments?<br />Just get in touch.</h3><p>(use the form below, or email edward@ed-yu.com)</p> <form id="contact" method="post" class="form" action="js/contactengine.php"> <p class="name"> <input type="text" name="Name" id="Name" /> <label for="Name">Name</label> </p> <p class="email"> <input type="text" name="Email" id="Email" /> <label for="Email">Email</label> </p> <p class="Subject"> <select name="Subject" id="Subject"> <option value="000" selected="selected"> - Choose -</option> <option value="General Question">General Question</option> <option value="Photography Inquiry">Photography Inquiry</option> <option value="Web-design Inquiry">Web-design Inquiry</option> <option value="Love Letter">Love Letter</option> <option value="Hate Mail">Hate Mail</option> <option value="Website Feedback">Website Feedback</option> </select> <label for="Subject">Subject</label> </p> <p class="Message"> <label for="Message"> </label><br /> <textarea name="Message" rows="20" cols="20" id="Message"></textarea> </p> <p class="Submit"> <input type="Submit" name="Submit" value="Send Email" class="submit-button" /> </p> </form> </div><!--contact_box--> Code: [Select] <?php $EmailFrom = "ED-YU.com"; $EmailTo = "eddytheflow@gmail.com"; $Subject = "A new ".mb_strtolower($_POST['Subject'])." from ".$_POST['Name']." "; $Name = Trim(stripslashes($_POST['Name'])); $Tel = Trim(stripslashes($_POST['Tel'])); $Email = Trim(stripslashes($_POST['Email'])); $Message = Trim(stripslashes($_POST['Message'])); // validation $validationOK=true; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Email: "; $Body .= $Email; $Body .= "\n"; $Body .= "Subject: "; $Body .= $Subject; $Body .= "\n"; $Body .= "Message: "; $Body .= $Message; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; } ?> So I posted something like this a while ago but i didn't get any particularly good answers so I redid it. this is what I have now. It takes clicking the reply three times before it changes changes the form but then after that initial session of reply button clicks it only takes two which is what I want. This is the last thing on my forum (at least till I find some other bug :p) and I need it fixed but I can't figure it out. IT\t wouldn't be a huge issue but the thing is that the first reply you make someone would fill it all in and then press reply then they would lose all their stuff and have to start over before it was submitted, Help please! thanks! Code: [Select] <form action="<?php if ($_SESSION['logged_in'] == '1') { if ((isset($_POST['reply_to_thread'])) && ($_SESSION['reply_has_been_clicked'] != '1')) { echo $this_thread_path; } elseif ((isset($_POST['reply_to_thread'])) && ($_SESSION['reply_has_been_clicked'] == '1')) { $_SESSION['reply_has_been_clicked'] = '0'; $_SESSION['came_from_a_page'] = '1'; echo 'thread_redirect.php'; }}?>" method='post'> <?php if ($_SESSION['logged_in'] == '1') { if ((isset($_POST['reply_to_thread'])) && ($_SESSION['reply_has_been_clicked'] != '1')) { echo '<textarea name="reply_body" cols="75" rows="10" style="resize:none; onKeyUp="limitText(this.form.reply_body,this.form.countdown,5000); onKeyDown="limitText(this.form.reply_body,this.form.countdown,5000);">Enter your reply here...</textarea><br><br><font size="1">(Maximum characters: 5000)<br> You have <input readonly type="text" name="countdown" size="3" value="5000"> characters left.</font><br>'; $_SESSION['reply_has_been_clicked'] = '1'; } } ?> <input type='submit' name='reply_to_thread' value="Reply"> <?php if (isset($_POST['reply_to_thread'])) { if ($_SESSION['logged_in'] != '1') { echo 'You need to be logged in!'; } } ?> </form> Hi, I am creating an access control page where my end user swipes his card and the page auto submits. At this stage I want to click his/her picture as well. The challenge is I am unable to find a script where a webcam clicks on page refresh or when it auto submits.. All the scripts i have seen only work on a click which is not possible here as the only user input is a swipe which has an autosubmit. The Script:
<h1>Do Add a Message to the MySQL Database</h1> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <textarea name="message"></textarea> <br/> <input type="submit" name="submit"/> </form> <?php // The Connection to the Database // Taken Out ?> <?php // To insert the text data into the MySQL database. if(isset($_POST['submit'])){ $tqs = "INSERT INTO messages (`message`) VALUES ('{$_POST['message']}')"; $tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc)); } ?> <?php // To select the text data from the MySQL database. $tqs = "SELECT * FROM messages"; $tqr = mysqli_query($dbc, $tqs); // To print out the text data inside of table on the page. echo "<h1>This Is Where the Messages Gets Printed on Screen</h1>"; echo "<table><tr><td>ID</td><td>The Message</td></tr>"; while($row = mysqli_fetch_assoc($tqr)){ echo "<tr><td>" . $row['id'] . "</td><td>" . $row['message'] . "</td></tr>"; } echo "</table>"; ?>1. When I have added text with the form to the MySQL database... 2. ... and I have clicked on "page reload" in Firefox to reload the page... 3. ... then the before submitted text gets submitted again to the MySQL database. So basically, add text with the form to the MySQL database, reload the page in Firefox, and the before added text will get submitted to the MySQL database again. My Question Is: What is the proper way to avoid this? Edited by glassfish, 06 October 2014 - 10:18 AM. I have a html form that submits to another website. Everything works fine in firefox and chrome however the data is duplicated in IE. Is there some quirk in IE when submitting a form to a different website? I have an existing GET form that I use and want to write to a MYSQL table everytime a user uses that form. Code: [Select] <FORM ACTION="https://someurl.com" METHOD=GET> Would the easiest to be a javascript function that uses the onclick event? What would be the best way to continue to pass the user along while capturing data and writing that to a MYSQL table. Thanks! I am inplanting a bonus system to a game i have. I want to say at first that i am not good at php am reading alot and go by learn by doing. But after a few hours i kinda gave up. Here is the code. The page end up blank. And i tested so my syntax work $cost and $points with only the db stuff and this code <div class="yellow_12_bold"><? print (number_format($points)); ?> </div> <div class="yellow_12_bold"><? print (number_format($cost)); ?> </div> And it does. Anyway here is the code Code: [Select] <? $dbq = $db->execute("select * from Bonus where username='$username'"); $points = $dbq->fields['points']; $allpoints = $dbq->fields['points_total']; $dbq->close(); if ($cost == "5" && $amount == "3000") { if ($points == "5" || $points > "5") { $sqlb = "update UserData set turns=turns+'3000' WHERE turns < 50000 and location != '9' and frozen = '0'"; $result1 = mysql_query($sqlb); $sqlc = "update Bonus set points=points-'5' WHERE username = '$username'; $result2 = mysql_query($sqlb); $points2 = ($points - 5); <p align="center" class="black">Thank you! 3000 turns have been added to everyone. You have <div class="yellow_12_bold"><? print (number_format($points)); ?> </div> bonus points left. </p> } else { <p align="center" class="black">Sorry you dont have $cost points. You have <div class="yellow_12_bold"><? print (number_format($points)); ?> </div> bonus points left.</p> } } ?> Trying to pass VARS $URL1 and $type to header location.Heres the code. Code: [Select] $URL1 = $_POST['url']; $type = $_POST['type_request']; session_start(); $string = strtoupper($_SESSION['string']); $userstring = strtoupper($_POST['userstring']); session_destroy(); if (($string == $userstring) && (strlen($string) > 4)) { header("Location: $success"); exit(); The VARS come from a FORM and then go to this script for checkind data. I need to have them continue to the next page. hi phpfreaks I am trying to remove the get variables from my url. the code below works if I echo it out but to try to modify the $_server variable it will not work. Any ideas? Code: [Select] $current_url = explode('?',$_SERVER["REQUEST_URI"]); $_SERVER["REQUEST_URI"]= $current_url[0]; echo $current_url[0]."<br>"; hey guys i have a static attribute $_exception_handler which is set to Exception and....now this value could change to a customer exception_handler but what i want to do is <?php catch (self::$_exception_handler $e) { } but im getting an error...is there a way of doing this...any help would be greatful thanks class below <?php class Autoloader { protected static $_exception_handler = Exception; protected static $_classes = array(); public static function load_library($class_name) { $file = ROOT . DS. LIBRARY_DIRECTORY . DS . $class_name . CLASS_EXTENSION; try { self::load_class($class_name, $file); } catch (self::$_exception_handler $e) { echo $e->getMessage(); } } public static function load_exception($class_name) { } public static function load_class($class_name, $file) { if (!class_exists($class_name, FALSE)) { if (file_exists($file)) { require_once $file; } else { throw new Exception(sprintf('Class %s not found.', $class_name)); } } } } I want to use all five results separately in order to use in a Jquery slider. Code: [Select] <?php $a = "SELECT * FROM blog_posts ORDER BY id DESC LIMIT 5"; $query = mysql_query($a) or die (mysql_error()); $query_results = mysql_fetch_array($query); ?> I know if i was going to grab vars from an normal array i would just use... Code: [Select] <?php echo $array_reults['0'] ?> Can any one help me with this problem? Hi I am attempting to request a single row from a table that has 20 fields. I want to turn each field into it's own variable (you'll see oc1, oc2 etc in the code) and then echo the variable just to check it has worked. When I run the qry below - it picks up the first one correctly but then places the same value in all the other fields. (The $question var should be a long text string but is echoing the first variable instead. There's clearly something wrong with the way I have constructed this - but I don't know at which point it has gone wrong. Can anyone help? $result = mysql_query("SELECT oid,qid,question,posneg,oc1,oc2,oc3,oc4,oc5,oc6,oc7,psc1,psc2,psc3,psc4,psc5,psc6,psc7,psc8,psc9 FROM tblquestions WHERE oid = '1'"); if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; } $oid=mysql_result($result,"oid"); $qid=mysql_result($result,"qid"); $question=mysql_result($result,"question"); $posneg=mysql_result($result,"posneg"); $oc1=mysql_result($result,"oc1"); $oc2=mysql_result($result,"oc2"); $oc3=mysql_result($result,"oc3"); $oc4=mysql_result($result,"oc4"); $oc5=mysql_result($result,"oc5"); $oc6=mysql_result($result,"oc6"); $oc7=mysql_result($result,"oc7"); $psc1=mysql_result($result,"psc1"); $psc2=mysql_result($result,"psc2"); $psc3=mysql_result($result,"psc3"); $psc4=mysql_result($result,"psc4"); $psc5=mysql_result($result,"psc5"); $psc6=mysql_result($result,"psc6"); $psc7=mysql_result($result,"psc7"); $psc8=mysql_result($result,"psc8"); $psc9=mysql_result($result,"psc9"); ?> <?php echo $oid; // Question Number?> <?php echo $qid; // Question Number?> <?php echo $question; // Question Number?> <?php echo $posneg; // Question Number?> <?php echo $oc1; // Question Number?> <?php echo $oc2; // Question Number?> <?php echo $oc3; // Question Number?> <?php echo $oc4; // Question Number?> <?php echo $oc5; // Question Number?> <?php echo $oc6; // Question Number?> <?php echo $oc7; // Question Number?> <?php echo $psc1; // Question Number?> <?php echo $psc2; // Question Number?> <?php echo $psc3; // Question Number?> <?php echo $psc4; // Question Number?> <?php echo $psc5; // Question Number?> <?php echo $psc6; // Question Number?> <?php echo $psc7; // Question Number?> <?php echo $psc8; // Question Number?> <?php echo $psc9; // Question Number?> Sorry if this isn't the right forum, I wasn't sure where to post this. Alright, so I have a high score submit script, and it goes as follows... This is the actionscript: Code: [Select] on (release) { var usco LoadVars = new LoadVars(); uscore.name = _root.suname; uscore.score = _root.suscore.stime; uscore.game = "alien"; uscore.mode = "survival"; uscore.sendAndLoad("linkhere", uscore, "POST"); play(); } Note: We have also tried: Code: [Select] on (release) { var usco LoadVars = new LoadVars(); uscore.name = _root.suname; uscore.score = _root.suscore.stime; uscore.game = "alien"; uscore.mode = "survival"; var uscoresubmit:LoadVars = new LoadVars(); uscore.sendAndLoad("linkhere", uscoresubmit, "POST"); play(); } The PHP is: <?PHP include('Connect.php'); $name=$_POST['name']; $name=mysql_real_escape_string($name); $score=$_POST['score']; $score=mysql_real_escape_string($score); $game=$_POST['game']; $game=mysql_real_escape_string($game); $mode=$_POST['mode']; $mode=mysql_real_escape_string($mode); if(!empty($game)) { mysql_query("INSERT INTO scores(game, name, score, mode) VALUES ('$game', '$name', '$score', '$mode')"); } ?> I have also tried running a number of things on the "else" of that if(!empty($game)) and nothing has pulled through, so I'm under the notion that it isn't loading the page in sendAndLoad()? It was working before, but it appears to have just stopped, we're not sure what we changed. Any help would be greatly appreciated! Thanks, Xyphon Hi! I'm working on a simple e-commerce script. I have some $_SESSION variables that is defined and works fine while surfing on the site. But when I close the browser and reenter the site, all the session-variables are not defined (unset?), until i click on a link on the site. Weird behavior... please help! /I Hello Guys, I want to be able to filter out any url in any of form $_POST vars? Would I do it with a foreach loop and the preg replace function? I would consider any web address in my form spam. I would like to filter it out.. I'm already using Strip tags, htmlentities, strip_tags, stripslashes & mysql_real_escape_string but they don't seem to filter out URLs.. Thanks for your help in advanced.. Hey guys, OK, heres what I would like to do. On my form, I have 50+ variables and not all of them require a response. If inserted, they insert a blank in the DB, instead of NULL. First, does this even matter? If it does, how can I create a function that checks the var to see if its empty, and if empty $var = NULL; Thanks |