We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,183 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion
hello, im tyring to change script from another page. i would like to change (a > true) to false and back if need be. As a dropdown or radio selection, maybe using variables but everything i have tried i have no luck. <?php if (a > true ) print "a…

Sorry to butt in here, but wouldn't a checkbox be more appropriate for a true/false? Perhaps not, depending on the use case. If you cast the post data as boolean, you get the true/false:

<?php
if($_POST){
    $option = (bool) $_POST['option'];  

    if($option){
        header("Location: index.php");
    }

}?>
<form method="post">
    <input type="radio" name="option" value="1" checked="checked">True</option>
    <input type="radio" name="option" value="0">False</option>
    <input type="submit" name="submit" value="Go!">
</form>
diafol
Keep Smiling
Moderator
10,662 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,513
Skill Endorsements: 57

thanks
still on refresh returns to false..
maybe us session then make false Destroy the session ? just a thought...

<?php
$option = $_POST['option'];
if(!isset($option))
{
echo 'You have not submitted an option';
}
switch($option)
{
case 0:
// FALSE
echo 'This is false';
break;
case 1:
// TRUE
// re-direct to link 1;
$new_link = "test.php";
echo include 'test.php';
break;
default:
echo 'Invalid option';
break;
}
?>

    <form method="post">
    <input type="radio" name="option" value="1">True</option>
    <input type="radio" name="option" value="0">False</option>
    <input type="submit" name="submit" value="Go!">
TKO
Junior Poster in Training
70 posts since Mar 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Do you have an online example of what is happening when you re-fresh? A url or something?

phorce
Master Poster
738 posts since Jul 2011
Reputation Points: 63
Solved Threads: 91
Skill Endorsements: 16

pm sent

TKO
Junior Poster in Training
70 posts since Mar 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

By the way, the html I copied was wrong:

<form method="post">
    <input type="radio" name="option" value="1" checked="checked">True</option>
    <input type="radio" name="option" value="0">False</option>
    <input type="submit" name="submit" value="Go!">
</form>

Should be:

<form method="post">
    <input type="radio" id="optrue" name="option" value="1" checked="checked" /><label for="optrue">True</label>
    <input type="radio" id="opfalse" name="option" value="0" /><label for="opfalse">False</label>
    <input type="submit" name="submit" value="Go!">
</form>

@TKO

With regard to PMs, unless it's a personal one, please post all relevant info to the forum as this will help other users with a similar problem.

diafol
Keep Smiling
Moderator
10,662 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,513
Skill Endorsements: 57

@diafol The user requires something different to what they are posting. He wants the script to remember the option that they selected, without using Database. Any suggestions other than cookies? (Obviously they would expire after a set amount of time)! I can't think of any other way.

phorce
Master Poster
738 posts since Jul 2011
Reputation Points: 63
Solved Threads: 91
Skill Endorsements: 16

This is the reason why questions of this nature should be put to the forum as opposed to PM. This is related to the problem. WHen he mentioned 'refresh' I assumed he meant 'why isn't the form storing my data'.

The best way to my mind would be a session variable. You could use cookies of course. I find cookies a little fiddly and I tend not to use them very much anymore - especially following the ridiculous cookie legislation - not that that is relevant here.

Anyhow, seeing as TKO sent the PM to you, you should answer him. If he decides to post to the forum, it's open season. :)

diafol
Keep Smiling
Moderator
10,662 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,513
Skill Endorsements: 57

the only reason pm was sent was for link to file.
no harm intended

TKO
Junior Poster in Training
70 posts since Mar 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

@TKO, no harm made..

Are you clear what you want the script to do yet ha?

phorce
Master Poster
738 posts since Jul 2011
Reputation Points: 63
Solved Threads: 91
Skill Endorsements: 16

@TKO - no prob.

diafol
Keep Smiling
Moderator
10,662 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,513
Skill Endorsements: 57

This seems to be way to much trouble so i have decided to go a differant direction on the script.
I just made a script that will fwrite an include every time i hit "on"
and an "off" button that will erase only the content of the file.
Its a total of 5 files but i works.

THANK YOU phorce, diafol and Javvy for your PATIENCE and HELP.

TKO
Junior Poster in Training
70 posts since Mar 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Ok, mark as solved - if it is.

diafol
Keep Smiling
Moderator
10,662 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,513
Skill Endorsements: 57
Question Answered as of 8 Months Ago by phorce, diafol and Javvy

done, thanks

TKO
Junior Poster in Training
70 posts since Mar 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
 
© 2013 DaniWeb® LLC
Page rendered in 0.0951 seconds using 2.72MB