Jump to content

wright67uk

Members
  • Posts

    454
  • Joined

  • Last visited

Everything posted by wright67uk

  1. Ok thankyou. I'm still not getting any form parameters from the Ajax page.
  2. I'm using this in the head of the original page; <script> function showUser(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","get_snag_score.php?q="+str,true); xmlhttp.send(); } </script>
  3. I'm using this in the head of the original page; <script> function showUser(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","get_snag_score.php?q="+str,true); xmlhttp.send(); } </script>
  4. I have a page (below) that has half of a form and I'm using ajax to display the second half of the form (which contains php input) , everything appears fine however, when I submit the form I'm only sending the forms first half! I'm not too familiar with ajax, and when i Google for info about my issue, all I find is info about two stage forms (which this is not). I've also tried moving my submit button around a bit but to no avail. I need to keep the physical layout of my page, however im open to suggestions. For the time being im using action="<?php echo $_SERVER['PHP_SELF']; and a get method, purely so that i can observe which parameters are being passed to the url. my original page: <?php $user_id = 7; #connection $connect_solning = mysql_connect($hostname_connect, $username_connect, $password_connect) or trigger_error(mysql_error(),E_USER_ERROR); @mysql_select_db($database_connect) or die (mysql_error()); $sql = "SELECT location FROM snag_score_cards WHERE user_id = $user_id"; $result = mysql_query($sql); $selected_id = isset($_POST['location']) ? intval($_POST['location']) : false; $who = ''; $options = ''; while ($row=mysql_fetch_array($result)) { if($selected_id==$row['location']) { $selected = ' selected="selected"'; } else { $selected = ''; } $options .= "<option value=\"{$row['location']}\"{$selected}>{$row['location']}</option>\n"; } ?> <div id="formright"> <form name="form" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label class="dateof" style="margin-left:10px;"> <a href="new_snag_scorecard.php">create new scorecard</a></label><br/><br/> <label class="dateof" style="margin-left:10px; "> Select a Scorecard: </label><br /> <select name="location" style="margin-left:10px; width:200px; " onchange="showUser(this.value)"><br /> <option value="">Select a Scorecard:</option><?php echo $options ?></select><br /><br /> <label class="dateof" style="margin-left:10px;"> Date of Score: </label><br /> <input type="date" name="date" id="date" style="border:1px solid #EBEBEB; padding:0px; margin:0px; height:20px; margin-left:10px; " value=" " /><br /> <?php $result = mysql_query("SELECT * FROM Competitions"); $num_rows = mysql_num_rows($result); if ($num_rows >0) { $selected_id = isset($_POST['Competition']) ? intval($_POST['Competition']) : false; $who = ''; $options2 = ''; while ($row=mysql_fetch_array($result)) { if($selected_id==$row['Competition']) { $selected = ' selected="selected"'; } else { $selected = ''; } $options2 .= "<option value=\"{$row['Competition']}\"{$selected}>{$row['Competition']}</option>\n"; } echo ' <br/><label class="dateof" style="margin-left:10px;" >Select a Competition: </label><br/> <select class="selectstyle" name="competition" > <option class="optionstyle" value="">Select a Competition</option> ' . $options2 . '</select><br/><br/>' ;} ?> <input type="submit" name="submit" value="submit" id="submit"/> </div><div id="formwrap"> <div id="txtHint"> <!-- ajax loads get_snag_score.php here --> </div> </div> </form> I'm using Ajax to show the below on my page... <?php // Sanitize input function sanitize($in) { return addslashes(htmlspecialchars(strip_tags(trim($in)))); } $q = sanitize($_GET['q']); echo '<Br/><h2 class="location">' . $q . "</h2>" ; #connection here $connect_solning = mysql_connect($hostname_connect, $username_connect, $password_connect) or trigger_error(mysql_error(),E_USER_ERROR); @mysql_select_db($database_connect) or die (mysql_error()); $sql = "SELECT par1, par2, par3 FROM snag_score_cards WHERE location = '$q'"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { $par1 = sanitize($row['par1']); $par2 = sanitize($row['par2']); $par3 = sanitize($row['par3']); } ?> <input type="hidden" name="processForm" value="1" /> <input type="text" autocomplete="off" name="Scores" id="Scores" value="Score" class="clip" readonly style="border:0px" > <input type="text" autocomplete="off" name="Par" id="Pars" value="Par" class="clip" readonly style="border:0px" > <input type="text" name="Par Score" id="ParScore" value="Total" class="clip" readonly style="border:0px" ><br> <input type="text" autocomplete="off" name="sum1" id="hole1A" value="" onchange="calc(this.value,'hole1B','hole1result')" > <input type="text" autocomplete="off" name="sum2" readonly value="<?php echo $par1;?>" id="hole1B" onchange="calc(this.value,'hole1A','hole1result')" > <input type="text" name="sum" value="" id="hole1result" readonly style="readonly"> <br> <input type="text" autocomplete="off" name="sum1" id="hole2A" value="" onchange="calc(this.value,'hole2B','hole2result')" > <input type="text" autocomplete="off" name="sum2" readonly value="<?php echo $par2;?>" id="hole2B" onchange="calc(this.value,'hole2A','hole2result')" > <input type="text" name="sum2T" value="" id="hole2result" readonly style="readonly"> <br> <input type="text" autocomplete="off" name="sum1" id="hole3A" value="" onchange="calc(this.value,'hole3B','hole3result')" > <input type="text" autocomplete="off" name="sum2" readonly value="<?php echo $par3;?>" id="hole3B" onchange="calc(this.value,'hole3A','hole3result')" > <input type="text" name="sum3" value="" id="hole3result" > <br> <input type="hidden" name="location" value="<?php echo $q?>">
  5. I have a page (below) that has half of a form and I'm using ajax to display the second half of the form (which contains php input) , everything appears fine however, when I submit the form I'm only sending the forms first half! I'm not too familiar with ajax, and when i Google for info about my issue, all I find is info about two stage forms (which this is not). I've also tried moving my submit button around a bit but to no avail. I need to keep the physical layout of my page, however im open to suggestions. For the time being im using action="<?php echo $_SERVER['PHP_SELF']; and a get method, purely so that i can observe which parameters are being passed to the url. my original page: <?php $user_id = 7; #connection $connect_solning = mysql_connect($hostname_connect, $username_connect, $password_connect) or trigger_error(mysql_error(),E_USER_ERROR); @mysql_select_db($database_connect) or die (mysql_error()); $sql = "SELECT location FROM snag_score_cards WHERE user_id = $user_id"; $result = mysql_query($sql); $selected_id = isset($_POST['location']) ? intval($_POST['location']) : false; $who = ''; $options = ''; while ($row=mysql_fetch_array($result)) { if($selected_id==$row['location']) { $selected = ' selected="selected"'; } else { $selected = ''; } $options .= "<option value=\"{$row['location']}\"{$selected}>{$row['location']}</option>\n"; } ?> <div id="formright"> <form name="form" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label class="dateof" style="margin-left:10px;"> <a href="new_snag_scorecard.php">create new scorecard</a></label><br/><br/> <label class="dateof" style="margin-left:10px; "> Select a Scorecard: </label><br /> <select name="location" style="margin-left:10px; width:200px; " onchange="showUser(this.value)"><br /> <option value="">Select a Scorecard:</option><?php echo $options ?></select><br /><br /> <label class="dateof" style="margin-left:10px;"> Date of Score: </label><br /> <input type="date" name="date" id="date" style="border:1px solid #EBEBEB; padding:0px; margin:0px; height:20px; margin-left:10px; " value=" " /><br /> <?php $result = mysql_query("SELECT * FROM Competitions"); $num_rows = mysql_num_rows($result); if ($num_rows >0) { $selected_id = isset($_POST['Competition']) ? intval($_POST['Competition']) : false; $who = ''; $options2 = ''; while ($row=mysql_fetch_array($result)) { if($selected_id==$row['Competition']) { $selected = ' selected="selected"'; } else { $selected = ''; } $options2 .= "<option value=\"{$row['Competition']}\"{$selected}>{$row['Competition']}</option>\n"; } echo ' <br/><label class="dateof" style="margin-left:10px;" >Select a Competition: </label><br/> <select class="selectstyle" name="competition" > <option class="optionstyle" value="">Select a Competition</option> ' . $options2 . '</select><br/><br/>' ;} ?> <input type="submit" name="submit" value="submit" id="submit"/> </div><div id="formwrap"> <div id="txtHint"> <!-- ajax loads get_snag_score.php here --> </div> </div> </form> I'm using Ajax to show the below on my page... <?php // Sanitize input function sanitize($in) { return addslashes(htmlspecialchars(strip_tags(trim($in)))); } $q = sanitize($_GET['q']); echo '<Br/><h2 class="location">' . $q . "</h2>" ; #connection here $connect_solning = mysql_connect($hostname_connect, $username_connect, $password_connect) or trigger_error(mysql_error(),E_USER_ERROR); @mysql_select_db($database_connect) or die (mysql_error()); $sql = "SELECT par1, par2, par3 FROM snag_score_cards WHERE location = '$q'"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { $par1 = sanitize($row['par1']); $par2 = sanitize($row['par2']); $par3 = sanitize($row['par3']); } ?> <input type="hidden" name="processForm" value="1" /> <input type="text" autocomplete="off" name="Scores" id="Scores" value="Score" class="clip" readonly style="border:0px" > <input type="text" autocomplete="off" name="Par" id="Pars" value="Par" class="clip" readonly style="border:0px" > <input type="text" name="Par Score" id="ParScore" value="Total" class="clip" readonly style="border:0px" ><br> <input type="text" autocomplete="off" name="sum1" id="hole1A" value="" onchange="calc(this.value,'hole1B','hole1result')" > <input type="text" autocomplete="off" name="sum2" readonly value="<?php echo $par1;?>" id="hole1B" onchange="calc(this.value,'hole1A','hole1result')" > <input type="text" name="sum" value="" id="hole1result" readonly style="readonly"> <br> <input type="text" autocomplete="off" name="sum1" id="hole2A" value="" onchange="calc(this.value,'hole2B','hole2result')" > <input type="text" autocomplete="off" name="sum2" readonly value="<?php echo $par2;?>" id="hole2B" onchange="calc(this.value,'hole2A','hole2result')" > <input type="text" name="sum2T" value="" id="hole2result" readonly style="readonly"> <br> <input type="text" autocomplete="off" name="sum1" id="hole3A" value="" onchange="calc(this.value,'hole3B','hole3result')" > <input type="text" autocomplete="off" name="sum2" readonly value="<?php echo $par3;?>" id="hole3B" onchange="calc(this.value,'hole3A','hole3result')" > <input type="text" name="sum3" value="" id="hole3result" > <br> <input type="hidden" name="location" value="<?php echo $q?>">
  6. @christian the page would thank the user for their details, giving them 5 seconds to read the message. Before taking them to a different website. @kicken out of interest could I keep the code as it is and place a variable in a html refresh? Populating the variable if the form was successful? Before posting I saw a lot of info on buffering.. and a lot of mixed opinions to go with that info Ps. Thanks for the replies
  7. Is it possible to redirect a site after a form submission and after 5 seconds? <head> <meta http-equiv="refresh" content="5; URL=asite.htm"> </head> Would surely need to be in the head and before any if statement... and <?php header("refresh: 5; asite.htm"; ?> Would need to be before any output. ie. myform I would like the re-direct to happen 5 seconds after a successful form submission. How do I go about this? <body> <div id="main"> <div id="title">The North London Corporate Cup</div> <div id="subheading"></div> <div id="mid"></div> <div id="form"> <form name="form1" method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> <input type="text" onclick="this.value=''" name="name" class="round" value="name" size="20" /> <input type="text" onclick="this.value=''" name="email" class="round" value="email" size="20"/> <input type="submit" class="round" name="Submit" value="Register Your interest"/> </form> </div> <?php if (isset($_POST['Submit'])) { if ($_POST['name'] != "") { $name = filter_var($_POST['name'], FILTER_SANITIZE_STRING); if (!filter_var($name, FILTER_SANITIZE_STRING)) { $errors .= '* Please enter a valid name.<br/><br/>'; } } else { $errors .= '* Please enter your name.<br/>'; } if ($_POST['email'] != "") { $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors .= "* $email is <strong>NOT</strong> a valid email address "; } } else { $errors .= '* Please enter your email address.<br/>'; } if (!$errors) { ### connection here ### if (!$con) { die ('Could not connect: ' . mysql_error ()); } mysql_select_db ("###", $con); mysql_query("INSERT INTO ### (name, email) VALUES ('$name', '$email')"); echo '<p style="color: white; margin-left:105px; font-size:22px; padding-top:15px">* Thankyou, we will be in touch soon!<br></p>'; } else { echo '<p style="color: white; margin-left:105px; padding-top:15px">' . $errors . 'please try again.</p></div>'; } } ?> </div> </body> </html>
  8. I feel very silly :-( ...and thank you for the replies.
  9. I'm using the file below, however nothing gets added to my database. I've tested my database connection, and i've echoed $email and $name, can I put this down to incorrect syntax? <div id="form"> <form name="form1" method="post" action="form-email.php"> <input type="text" onclick="this.value=''" name="name" class="round" value="name" size="20" /> <input type="text" onclick="this.value=''" name="email" class="round" value="email" size="20"/> <input type="submit" class="round" name="Submit" value="Register Your interest"/> </form> </div> <?php if (isset($_POST['Submit'])) { if ($_POST['name'] != "") { $name = filter_var($_POST['name'], FILTER_SANITIZE_STRING); if (!filter_var($name, FILTER_SANITIZE_STRING)) { $errors .= '* Please enter a valid name.<br/><br/>'; } } else { $errors .= '* Please enter your name.<br/>'; } if ($_POST['email'] != "") { $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors .= "* $email is <strong>NOT</strong> a valid email address "; } } else { $errors .= '* Please enter your email address.<br/>'; } if (!$errors) { $hostname = "###"; $username = "###"; $dbname = "###"; $password = "###"; $con = mysql_connect ("$hostname", "$username", "$password"); if (!$con) { die ('Could not connect: ' . mysql_error ()); } mysql_select_db ("###", $con); $sql = "INSERT INTO NLCUP (name, email) VALUES ('$name', '$email')"; echo '<p style="color: white; margin-left:105px; font-size:22px; padding-top:15px">* Thankyou, we will be in touch soon!<br></p>'; } else { echo '<p style="color: white; margin-left:105px; padding-top:15px">' . $errors . 'please try again.</p></div>'; } } ?> </div>
  10. In the coe below the status of the drop down list is passed to the $q variable and used in an sql query. In what way would I change the code if I wanted to have a second drop down? xmlhttp.open("GET","getuser.php?q="+str,true); xmlhttp.send(); <html> <head> <script> function showUser(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getuser.php?q="+str,true); xmlhttp.send(); } </script> </head> <body> <form> <select name="users" onchange="showUser(this.value)"> <option value="">Select a person:</option> <option value="1">Peter Griffin</option> <option value="2">Lois Griffin</option> <option value="3">Glenn Quagmire</option> <option value="4">Joseph Swanson</option> </select> </form> <br> <div id="txtHint"><b>Person info will be listed here.</b></div> </body> </html>
  11. Thanks for your advice Christian, I've done a bit of reading, and decided to have the processing and form on the same page. I think I'm now validating both the email and name field, however I'm not having any entries in my MySQL database. Am I still really wrong in my approach? <div id="form"> <form name="form1" method="post" action="form-email.php"> <input type="text" onclick="this.value=''" name="name" class="round" value="name" size="20" /> <input type="text" onclick="this.value=''" name="email" class="round" value="email" size="20"/> <input type="submit" class="round" name="Submit" value="Register Your interest"/> </form> </div> <?php if (isset($_POST['Submit'])) { if ($_POST['name'] != "") { $name = filter_var($_POST['name'], FILTER_SANITIZE_STRING); if (!filter_var($name, FILTER_SANITIZE_STRING)) { $errors .= '* Please enter a valid name.<br/><br/>'; } } else { $errors .= '* Please enter your name.<br/>'; } if ($_POST['email'] != "") { $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors .= "* $email is <strong>NOT</strong> a valid email address "; } } else { $errors .= '* Please enter your email address.<br/>'; } if (!$errors) { $hostname = "###"; $username = "###"; $dbname = "###"; $password = "###"; $con = mysql_connect ("$hostname", "$username", "$password"); if (!$con) { die ('Could not connect: ' . mysql_error ()); } mysql_select_db ("###", $con); $sql = "INSERT INTO NLCUP (name, email) VALUES ('$name', '$email')"; echo '<p style="color: white; margin-left:105px; font-size:22px; padding-top:15px">* Thankyou, we will be in touch soon!<br></p>'; } else { echo '<p style="color: white; margin-left:105px; padding-top:15px">' . $errors . 'please try again.</p></div>'; } } ?> </div>
  12. changed line7 to $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL); and im now using $email and $name in my query, however issue still exists.
  13. I was expecting this code to add the users name and address to my database IF the email address existed in the first place. ELSE echo "sorry wrong email address" However I'm going wrong somewhere. The form echo's regardless of there being an email address set or not. Any ideas of where i'm going wrong on this one? <?php if (isset($_POST['email'])) { filter_var($_POST['email'], FILTER_SANITIZE_EMAIL); $hostname = "###"; $username = "###"; $dbname = "###"; $password = "###!"; $name = $_POST['name']; $email = $_POST['email']; $con = mysql_connect("$hostname","$username","$password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("###", $con); $sql="INSERT INTO ### (name, email) VALUES ('$_POST[name]','$_POST[email]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo ' <div id="main"> <div id="title">Thankyou! we will be in touch soon.</div> <div id="subheading"></div> <div id="mid"></div> <div id="form"> </div> </div> '; } else { echo "sorry wrong email address"; } mysql_close($con); ?>
  14. I'm a bit new to this, but I've gone into the page were talking about in ie and pressed f12, I've gone through the various tabs, profiling and debugging buttons and I can't find any errors. I've also tried Tools >> Internet Options >> Advanced Tab >> Browsing >> Check the "Display a notification about every script error" checkbox.
  15. This code works well in firefox and chrome, but in IE I have just a blank box and nothing happens when I click in the box. Can you tell my why this isnt working in IE? (tested on IE.9) <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.min.js" type="text/javascript"></script> <script> (function() { var elem = document.createElement('input'); elem.setAttribute('type', 'date'); if ( elem.type === 'text' ) { $('#date').datepicker({ dateFormat: 'dd-mm-yy', // defaultDate: +5 maxDate : +3 }); } })(); </script> </head> <body> <form> <input type="date" name="date" id="date" value=" " /> </form> </body> </html>
  16. A month or so ago @Barand ever so kindly helped create an sql query for me... SELECT month_table.month , IFNULL(AVG( yard ), 0) AS avscore FROM month_table LEFT JOIN `snag` ON month_table.month = MONTH( STR_TO_DATE( sdate, '%d/%m/%y' ) ) AND club = '3 wood' AND user_id = $user_id AND YEAR = $year GROUP BY `month`"; Since doing this, I have changed the name of 'sdate' to 'date' and ive changed it from a varchar column to a date column with the format yyyy-mm-dd or 2013-07-31 . Could anyone tell me how I can now update my query so that it works again?
  17. I have a list of dates in a varchar column 'sdate', in the following format dd/mm/yyyy I would like to change above the column type to date, and change all entries in the column to this format: yyyy-mm-dd Is this possible in an sql query?
  18. How can I change a date from YYYY-MM-DD to DD/MM/YYYY ? I have a date picker in a form which always posts in this format: 2013-01-30 When I process the form I would like to store this date into a variable but in this format 30/01/2013. So I need to replace dashes for slashes, and reverse the order of year, month, and date.
  19. Many thanks, I shall give this a go!
  20. @requinix, your link 'these' led to a page which gave in my opinion a really well explained example of prepared statements. However the comments left at the bottom of the page, say that the example was a bad one that contained mistakes. As somone that has given me plenty of advice before, what did you make of it?
  21. In the basic form below, how can I prevent an sql error if a user decides to use ' or " ? Is this where I should be using addslashes? I still would like words such as (I'm) to appear in the php echo below. <form method="get" action="editabout.php" style="border:0px" /><br /> <input name="title" class="title" readonly="readonly" value="about:" /><br /> <textarea name="about" class="aboutme"><?php echo $about; ?></textarea><br /> <input type="submit" name="submit" value="Save Change"/> </form> editabout.php <?php session_start(); include 'connectionhere.php'; $user_id = $_SESSION['user_id']; $about = $_GET['about']; $sql = "UPDATE registration SET about='$about' WHERE user_id='$user_id'"; mysql_query($sql) or die (mysql_error()); header ("Location: profile.php"); ?>
  22. I've set up my database with a Competition column as a primary key, to prevent duplicate entries. How can I echo, a message to the user, informing them if they were unsuccessful in trying to add a duplicate entry? Here is what I have already tried; <?php if(isset($_POST['processForm'])) { $sql = "INSERT INTO Competitions (Competition) VALUES ('$_POST[compname]')"; mysql_query($sql); if (!$sql) { echo "This Name is already taken"; } else { echo '<p>Your New Competition is now up and running <a href="comptable.php"><img src="refresh.png"/><a/></p><br/>'; } }; ?>
  23. All sorted. I didn't declare a doctype. Thanks for the reply.
  24. Create your banner that you would like to use and save it as a separate file. eg. banner.php You can then include the whole file. eg. <?php include 'banner.php'; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.