smc Posted January 21, 2007 Share Posted January 21, 2007 Hello,Okay basically my deliuma is that I had one php script. This PHP is going to add users to a database. When you go to the page the PHP detects that a variable "submit" is not defined as true so I want it to show the HTML that has the forms and submit button, etc. When you click the submit button the script goes back to itself but with the ending ?submit=true to declare that it has been infact submitted, then proccess and adds the information to the PHP. My problem is I want it when it is submited to show an HTML on the page that says it's submitted as opposed to the HTML showing the forms.In essence, I need to load different HTML for different instances in the same PHP script.How do I do this? Quote Link to comment https://forums.phpfreaks.com/topic/35052-newb-question-loading-html-in-one-instance-and-another-html-in-another/ Share on other sites More sharing options...
utexas_pjm Posted January 21, 2007 Share Posted January 21, 2007 Trivial example:[code]<?phpif($_GET['submit']){?> <p>You've successfully submitted my trivial form. Tada.</p><?php}else{?> <form action='test.php'> <input type='hidden' name='submit' value='1' /> <input type='submit' name='formSubmit' value='submit' /> </form><?php}?>[/code]Best,Patrick Quote Link to comment https://forums.phpfreaks.com/topic/35052-newb-question-loading-html-in-one-instance-and-another-html-in-another/#findComment-165410 Share on other sites More sharing options...
Ninjakreborn Posted January 21, 2007 Share Posted January 21, 2007 I personally have it like this[code]<?phpif (isset($_POST['submit'])) {// validate// errorcheck// clean// process from db// update builder (entry whatever)if (mysql_query($query)) {$show = "yes";}}?><?phpif ($show != "yes") {?><!-- XHTML/CSS form right here, with submit button --><?php}?>[/code]Seems to just be the way I always have done it when I do same page processing. Quote Link to comment https://forums.phpfreaks.com/topic/35052-newb-question-loading-html-in-one-instance-and-another-html-in-another/#findComment-165428 Share on other sites More sharing options...
smc Posted January 21, 2007 Author Share Posted January 21, 2007 Perfect! Exactly what I needed, thanks :)One more question I have on this subject though is that is there anyway way to call an HTML page into the if else functions. ie: Having two complete page sets of HTML can get a bit messy, is there any way to have the HTML external and call it in depending on the situation?Thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/35052-newb-question-loading-html-in-one-instance-and-another-html-in-another/#findComment-165643 Share on other sites More sharing options...
utexas_pjm Posted January 21, 2007 Share Posted January 21, 2007 There is. The best way would be to implement some 2 or 3 tier architecture i.e., MVC but this introduces quite a bit of overhead and requires some knowledge of object oriented paradigms. You can achieve what you are after using the PHP include construct. We would modify the afore mentioned code as follows:[code]<?phpif($_GET['submit']){ include 'success.php';}else{ include 'someForm.php'; }?>[/code]Where success.php and someForm.php contain their respective html from the previous example. I hope this was of some help.Best,Patrick Quote Link to comment https://forums.phpfreaks.com/topic/35052-newb-question-loading-html-in-one-instance-and-another-html-in-another/#findComment-165661 Share on other sites More sharing options...
smc Posted January 21, 2007 Author Share Posted January 21, 2007 That worked perfectly, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/35052-newb-question-loading-html-in-one-instance-and-another-html-in-another/#findComment-165714 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.