Help' I dont know how to solve this

I keep getting this message;

Notice: Undefined index: interest in C:\xampp\New folder\htdocs\ShowPets.php on line 25.

Is this line of code ok? Thank you!

[php]$query = “SELECT * FROM pet WHERE petType=”{$_POST[‘interest’]}""; [/php]

Please use the php code tags when posting code :slight_smile:


On topic: you should make sure the array key exists.

[php]echo $_POST[‘interest’];[/php]

If a field with the name interest is not submitted then you will get an Undefined index notice.

[php]echo !empty($_POST[‘interest’]) ? $_POST[‘interest’] : ‘not set’;[/php]

Now if the array key is not set / not submitted you will get a default value of “not set” instead.


Please do not add variables directly into an sql query, it leaves you open to SQL injection attacks. Read more about using databases in PHP by following the PDO link in my signature.

Sponsor our Newsletter | Privacy Policy | Terms of Service