Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 05-06-2005, 01:16 AM Undefined index?
Novice Talker

Posts: 5
Trades: 0
Well.. I am getting an Undefined index notice from the Log-In code below.
I have not written the code myself, so I guess the problem is that I am not sure what "op" is exactly.
Can someone please provide me with some input on what I need to do in order to get rid of the 'Undefined index' notice?

Quote:
Notice: Undefined index: op in C:\program files\apache\htdocs\login.php on line 6
PHP Code:
<?php
session_start
();
$conn mysql_connect("localhost","hat","pas");
$db mysql_select_db("database");

    if (
$_GET["op"] == "login")
        {
        
    
$username $_POST["username"];
    
$password $_POST["password"];
        if (!
$username || !$password)
            {
            die(
"You need to supply a username and password.");
            }
            
    
$result MYSQL_QUERY("SELECT * from users WHERE username='$username'and password=PASSWORD('$password')")
           or die (
"Name and password not found or not matched");

    
$worked mysql_fetch_array($result);

            
$id $worked['id'];
            
$_SESSION["valid_id"] = $id;
            
$_SESSION["valid_user"] = $username;
            
$_SESSION["valid_time"] = time();

            
// Redirect to member page
            
Header("Location: members.php");
        }
    else
        {
        echo 
"<form action=\"?op=login\" method=\"POST\">";
        echo 
"Username: <input name=\"username\" size=\"15\"><br />";
        echo 
"Password: <input type=\"password\" name=\"password\" size=\"8\"><br />";
        echo 
"<input type=\"submit\" value=\"Login\">";
        echo 
"</form>";
        }
?>
gartok is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-06-2005, 06:16 AM
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
You should do it like this:
PHP Code:
if (isset($_GET['op'])) {
   if (
$_GET['op'] == 'login') {
      
// ... blah-blah...
   
}

Or just add error_reporting (E_ALL ^ E_NOTICE) in the beginning of your script. Also you can read http://php.net/error_reporting for more clues on it.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 05-06-2005, 03:01 PM
Novice Talker

Posts: 5
Trades: 0
Thanks for the help!
gartok is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Undefined index?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.44107 seconds with 12 queries