phpjayx Posted December 22, 2012 Share Posted December 22, 2012 So after successfully getting a database value called VIEW1, I want to look at that value either go to view1.php or view.php. I attempted to put a simple PHP if statement in my HTML code, but no luck. I'm assuming because it only runs once when the page loads?. I tried it in my Javascrips, but no luck there..... I'm a begginner at this and still learning... Can someone suggest an approach to take of where and what code to put in? Thanks for the help -------------basic HTML form.... <form action="view1.php" method="post" id="form_submit"> <input name="userid" class="invinsible" id="userid_submit" > <input name="message1" class="invinsible" id="message1_submit" > <input value="Go to view1" type="button" onclick="onclickSubmit();" > </form> Quote Link to comment https://forums.phpfreaks.com/topic/272293-html-php-help-with-if-statement-based-off-of-db-value/ Share on other sites More sharing options...
MDCode Posted December 22, 2012 Share Posted December 22, 2012 You have not explained your issue well at all. I have no idea what you are trying to do or what you mean by "it only runs once when the page loads" but you could just do something like this <?php // If a form was submitted if($_SERVER['REQUEST_METHOD'] === "POST") { // load all the data you're talking about here // if $view1 equals whatever would go to view1.php, go to view1.php if($view1 == "something") { header("Location: view1.php"); die; // If it doesn't, go to view.php } else { header("Location: view.php"); die; } } ?> <html> <head></head> <body> <form method="post" id="form_submit"> <input name="userid" class="invinsible" id="userid_submit" > <input name="message1" class="invinsible" id="message1_submit" > <input value="Go to view1" type="button" onclick="onclickSubmit();" > </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/272293-html-php-help-with-if-statement-based-off-of-db-value/#findComment-1400929 Share on other sites More sharing options...
phpjayx Posted December 23, 2012 Author Share Posted December 23, 2012 Sorry, your right that wasn't the best written up issue.... I wasn't able to get yours to work, it just blew away my buttons after I logged on.... Here is the full code of what I had previously...... But this didn't work. I meant by that it only runs once... was just my theory that it only looked at the PHP IF code on startup, but not after I allowed the user to LogIn. I don't know if thats how it works... Also in your code where you say ....// load all the data you're talking about here Sorry for being a newbie with PHP, but is this the echo $view1; command or something else? <?php if($view1=="1") : ?> <form action="view.php" method="post" id="form_submit"> <?php else : ?> <form action="view1.php" method="post" id="form_submit"> <?php endif; ?> <input name="userid" class="invinsible" id="userid_submit" > <input name="message1" class="invinsible" id="message1_submit" > <input value="Go to other view" type="button" onclick="onclickSubmit();" > </form> Quote Link to comment https://forums.phpfreaks.com/topic/272293-html-php-help-with-if-statement-based-off-of-db-value/#findComment-1400961 Share on other sites More sharing options...
hyster Posted February 14, 2013 Share Posted February 14, 2013 u want something like this <?php //depends on how ur passing the data $data = $_GET['value']; or $data = $_POST['value'] if($data=="1") { $page = "view1.php"; }else{ $page = "view.php"; } ?> some html <form action="./<?php echo $page ?>" method="post" id="form_submit"> some html Quote Link to comment https://forums.phpfreaks.com/topic/272293-html-php-help-with-if-statement-based-off-of-db-value/#findComment-1412374 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.