Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Undefined index:

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Undefined index:

Postby funtoox » Mon Jul 22, 2013 7:01 am

Hi Everyone, I am beginner in PHP. So I would like to learn more from this forum. I am new to this forum and This is my first post.

I don't know this is the correct way to ask or not? :D

However, Here is my Code,
Code: Select all
<form name="form1" method="post">
    <input type="text" name="name">
   <input type="submit" value="login">
</form>
<?php
$name = strtolower($_POST['name']);
if ($name=="sandeep") {
   echo "Welcome ".ucfirst($name).".";
} else {   
   echo "Hello ".ucfirst($name).", You are not authorized.";
}
?>

and Here is the result,
Notice: Undefined index: name on line 6
Hello , You are not authorized.

The problem is the Undefined index: and the message printed by echo. As I don't want to print any message, if the user doesn't enter anything in the textbox, in other words I want this text to be printed only after the user insert the text in the textbox. I don't want this to appear at default!

Hope the members of this forum will help me.

Thanks in advance for your :help: ,

Regards,
funtoox
New php-forum User
New php-forum User
 
Posts: 1
Joined: Mon Jul 22, 2013 6:53 am

Re: Undefined index:

Postby johnj » Mon Jul 22, 2013 10:26 pm

johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Undefined index:

Postby rupali » Tue Jul 23, 2013 5:08 pm

Hi,

Use isset() at the first line of php code like this and assign the name to submit button :
<form name="form1" method="post">
<input type="text" name="name">
<input type="submit" value="login" name="submit">
</form>
<?php
if(isset($_POST['submit']))
{

$name = strtolower($_POST['name']);
if ($name=="sandeep") {
echo "Welcome ".ucfirst($name).".";
} else {
echo "Hello ".ucfirst($name).", You are not authorized.";
}
}
?>
rupali
New php-forum User
New php-forum User
 
Posts: 140
Joined: Thu Oct 13, 2011 10:32 pm
Location: Chandigarh, INDIA


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.