Jump to content

undefined constant


DataSpy

Recommended Posts

Basically I'm trying to get a value from a database and use an if elseif else to reassign the variable but I'm getting a 'Use of undefined constant' error.

 

Error

Notice: Use of undefined constant Yes - assumed 'Yes' in /opt/lampp/htdocs/xampp/www/test.php  on line 137

 

Code

while($row = mysql_fetch_array($result)){
$main_title = $row['main_title'];
$romanji = $row['romanji'];
$link = $row['link'];
$episodes = $row['episodes'];
$complete = $row['complete'];
$disc_num = $row['disc_num'];
$type = $row['type'];
$format = $row['format'];
$extention = $row['extention'];
$fsgroup = $row['fsgroup'];

if($complete == "1"){
$complete = Yes;  <== this is line 137
} elseif($complete == "2"){
$complete = No;
}else {
$complete = NA;
}

 

This is user enter data and the choices are Yes, No, or NA from a drop down menu

 

Would it be better to:

1. Store Yes, No, NA in the database

2. Store 1,2,3 in the database and use a conditional against them (which is what I'm trying to do now)

3. Have a separate table for Yes, No, and NA

 

Even though I know I won't use it I'm trying to make the database as efficient as possible, it's more of a learning thing.

 

Any help would be greatly appreciated, thanks in advance!

Link to comment
Share on other sites

Strings need to be enclosed in quotes (either single or double)

<?php
if($complete == "1"){
$complete = 'Yes';  <== this is line 137
} elseif($complete == "2"){
$complete = 'No';
}else {
$complete = 'NA';
}
?>

But you really shouldn't be using the same variable:

<?php
if($complete == "1"){
$complete1 = 'Yes';  <== this is line 137
} elseif($complete == "2"){
$complete1 = 'No';
}else {
$complete1 = 'NA';
}
?>

 

Ken

Link to comment
Share on other sites

Would it be better to:

1. Store Yes, No, NA in the database

2. Store 1,2,3 in the database and use a conditional against them (which is what I'm trying to do now)

3. Have a separate table for Yes, No, and NA

 

1. For your purposes, I would say yes. Unless there is some functional reason for using 1,2,3 I'd just use the values (see exceptions below).

 

2. This makes sense if you have some functional use for those values. One option could be to use 0 for false (no), 1 for true (yes) and NULL for N/A. you could then use the value directly in your logic without comaprisons to strings.

 

3. This makes sense if the list is not static (can be added or removed from) or if you want to allow the application to be used for different languages.

Link to comment
Share on other sites

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.