Results 1 to 8 of 8

Thread: PHP submit from same page ?

  1. #1

    Thread Starter
    Fanatic Member kevin_sauerwald's Avatar
    Join Date
    Feb 2002
    Location
    outside Philly
    Posts
    516

    PHP submit from same page ?

    ok I'm learning PHP from scratch.. and I'm no expert in HTML either.. here is what I'm trying to do.. looking for best approach..

    website to ask some questions in banks of like 5.... to a table would have like 5 questions on it.. and first data in the row would have a submit button to then
    capture all those answers to mysql db..

    now I kinda know how to make code take the data on the submit for a POST and then pass to a php page that can push to mysql.. but I dont want to go
    off that page.. in all the examples I see.. and have tested when you make the
    action the php page.. it comes up a blank page and does what the php page
    says to do.. is there a way to run the php script and stay on the same page ?

    I guess worst case I can make it flash thanks from the php page but then reload the last one ? I have seen some posts where they say to make the action blank.. but I keep getting errors on the page.. I assume I'm mixing my HTML and php wrong on my page..

    any examples someone can give me ? or a website to visit for some good info ?

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: PHP submit from same page ?

    You can do AJAX submission of form data to the PHP page and display a result say "Thanks for posting" or "Sorry there were some errors !" like that, with out refreshing the actual page !

    Google it, you'll find lots of examples and tutorials

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3

    Thread Starter
    Fanatic Member kevin_sauerwald's Avatar
    Join Date
    Feb 2002
    Location
    outside Philly
    Posts
    516

    Re: PHP submit from same page ?

    Thanks.. looked that up and it should work for what I need to do.. question
    though.. for AJAX can you make it pass lots of data ? or only small ? in reading it said its good for small data chunks..

    I'm making a UI for a website that you can enter in new data to be viewed on
    the website.. in the UI you enter some fields and select things.. then submit
    and all that data needs to go into a mySql db.. so I'm thinkin Ajax is not good
    for this.. and I should just make this page actually call a full script page where
    I can get easier access to the inputs from the calling page.. and not try to AJAX pass all that data to the php page that will do inserts ?

  4. #4
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: PHP submit from same page ?

    I think it's okay to send large amount of data. For this, use the POST method instead of the GET.
    If it is very large amount of data, just display a "loading bar" inorder to inform the user that the data is sending. And when you the data is finished sending, display a success message in place of the loading bar.

    Can you give me an example of what all data you'll be going to pass ?


    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  5. #5

    Thread Starter
    Fanatic Member kevin_sauerwald's Avatar
    Join Date
    Feb 2002
    Location
    outside Philly
    Posts
    516

    Re: PHP submit from same page ?

    I actually just wrote it all in a php page.. but this is what I'm trying to write to a sql Db.. from the submit button.. combo of radio button values, check boxes and text data

    Code:
    $Category = $_POST['Category'];
    $Question = $_POST['QuestionText'];
    $SelectType = $_POST['SelectType'];
    $RosterSelect = $_POST['RosterSelect'];
    $AnswerText1=$_POST['AnswerText1'];
    $AnswerText2=$_POST['AnswerText2'];
    $AnswerText3=$_POST['AnswerText3'];
    $AnswerText4=$_POST['AnswerText4'];
    $AnswerText5=$_POST['AnswerText5'];
    $checkBox = $_POST['Check'];
    for($i=0; $i<sizeof($checkBox); $i++){
    //$query = "INSERT INTO table(things) values('".$checkBox[$i]."')";
    //mysql_query($query) or die(mysql_error());
    echo "$checkBox[$i]<br>";
    }

  6. #6
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: PHP submit from same page ?

    I think, it would be a good choice if you use something to prevent sql injection aslo: use PDO with prepared statements or MySQLi with prepared statements or mysql_real_escape_string()


    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  7. #7
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: PHP submit from same page ?

    I reread your original question a few times and from what i understand, AJAX may not be necessary.

    If you are on page x. You want to submit your form and end up back at page x with the same form correct?

    Just set the action the the same page, and put the PHP code on that page. AJAX is to save without a form load.

  8. #8

    Thread Starter
    Fanatic Member kevin_sauerwald's Avatar
    Join Date
    Feb 2002
    Location
    outside Philly
    Posts
    516

    Re: PHP submit from same page ?

    well lemme explain further what I want to do.. and you guys tell me..

    there will be banks of questions in rows.. at the front of a row will be
    a submit button for that row.. I just want to be able to have
    the user hit the submit button and really not see anything happen to
    that page.. I may make the frame around the question change color to
    indicate you are done that bank or something.. but thats the jist of
    what I'm trying to do.. so Ajax or PMP and HTML on same page ? I was messing
    with the PMP and HTML on the same page but always seemed to do
    something goofy so I gave up.. most likely newbie coding issue..

    And I definitely need to use sp's...
    Last edited by kevin_sauerwald; Feb 12th, 2012 at 01:04 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width