How can I post form data to another php page (without redirecting)

Discussion in 'PHP' started by mani2604, Oct 21, 2010.

  1. #1
    Hi everyone...


    Well i do have a mysql query in one php page(php_1) & I want to submit the variables to the query in different php page(php_2) via form action but how am I supposed to do it without redirecting to php_1..

    All I need is to post the data to the first php page query so that It performs some action over there & thats all...

    php_1 page :-
    $query = ("SELECT * FROM state4 WHERE (LONG_HI<'".$_POST['Ymax']."')");
    
    Code (markup):
    php_2 page:-
    Ymax<input type="text" name="Ymax" size="15">
    	      <input type=SUBMIT name="submit" VALUE="Submit"></td>  
    Code (markup):
     
    mani2604, Oct 21, 2010 IP
  2. TechDesigner

    TechDesigner Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You will have to use Ajax to send data without a refresh / redirect.
     
    TechDesigner, Oct 21, 2010 IP
  3. kai555

    kai555 Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi

    sounds like you want to use Ajax. Ajax allows you to submit information to the server without refreshing the page.

    You will have to write a Javascript function that submits the form when you click on the submit button.

    Hope this helped.
     
    kai555, Oct 21, 2010 IP
  4. TheDataPlanet.com

    TheDataPlanet.com Well-Known Member

    Messages:
    503
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #4
    TheDataPlanet.com, Oct 21, 2010 IP
  5. mani2604

    mani2604 Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    well looks like the answer is unanimous.... AJAX?????

    I really dont know wat I am goin' to do now
     
    mani2604, Oct 21, 2010 IP
  6. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #6
    Emm it sounds like your making things more complicated then they need to be, is it a problem to put the query on php_2, its the same site right ?

    Then you just use php function isset
     
    MyVodaFone, Oct 21, 2010 IP
  7. Tastyweb

    Tastyweb Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    MyVodaFone is right - if there's nothing stopping you from having the form generated by the same php page that processes it, that's a much simpler solution than invoking ajax, especially if you're not familiar with ajax techniques.
     
    Tastyweb, Oct 21, 2010 IP
  8. mani2604

    mani2604 Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    well cud u be more specific... I really didn't get u..

    yup its the same site.. actually php_1 just generates an image with some overlays from the query && the thing is we do use the Url of php_1 to embed the image in our mapserver framework... So we do always stay on php_2 page & somehow i need to post the variables to php_1 for query purposes....
     
    mani2604, Oct 21, 2010 IP
  9. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #9
    When you submit your text $_POST['Ymax'] gets populated and your query will run
    
    <?php
     if (isset($_POST['Ymax'])) { 
     $query = ("SELECT * FROM state4 WHERE (LONG_HI<'".$_POST['Ymax']."')");
         //.. and the rest of your code from php_1 if needed goes here.
      }
    ?>
    
    PHP:
     
    MyVodaFone, Oct 21, 2010 IP
  10. djarotstudio

    djarotstudio Member

    Messages:
    200
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    33
    #10
    if AJAX is an alien for you, the isset would be your way. one page only. Go with MyVodaFone pointer.
     
    djarotstudio, Oct 21, 2010 IP
  11. pro-php-developer

    pro-php-developer Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    The isset seems simple
     
    pro-php-developer, Oct 21, 2010 IP
  12. mani2604

    mani2604 Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Sory but wat shud be the form action in php_2 page... I am still being redirected
     
    mani2604, Oct 22, 2010 IP
  13. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #13
    You need to post your full codes from both php_1 and 2 here, otherwise we are only guessing how to fix it for you...

    EDIT: failing that remove the action="php_1.php" from your <form, if you have that.
     
    Last edited: Oct 22, 2010
    MyVodaFone, Oct 22, 2010 IP
  14. mani2604

    mani2604 Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    well here they are :-

    php_1 :- pastebin.com/pZTRd6hp

    php_2 :- pastebin.com/2zCsfiKN
     
    mani2604, Oct 22, 2010 IP
  15. sincos

    sincos Active Member

    Messages:
    64
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    51
    #15
    a example too it's use iframe with target to that frame.
    
    <form action="php2.php" target="desc" method="post">
    Ymax<input type="text" name="Ymax" size="15">
    	      <input type=SUBMIT name="submit" VALUE="Submit"></td>
    </form>
    <iframe name="desc" width="100" height="100"></iframe>
    
    PHP:
     
    sincos, Oct 22, 2010 IP
  16. flight05

    flight05 Active Member

    Messages:
    122
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    61
    #16
    You could set the target to an iframe. And submit the form onload with javascript.
     
    flight05, Oct 22, 2010 IP
  17. xpertdev

    xpertdev Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    very simple, use AJAX...
     
    xpertdev, Oct 22, 2010 IP
  18. Thorlax402

    Thorlax402 Member

    Messages:
    194
    Likes Received:
    2
    Best Answers:
    5
    Trophy Points:
    40
    #18
    If it is not a problem to reload the page you are on, then using the isset() function to check for posted variables would work perfectly. As described above, simply use a conditional to look for the posted data and make sure your form action is set to the currect page instead of the second page you were using before.

    If you would rather submit the form without reloading the page at all, you should look into using AJAX, it will give off the appearance that pressing the submit button instantly completed its task instead of going to another page first.


    The option is yours depending on how you want your users to see it. I'd have to agree with everyone else though. Using isset() would be much simpler. It is essentially the same method you are using, but your page1 and page2 are merged together.
     
    Thorlax402, Oct 22, 2010 IP
  19. AnoxiA

    AnoxiA Peon

    Messages:
    27
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #19
    are you all insane? you dont need AJAX for this, the isset solution seems perfect.
     
    AnoxiA, Oct 22, 2010 IP