User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 425,934 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,626 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 819 | Replies: 2
Reply
Join Date: Mar 2007
Posts: 3
Reputation: Manawyddan is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Manawyddan Manawyddan is offline Offline
Newbie Poster

Undifined Index in PHP code

  #1  
May 1st, 2007
Hi everyone.
i'm having the following problem with the PHP code that i'm writing:

Notice: Undefined index: email in c:\program files\easyphp1-8\www\gestao_perfil.php on line 15

Notice: Undefined index: password in c:\program files\easyphp1-8\www\gestao_perfil.php on line 22


Here is the code:


  1. <?php
  2. parse_str ($_SERVER['QUERY_STRING']);
  3. //Tenta estabelecer uma ligação ao servidor MySQL
  4. @mysql_connect("localhost","root","")
  5. or die("Não foi estabelecida uma ligação ao servidor MySQL!");
  6. //Tenta celeccionar a base de dados 12in
  7. @mysql_select_db("12in")
  8. or die("Não foi possivel seleccionar uma base de dados");
  9. // declaração de variáveis, query á base de dados, resultado da query atribuidos ás variáveis $mail $passwd
  10.  
  11. if (isset ($_POST['email'])) $email = $_POST['email'];
  12. {
  13. $email = $_POST['email'];
  14. $query = "SELECT mail FROM utilizador WHERE mail='$email'";
  15. $result = mysql_query($query);
  16. $mail= @MYSQL_RESULT($result,0,"email");
  17. }
  18. if (isset ($_POST['password'])) $password = $_POST['password'];
  19. {
  20. $password = $_POST['password'];
  21. $query = "SELECT password FROM utilizador WHERE password='$password'";
  22. $result = mysql_query($query);
  23. $passwd = @MYSQL_RESULT($result,0,"password");
  24. }
  25. ?>

The idea is to fetch values from a database and in the end update the database with new ones(i know that the last part isn't finnish yet). Why am i getting these messages on my web browser?
Can someone help me to find waht's wrong with the code?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2006
Location: Canada
Posts: 55
Reputation: GliderPilot is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
GliderPilot's Avatar
GliderPilot GliderPilot is offline Offline
Junior Poster in Training

Re: Undifined Index in PHP code

  #2  
May 1st, 2007
Take a look at the form that is getting submitted.. My guesse is that you are using the GET method rather than the POST method. The error indicates you are trying to access an array index that does not exsist.

Two ways to fix this would be change your $_POST to $_GET or goto the form and set method equal to post. (<form action="me.html" method="POST">)

If not check the names of your form fields. The must match the names of the index you are using in the array.

I.E.

<input type="text" name="email">

<?php

$_POST['email'];

?>

They must match
Last edited by GliderPilot : May 1st, 2007 at 10:56 pm. Reason: Spelling
Reply With Quote  
Join Date: Feb 2007
Location: Palmerston North, New Zealand
Posts: 16
Reputation: WhiteLeo is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
WhiteLeo's Avatar
WhiteLeo WhiteLeo is offline Offline
Newbie Poster

Re: Undifined Index in PHP code

  #3  
May 1st, 2007
I'm not exactly sure. However, there is a way to get the query to say if there is an error with that.

[PHP]if(!$result){die(mysql_query());} // This will halt the script and display the sql error if the query failed to run[/PHP]

You should be able to then see if you have some sort of error with your query, or if it is because of something else.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 9:17 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC