Siggles Posted August 21, 2008 Share Posted August 21, 2008 Further up my code a variable is filled with a string. Eg, $text = 'thanks'; Later on i the code I write.. if (isset($text)) { echo $text; } Have I got the wrong understanding of how isset works? If I just put echo $text it works but I wanted to use isset to broaden what I am doing. Quote Link to comment https://forums.phpfreaks.com/topic/120694-solved-isset-problem-or-missunderstanding/ Share on other sites More sharing options...
MasterACE14 Posted August 21, 2008 Share Posted August 21, 2008 yeah, thats fine how you're using it. But a more common way to use isset() is for variables passed from 1 page to another. by either POST or GET method. for example: <?php if(isset($_GET['text'])) { echo $_GET['text']; } else { echo "text is not set!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/120694-solved-isset-problem-or-missunderstanding/#findComment-621910 Share on other sites More sharing options...
Siggles Posted August 21, 2008 Author Share Posted August 21, 2008 Quote yeah, thats fine how you're using it. But a more common way to use isset() is for variables passed from 1 page to another. by either POST or GET method. for example: <?php if(isset($_GET['text'])) { echo $_GET['text']; } else { echo "text is not set!"; } ?> Basically, someone submits a form to the same page, then a switch statement at the top of the page proccesses the POST variables and the result of that populates the text varaible with a message. I wanted to use something like isset so that I can add html in if it is set and not, if it isn't. Quote Link to comment https://forums.phpfreaks.com/topic/120694-solved-isset-problem-or-missunderstanding/#findComment-621914 Share on other sites More sharing options...
peddel Posted August 21, 2008 Share Posted August 21, 2008 isset checks for a true or false variable, the way u fill in u check if there is a variable $text, wich is in this case ALWAYS true so ur code works i also agree on master that his way is more common Quote Link to comment https://forums.phpfreaks.com/topic/120694-solved-isset-problem-or-missunderstanding/#findComment-621915 Share on other sites More sharing options...
Siggles Posted August 21, 2008 Author Share Posted August 21, 2008 Quote isset checks for a true or false variable, the way u fill in u check if there is a variable $text, wich is in this case ALWAYS true so ur code works i also agree on master that his way is more common then i still dont understand why it doesn't echo to the screen. Here is snippets of the full code. if (eregi('^[0-9]$', $presultmfc) && eregi('^[0-9]$', $presultother)) { mysql_query("INSERT INTO predictions (datecreated, username, id, resultmfc, resultother, score, lasteditedby) VALUES ('$datecreated', '$pusername', '$pid', '$presultmfc', '$presultother', '$pscore', '$adminlgd')"); $formsubtext='Enter a number between 0 and 9'; } else { $formsubtext='Prediction Submitted'; } then later in the code... <tr> <td colspan="4" align="left" class="style6" style="padding: 2px">Enter the User's Prediction below...</td> </tr> <?php if (isset($formsubtext)) { echo "<tr><td>"; echo $formsubtext; echo "</td></tr>"; } ?> <tr> Quote Link to comment https://forums.phpfreaks.com/topic/120694-solved-isset-problem-or-missunderstanding/#findComment-621918 Share on other sites More sharing options...
Siggles Posted August 21, 2008 Author Share Posted August 21, 2008 Oh b**ls. It works. Sorry :-( Quote Link to comment https://forums.phpfreaks.com/topic/120694-solved-isset-problem-or-missunderstanding/#findComment-621922 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.