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:


<?php
parse_str ($_SERVER['QUERY_STRING']);
//Tenta estabelecer uma ligação ao servidor MySQL
@mysql_connect("localhost","root","")  
    or die("Não foi estabelecida uma ligação ao servidor MySQL!");
//Tenta celeccionar a base de dados 12in
@mysql_select_db("12in")
    or die("Não foi possivel seleccionar uma base de dados");
// declaração de variáveis, query á base de dados, resultado da query atribuidos ás variáveis $mail $passwd

if (isset ($_POST['email'])) $email = $_POST['email'];
{
    $email = $_POST['email'];
    $query = "SELECT mail FROM utilizador WHERE mail='$email'";
    $result = mysql_query($query);
    $mail= @MYSQL_RESULT($result,0,"email");
}
if (isset ($_POST['password'])) $password = $_POST['password'];
{
    $password = $_POST['password'];
    $query = "SELECT password FROM utilizador WHERE password='$password'";
    $result = mysql_query($query);
    $passwd = @MYSQL_RESULT($result,0,"password");
}
?>

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?

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;

?>

They must match

I'm not exactly sure. However, there is a way to get the query to say if there is an error with that.

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

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.

This article has been dead for over six months. Start a new discussion instead.