PHP - Moved: Fetch Info Without Reloading Page (when Clicking Submit Button - Ajax?)
This topic has been moved to Ajax Help.
http://www.phpfreaks.com/forums/index.php?topic=326913.0 Similar TutorialsSo, I just don't know where to post this question. I've written a quiz program where 50 English vocab words are pulled from a dB and displayed on one page with the order scrambled. My students then type the Spanish translation for each. When they submit the form the next page grades their work. They have to get a 90 or better for the grade to be automatically recorded, so I want them to click the back button and go back and make corrections. The problem is when they use a Chrome browser and click the back button the program re-sorts the order of questions. It leaves the order of their answers the same. So what they answered for number 1 is still in the field for number 1, but the questions (the English vocab word) is different. Chrome does this consistently so I thought this was a Chrome issue only. Then one of my students said the same thing happened to her when using Safari. So here is my question, how can I stop Chrome (or any other browser) from re-running my server-side PHP scripts (re-sorting the vocab array) when clicking the back button?
Here is the code for students taking the quiz:
<form method="post" action="portal.php?load=vquiz_grade" style="margin-left: 50px; line-height: 30px;">
$max = $count-1;
?>
//print "<br>";
<input type="hidden" name="max" value="<?print $max?>"> And here is the code showing them what they missed.
<?
// Total grade
print "You missed ".$wcount." words.<br>";
print "<table>";
// Grade response and set color
if ($wrong == 1){ if ($grade >= 90){
$query = "SELECT * FROM inno_vocab_assignments WHERE key_code = '$key_code' AND uname = '$secure_uname' AND teacher = '$teacher'";
// Prevent student from changing vocab list so as to do an easier list
// Insert grade
}
Thank you!
Hello, I have links at above of the page. if i click a link a new page will appear. The menu links above are same for all pages. Which is better reloading the whole page with all menu links or keeping the above menu link permanent/unchange reloading bottom division with ajax? I mean only one page will contain the menu.Is it better? Or every page will contain the menu above.Is it better then the first one? I say many web site they have link menus above if i click a link from above it seems the whole page reloads or chages. For example:http://www.sitepoint.com/ Thank you. This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=357107.0 here my sample code <form> <input id="query" type="text" name="query" placeholder="search here..." autocomplete="off"> <button type="submit" value="query" >search</button> <div class="sugbx"></div> </form> //php code, assume we already run a whole php code ...... <ul class="list-group list-unstyled" style="cursor:pointer; color: #191919; position:absolute; top:12px;"> <?php foreach($query as $movie) { ?> <li class="list-group-item" onClick="searchValue('<?php echo $movie["movie_name"]; ?>'),;"><?php echo $movie["movie_name"]; ?></li> <?php } ?> </ul> <?php } ?> //ajax here $('#search').keyup(function(){ $.ajax({ type: 'GET', url: 'phpcode.php', data:'query='+$(this).val(), success: function(data){ $('.sugbx').show(); $('.sugbx').html(data); } }); }); function searchValue(val) { $('#query').val(val); $('.sugbx').hide(); } //ajax the input accept the value only after selecting one of the listed value on the suggesstion box and then i have to click the submit button the problem is, how to submit the value accepted when a list is clicked Dear All I have a form say i have selected Volva from drop down box . So without clicking on submit button when i move to next field that is `<input>` the value that is volva should get store in php variable <html> <body> <form action=""> <select name="cars"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="fiat">Fiat</option> <option value="audi">Audi</option> </select> <input type="text" name="abc" /> </form> </body> </html> Folks,
Look at this weird thing. I load the page and get echoed as expected: Did Not REQUEST_METHOD! Then, I click the SUBMIT button and to my astonishment I get echoed: Did Not POST->Submit! Got 2 buttons. Same result whenever clicking any. Why is that ? Check it out:
<?php //include('error_reporting.php'); ini_set('error_reporting',E_ALL);//Same as: error_reporting(E_ALL); ini_set('display_errors','1'); ini_set('display_startup_errors','1'); ?> <form name = "submit" method = "POST" action=""> <label for="domain">Domain:</label> <input type="text" name="domain" id="domain" placeholder="Input Domain"> <br> <label for="domain_email">Domain Email:</label> <input type="email" name="domain_email" id="domain_email" placeholder="Input Domain Email"> <br> <label for="url">Url:</label> <input type="url" name="url" id="url" placeholder="Input Url"> <br> <label for="link_anchor_text">Link Anchor Text:</label> <input type="text" name="link_anchor_text" id="link_anchor_text" placeholder="Input Link Anchor Text"> <br> <textarea rows="10" cols="20">Page Description</textarea> <br> <label for="keywords">Keywords:</label> <input type="text" name="keywords" id="keywords" placeholder="Input Keywords related to Page"> <br> <input type="checkbox" name="alert_visitor_type" id="alert_visitor_type" value="Give Alert: Visitor Type"> </label for="alert_visitor_type">Give Alert: Visitor Type</lablel> <input type="checkbox" name="alert_visitor_potential" id="alert_visitor_potential" value="Give Alert: Potential Visitor"> </label for="alert_visitor_potential">Give Alert: Potential Visitor</lablel> <br> <input type="radio" name="tos_agree" id="tos_agree_yes" value="yes"> <label for="tos_agree_yes">Yes:</label> <input type="radio" name="tos_agree" id="tos_agree_no" value="no"> <label for="tos_agree_no">No:</label> <br> <label for="tos_agreement">Agree to TOS or not ?</label> <select name="tos_agreement" id="tos_agreement"> <option value="yes">Yes</option> <option value="no">No</option> </select> <br> <button type="submit" value="submit">Submit</button><br> <button type="submit">Submit</button> <br> <input type="reset"> <br> </form> <?php if($_SERVER['REQUEST_METHOD'] === 'POST') { if(isset($_POST['submit'])) { mysqli_report(MYSQLI_REPORT_ALL|MYSQLI_REPORT_STRICT); mysqli_connect("localhost","root","","test"); $conn->set_charset("utf8mb4"); $query = "INSERT into links (domain,domain_email,url,link_anchor_text,page_description,keywords,alert_visitor_type,alert_visitor_potential) VALUES (?,?,?,?,?,?,?,?)"; $stmt = mysqli_stmt_init($conn); if(mysqli_stmt_prepare($stmt,$query)) { mysqli_stmt_bind_param($stmt,'ssssssss',$_POST['domain'],$_POST['domain_email'],$_POST['url'],$_POST['link_anchor_text'],$_POST['page_description'],$_POST['keywords'],$_POST['alert_visitor_type'],$_POST['alert_visitor_potential']); if(mysqli_stmt_execute($stmt) === FALSE) { die("Error\" . mysqli_stmt_error()"); } mysqli_stmt_close($stmt); mysqli_close($conn); } else { die("Did not INSERT!"); } } else { die("Did Not POST->Submit!"); } } else { die("Did Not REQUEST_METHOD!"); } ?>
This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=341998.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=305930.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=314750.0 Hello. I hope one of the PHP/HTML gurus here can help me. I have a web page that has been altered a bit to add some Google Analytics stuff and I've moved it to a 2nd directory. The original one works fine, the 2nd one won't post the form when I click the submit button. 1st URL https://www.theneutralizer.info/neutralizer 2nd URL: https://www.theneutralizer.info/neutralizer2 I have changed the action property to the correct script, and it does exist. But the problem is when clicking the button nothing happens. Anyone have any ideas? I can send the PHP code if needed, but since it's HTML output, it should work the way it is displayed in the browser. David This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=356816.0 This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=322542.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=305698.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=310879.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=305845.0 Hello, Im new to website building. I have created a login system. The login system echoes some text when the username and password is correct. However, if correct i would like it to open another page on my site. Code: [Select] <form name="form1" method="post" action=""> <p>Username <label> <input type="text" name="username" id="username"> </label> Password <label> <input type="password" name="password" id="password"> </label> <input name="login" type="submit" id="login" value="Login"> <?php $username = $_POST ["username"]; $password = $_POST ["password"]; if ($username == "admin" && $password == "password"){ echo"Logged In";} ?> </p> </form> I am a novice and learnt this via youtube. However, can't find a tutorial for what i want. Thanks Please, take a look to the following code.After clicking Next it goes to overview.php.Why when I click back on my browser to return to this page again, it is not returning back? When I click back I receive "Confirm Form Resubmission" message. After refreshing page it loads page. I guess problem is in "session_start();" part. Something to do with cookies. Please, help me it is very urgent for me. <?php session_start(); echo "<html> <head> <title>Hello World</title> <meta http-equiv='Content-Type' content='text/html; charset=Windows-1252'/> </head>"; require_once ('functions.inc'); if(!isset($_POST['userid'])) { echo "<script type='text/javascript'>"; echo "window.location = 'index.php'"; echo "</script>"; exit; }else{ session_register("userid", "userpassword"); $username = auth_user($_POST['userid'], $_POST['userpassword']); if(!$username) { $PHP_SELF = $_SERVER['PHP_SELF']; session_unregister("userid"); session_unregister("userpassword"); echo "Authentication failed " . "Please, write correct username or password. " . "try again "; echo "<A HREF=\"index.php\">Login</A><BR>"; exit; } } function auth_user($userid, $userpassword){ global $default_dbname, $user_tablename; $user_tablename = 'user'; $link_id = db_connect($default_dbname); mysql_select_db("d12826", $link_id); $query = "SELECT username FROM $user_tablename WHERE username = '$userid' AND password = '$userpassword'"; $result = mysql_query($query) or die(mysql_error()); if(!mysql_num_rows($result)){ return 0; }else{ $query_data = mysql_fetch_row($result); return $query_data[0]; } } echo "hello"; echo "<form method='POST' name='myform' action='overview.php'>"; echo "<input type='submit' value='Next'>"; echo "</form>"; ?> I have two pages. one is insert_events.php and the other is veiw_events. In insert_events i have a form which have a submit button. I want when i click on the submit button, it redirects me to the view_events.php page showing the events. Any idea about this problem will be appreciated. Thanks //my controller <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use DB; class homeController extends Controller { public function index() { $employee = DB::table('employee')->orderBy('id','desc')->get(); $department = DB::table('department')->orderBy('id','desc')->get(); return view('index', ['employee' => $employee , 'department' => $department]); } } //my routes Route::get('index','homeController@index'); //my view using blade temmplating engine @foreach($employee as $emp) <div class="employee"> <b>{{ $emp->name }} </b> <a href="employee/{{ $emp->id }}"> <p class="intro">{{ substr($emp->intro ,0, 50) }}...</p> </a> </div> @endforeach @foreach($department as $dep) <div class="department"> <b>{{ $dep->name }} </b> <a href="department/{{ $dep->id }}"> <p class="desc">{{ substr($dep->description ,0, 100) }}...</p> </a> </div> @endforeach I want to fetch using ajax, how can i do it, teach/help me I have two pages one is db.php and another is form.php. In form.php i have created a form which contains different fields and a submit button. But i want to write the queries in db.php. And when i click on the submit button the insert query in db.php should be executed and insert data in database but the focus remains on form.php. How can i do this??? Any Idea? |