Page 1 of 1

Undefined variable

Posted: Sat Jan 27, 2007 3:31 pm
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);
}

Posted: Sat Jan 27, 2007 3:34 pm
by volka
Notice: Undefined variable: propertyname in <file> on line <line>
For which line of code do you get the notice?

Posted: Sat Jan 27, 2007 3:52 pm
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.

Posted: Sat Jan 27, 2007 4:00 pm
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']); 
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
}

Posted: Sat Jan 27, 2007 4:05 pm
by cturner
Problem is solved. Thanks to louie35.

Posted: Sat Jan 27, 2007 4:13 pm
by superdezign
cturner wrote:Problem is solved. Thanks to louie35.
Yeah, he's certainly a talented one.
*bow*