Undefined variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

Undefined variable

Post by cturner »

I have an undefined variable: propertyname error. My code is below:

Code: Select all

if (isset($_POST['propertyname'])) {
    $propertyname = str_replace("\r\n","",$_POST['propertyname']);
    $propertyname = stripslashes($propertyname);
    $propertyname = mysql_real_escape_string($propertyname);
}
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Notice: Undefined variable: propertyname in <file> on line <line>
For which line of code do you get the notice?
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

Post by cturner »

The error is on line 601. This what is on that line:

Code: Select all

if (!empty($arrErrors['propertyname'])) echo ' class="formerror"';
and this as well:

Code: Select all

<textarea name="propertyname" cols="50" rows="4"><?php echo $propertyname; ?></textarea>
For the first lot of syntax it is meant to display an error if the propertyname is blank.
User avatar
louie35
Forum Contributor
Posts: 144
Joined: Fri Jan 26, 2007 8:40 am
Location: Dublin
Contact:

Post by louie35 »

if you have this code

Code: Select all

if (isset($_POST['propertyname'])) { 
    $propertyname = str_replace("\r\n","",$_POST['propertyname']); 
    $propertyname = stripslashes($propertyname); 
    $propertyname = mysql_real_escape_string($propertyname); 
}
above the lines that you get the error is because indeed you have an undefined variable.
The above code only sets the variable if the post was made otherwise there is none so add this above you code:

Code: Select all

$propertyname = "";//or you could say $propertyname = NULL;
//then your code here
if (isset($_POST['propertyname'])) { 
    $propertyname = str_replace("\r\n","",$_POST['propertyname']); 
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
}
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

Post by cturner »

Problem is solved. Thanks to louie35.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

cturner wrote:Problem is solved. Thanks to louie35.
Yeah, he's certainly a talented one.
*bow*
Post Reply