Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP undefined variable using the if statement
Old 09-24-2010, 04:54 PM PHP undefined variable using the if statement
Skilled Talker

Posts: 96
Name: Joan
Trades: 0
Hey guys im new to php i dont really dont know much i dont know if what i did is possible or not but im getting and undefined variable error here does anyone know why? please help... here is the code

the variable undefined is $crem_vel


PHP Code:
$tipo $fif['Tipo de Servicio'];
if (
$tipo == "Cremacion con Velacion")
{
    
$crem_vel "Cremacion con Velacion";
}
else if (
$tipo == "Cremacion Directa")
{
    
$crem_dir "Cremacion Directa";
}
else if (
$tipo == "Sepultura con Velacion")
{
    
$sep_vel "Sepultura con Velacion";
}
else if (
$tipo == "Sepultura Directa")
{
    
$sep_dir "Sepultura Directa";
}
else if (
$tipo == "Traslado Guadalajara/Mexico DF")
{
    
$tras_df "Traslado Guadalajara/Mexico DF";
}
else if (
$tipo == "Traslado Guatemala")
{
    
$tras_gua "Traslado Guatemala";
}
else if (
$tipo == "Traslado Salvador/Honduras/Nicaragua")
{
    
$tras_sal "Traslado Salvador/Honduras/Nicaragua";
}
else 
{
    
$crem_vel $crem_dir $sep_vel $sep_dir $tras_df $tras_gua $tras_sal "";


Thanks

Last edited by stivens; 09-24-2010 at 04:55 PM..
stivens is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-24-2010, 05:52 PM Re: PHP undefined variable using the if statement
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Its a notice not an error. It means you're making a reference to $crem_vel, but it has not been declared. I don't see any references to $crem_vel in the code you provided, only assignments. Most likely what's happening is the script isn't executing the portion of the if statement where $crem_vel is assigned.

You should know that a script can function perfectly fine while still issuing notices; they're useful for debugging but can often be ignored. In a production environment you should at least set error reporting to E_ALL & ~E_NOTICE (everything but notices) if not disable errors messages all together (ie set display_errors to off).
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 09-24-2010 at 05:55 PM..
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 09-25-2010, 04:35 PM Re: PHP undefined variable using the if statement
Skilled Talker

Posts: 96
Name: Joan
Trades: 0
it shows it as an error, it doesnt run the rest of the script, the output is for a pdf form, im getting the data from the database, this is what i do the field is a checkbox list with 6 items, but for some reason this is the way it works i have to do a statement for each variable. just though it would work the other way, using just one statement for all the variables..

Thanks for the reply

PHP Code:
$tipo $fif['Tipo de Servicio'];
if (
$tipo == "Cremacion con Velacion")
{
    
$crem_vel "Cremacion con Velacion";
}
else
{
    
$crem_vel "";
}

$tipo1 $fif['Tipo de Servicio'];
if (
$tipo1 == "Cremacion Directa")
{
    
$crem_dir "Cremacion Directa";
}
else 
{
    
$crem_dir "";

  
$fdf_data_strings = ('crem_vel' => $crem_vel'crem_dir' => $crem_dir); 
.......
stivens is offline
Reply With Quote
View Public Profile
 
Old 09-27-2010, 02:01 PM Re: PHP undefined variable using the if statement
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Try initializing your variables at the top of the script and then changing them only if needed. For example,
PHP Code:
$crem_vel $crem_dir "";
$tipo $tipo1 $fif['Tipo de Servicio'];
if (
$tipo == "Cremacion con Velacion")
{
    
$crem_vel "Cremacion con Velacion";
}
if (
$tipo1 == "Cremacion Directa")
{
    
$crem_dir "Cremacion Directa";

Also, from the PHP site:
Quote:
Originally Posted by http://us2.php.net/manual/en/language.variables.basics.php
It is not necessary to initialize variables in PHP however it is a very good practice.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 09-27-2010, 05:17 PM Re: PHP undefined variable using the if statement
Skilled Talker

Posts: 96
Name: Joan
Trades: 0
Thank you very much!!! It worked great!!!
stivens is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP undefined variable using the if statement
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.22626 seconds with 12 queries