Page 1 of 1

This is killing me...please help.

Posted: Mon Oct 27, 2003 3:20 pm
by AliasBDI
I am pulling information from a database and it is stored in a SESSION as a variable. The variable is $newletter. In the database this field is a CHAR which will either have "0" or "1" in the record.

So I am displaying this variable in a form checkbox. Here is the code:

Code: Select all

<input type="checkbox" name="newsletter" value="<?php echo $newsletter; ?>">
I get an error of:
<ERROR Number="8" Description="Error: "Use of undefined constant userid - assumed &apos;userid&apos;" on line 121 of /home/httpd/vhosts/ticketblasters.com/httpdocs/students/manage.php."/>
Any ideas why?

Posted: Mon Oct 27, 2003 5:37 pm
by JAM
Line 121 reads...
If it's the above in, display the part of the code where the variable get's set.

JAM

Posted: Mon Oct 27, 2003 6:27 pm
by AliasBDI
Your question spawned a solution. I ran to where the SESSION variable was registered and boom...that was it. So I added the code to register the variable. And added an echo in my manage page (where the form lies). It echos correctly. I am now having a problem using the checkbox to display the record.

It should display as unchecked if the record has "0" or "" (nothing) in it. AND display as checked if the record has "1" in it.

How is that supposed to look (in contrary to what I have now - stated in my last post)?

Posted: Mon Oct 27, 2003 6:35 pm
by JAM

Code: Select all

<?php
    // setting it...
    $foo = 1;
?>
<input type="checkbox" name="newsletter" value="<?php echo $newsletter; ?>" <?php echo (isset($foo) ? 'CHECKED' : ''); ?>><br />
<?php
    // removing it...
    unset($foo);
?>
<input type="checkbox" name="newsletter" value="<?php echo $newsletter; ?>" <?php echo (isset($foo) ? 'CHECKED' : ''); ?>><br />
Try this, and you will get the picture. This is using the alternate if-then-else syntax...