Jump to content

Recommended Posts

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.

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

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

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>

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.