Problem in php script

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
indianlibra
Forum Newbie
Posts: 4
Joined: Tue Mar 27, 2007 1:40 pm

Problem in php script

Post by indianlibra »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


In the below script you see a string length counter 

This script is working fine but i have a problem 

When first time i open this page in my browser it show an error in line 2 
(explained in image 2)

But when u enter the test string the error removed

I can't remove the 'test' variable 
b'coz i have to work with it

Can anybody help me to to remove this erro line in the browser

Code: Select all

<?php
 	$var = $_GET["test"];
	$len = strlen($var);
	
	if($len > 0)
	{
		echo $len;
	}
	else
	{
		echo "error: no input";
	}
?>
<form action="var_test.php" method="GET">
	<input type="text" name="test" >
	<input type="submit" value="Click Here">
Image 1
http://img76.imageshack.us/img76/4466/untitledkc2.gif

Image 2
http://img67.imageshack.us/img67/3272/untitled2ab1.gif

Image 3
http://img67.imageshack.us/img67/5409/untitled3xb8.gif


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

You need to check to see if the index is set so that you don't get that notice.

Code: Select all

$var = (isset($_GET["test"])) ? $_GET["test"] : '' ;
indianlibra
Forum Newbie
Posts: 4
Joined: Tue Mar 27, 2007 1:40 pm

Post by indianlibra »

thanks

'isset' in 'if' condition worked

thanks
Post Reply