This is killing me...please help.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

This is killing me...please help.

Post 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?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Line 121 reads...
If it's the above in, display the part of the code where the variable get's set.
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

JAM

Post 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)?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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...
Post Reply