954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Undefined Variable

I think I must be blind ;)

$Title = $_POST['title'];
    $Category = $_POST['category'];
    $Content = $_POST['article'];
    $Tags = $_POST['tags'];
    $Description = $_POST['description'];

//error below...
    
    $Title = addslashes($Title);

//error above...

    $Category = addslashes($Category);
    $Content = addslashes($Content);
    $Tags = addslashes($Tags);
    $Description = addslashes($Description);


I declared title the first time... $Title = $_POST['title']; ... no problems. Then I declare it again and I get the Undefined variable error. All of the other variables work just fine. What's the problem?

Joe34
Junior Poster in Training
92 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
 

display the value of $Title before that error line...and make that line as comment and tell whats the error...or whats the output....

echo $Title;
IIM
Junior Poster
165 posts since Jun 2011
Reputation Points: 46
Solved Threads: 37
 

Error is not because of $Title, its because of $_POST['title'].
Write if condition as shown below.

if(isset($_POST['title']))
	$Title = $_POST['title'];

Also you can use error_reporting function to rid of errors.

vibhaJ
Posting Shark
931 posts since Apr 2010
Reputation Points: 161
Solved Threads: 183
 

Yes, vibhadevit is right. addslashes only accepts string as an argument, so to make it safe, have a condition to check where the string you supplied to addslashes funtion is not null or something that is not a string.

reyborn
Junior Poster in Training
58 posts since Jan 2006
Reputation Points: 11
Solved Threads: 9
 

post your html code too

Karthik_pranas
Posting Pro
564 posts since Feb 2011
Reputation Points: 96
Solved Threads: 97
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: