1 Replies - 834 Views - Last Post: 14 September 2013 - 02:42 PM Rate Topic: -----

#1 mutago234  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 151
  • Joined: 08-September 13

how to automatically refresh a page on form submission

Posted 14 September 2013 - 01:19 PM

Can someone tell me how to automatically refresh a page on form submission

using either php, ajax or javascript

below is my code

<?php               
               

require('db.php');


$addedby=strip_tags($_POST['addedby']);
$rrt=strip_tags('accepted');
$requested=strip_tags($_SESSION['SESS_MEMBER_ID']);


 $statement = $db->prepare('INSERT INTO friends ( addedby, requested, status)
                          values
                ( :addedby,:requested,:status)');


         $statement->execute(array(
            ':addedby' => $requested,
                         ':requested' => $addedby,
            ':status' => $rrt));


// automatically refresh page on form submission on server side
using either php, ajax or javascript

?>



<html><head></head>
<form method="POST" name="" action="insert.php">
<input name="added" type="text"/>
<input name="submit" type="submit"/>
</form>
</body>
</html>


This post has been edited by andrewsw: 14 September 2013 - 01:21 PM
Reason for edit:: Fixed code tags


Is This A Good Question/Topic? 0
  • +

Replies To: how to automatically refresh a page on form submission

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3716
  • View blog
  • Posts: 5,976
  • Joined: 08-June 10

Re: how to automatically refresh a page on form submission

Posted 14 September 2013 - 02:42 PM

When you say "refresh", you mean "redirect back to the form"? The form submission redirects you to the "insert.php" file. If you want to show the form again, you need to redirect from there and back to the form. To do that from the server side, the best solution is to send back a HTTP header with the response, telling the browser to go to another location. You can use the header() function to do that. (The docs have an example showing how to do this.)


Also, you are overusing the strip_tags function again. I've mentioned this to you in other threads before a few times. That function should not be used just anywhere on any data aimed at the database. It is meant to remove HTML code from user input when printing it, to prevent XSS injection. Using it like you use it there does not make sense. - That goes doubly for line #8, where you are actually running a hard-coded string ("accepted") through the function. That is just nonsensical. I suggest you go thoroughly through the doc entry I linked to and learn what the function does, and where to use it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1