Jump to content

Html-Php Help With If Statement Based Off Of Db Value


Recommended Posts

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>

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>

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>

  • 1 month later...

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.