Hi,
I'm doing a page with the info of the user. For exemple i log in if i want to change my information i click on this page.
But something is wrong:

<?PHP

include 'topo.php';

include ('db_connect.php');

$sql="SELECT username, password, nome_aluno, data_nascimento, morada_aluno, cp_aluno, telemovel_aluno,email_aluno,nome_ee,morada_ee,cp_ee,telemovel_ee,email_ee  FROM alunos WHERE username='". $_SESSION['username'] . "'";
$resultado = mysql_query($sql, $connect) or die(mysql_error());
$dados = mysql_fetch_array($resultado);

if (isset($_POST['confirm'])) 
{	
	//Declara um Array para armazenar a mensagem de erro
	$error = array();
    
	if (($_POST['conf_pass']) != ($_POST['pass'])) 
	{
        $error[] = 'As senhas não correspondem';
    }
	
	
	if (empty($_POST['email_aluno'])) 
	{
        $error[] = "Preencha o campo 'Email' (Aluno)";
    } 
	else 
	{
        if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['email'])) 
		{
           //regular expression for email validation
            $email = $_POST['email_aluno'];
        } 
		else 
		{
			$error[] = 'O endereço de email é inválido (Aluno)';
        }
	}
	
	
	if (empty($_POST['email_ee'])) 
	{
        $error[] = "Preencha o campo 'Email' (Enc. Educação)";
    } 
	else 
	{
        if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['email_ee'])) 
		{
           //regular expression for email validation
            $email_ee = $_POST['email_ee'];
        } 
		else 
		{
			$error[] = 'O endereço de email é inválido (Aluno)';
        }
	}
	
	$username = $_POST['username'];
	$pass = $_POST['pass'];
	$conf_pass = $_POST ['conf_pass'];
	$nome = $_POST['nome'];
	$nome_ee = $_POST['nome_ee'];
	$tele_aluno = $_POST['tele_aluno'];
	$tele_ee = $_POST['tele_ee'];
	$data_nasc = $_POST['data_nascimento'];
	$morada_aluno = $_POST['morada_aluno'];
	$cp_aluno = $_POST['cp_aluno'];
	$morada_ee = $_POST['morada_ee'];
	$cp_ee = $_POST['cp_ee'];
	
	//send to Database if there's no error '
    if (empty($error)) // If everything's OK...
    { 
		// Make sure the email address is available:
        $query_verify_user = "SELECT * FROM alunos WHERE username ='".$username."'";
        $result_verify_user = mysql_query($query_verify_user, $connect);
		
		//if the Query Failed, similar to if($result_verify_email==false)
		if (!$result_verify_user) 
		{
			
            echo ' Database Error Occured ';
        }
		
		$query_update_user = "UPDATE alunos SET username ='" . $username . "',password= '" . $pass . /*"', telemovel_aluno = '" . tele_aluno.Text . "', email_aluno = '" . email_aluno.Text . "', nome_ee = '" . nome_ee.Text . "', morada_ee = '" . morada_ee.Text . "', cp_ee = '" . cp_ee.Text . "', telemovel_ee = '" . tele_ee.Text . "', email_ee = '" . email_ee.Text .*/ "'";	
		echo $query_update_user;
        $result_update_user = mysql_query($query_update_user, $connect);
            
		if (!$result_insert_user) 
		{
            echo 'Query Failed ';
        }

		//If the Insert Query was successfull.
        if (mysql_affected_rows($connect) == 1) 
		{ 
            // Finish the page:
            echo '<div class="success"> Thank you for registering! A confirmation email has been sent to Please click on the Activation Link to Activate your account </div>';
        } 
		else 
		{ 
			// If it did not run OK.
            echo '<div class="errormsgbox">You could not be registered due to a system error. We apologize for any inconvenience.</div>';
        }

    } 
	else 
	{ 
		// The email address is not available.
        echo '<div class="errormsgbox">That email address has already been registered.</div>';
    }
	
} 
else 
{
	//If the "error" array contains error msg , display them
    echo '<div class="errormsgbox"> <ol>';
    foreach ($error as $key => $values) 
	{
		echo '<li>'.$values.'</li>';
	}
	echo '</ol></div>';
}
mysql_close($connect);//Close the DB Connection
?>

    
<form action="profile.php" method="post" class="registration_form">
<table>
	<tr>
		<td align="right">
			<br/>
			<div class="field"><label>Username: </label>
		</td>
		
		<td>
			<input type="text" name = "username" size="40" value="<?PHP echo $dados[0]; ?>"/></div>
		</td>
	</tr>
	
	<tr>
		<td align="right">
			<br/>
			<div class="field"><label>Password: </label>
		</td>
		
		<td>
			<input type="password" size="25" name = "pass"/></div>
		</td>
	</tr>
	
	<tr>
		<td align="right">
			<br/>
			<div class="field"><label>Confirma Password: </label>
		</td>
		
		<td>
			<input type="password" size="25" name = "conf_pass"/></div>
		</td>
	</tr>
	
	<tr>
		<td align="right">
			 <br/>
			<div class="field"><label>Nome: </label>
		</td>
		
		<td>
			<input type="text" size="40" name = "nome_aluno" value="<?PHP echo $dados[2]; ?>"/></div>
		</td>
	</tr>
	
	<tr>
		<td align="right">
			<br/>
			<div class="field">Data de Nascimento: </label>
		</td>
		
		<td>
			<input type="text" size="40" name = "data_nascimento" value="<?PHP echo $dados[3]; ?>"/></div>
		</td>
	</tr>
	
	<tr>
		<td align="right">
			<br/>
			<div class="field"><label>Morada: </label>
		</td>
		
		<td>
			<input type="text" size="40" name = "morada_aluno" value="<?PHP echo $dados[4]; ?>"/></div>
		</td>
	</tr>
	
	<tr>
		<td align="right">
			<br/>
			<div class="field"><label>Código-Postal: </label>
		</td>
		
		<td>
			<input type="text" size="40" name = "cp_aluno" value="<?PHP echo $dados[5]; ?>"/></div>
		</td>
	</tr>
	
	<tr>
		<td align="right">
			<br/>
			<div class="field"><label>Telemóvel: </label>
		</td>
		
		<td>
			<input type="text" size="40" name = "tele_aluno" value="<?PHP echo $dados[6]; ?>"/></div>
		</td>
	</tr>
	
	<tr>
		<td align="right">
			<br/>
			<div class="field"><label>E-Mail: </label>
		</td>
		
		<td>
			<input type="text" size="40" name = "email_aluno" value="<?PHP echo $dados[7]; ?>"/></div>
		</td>
	</tr>
	
	<tr>
		<td align="right">
			<br/>
			<div class="field"><label>Nome Enc. Educação: </label>
		</td>
		
		<td>
			<input type="text" size="40" name = "nome_ee" value="<?PHP echo $dados[8]; ?>"/></div>
		</td>
	</tr>
	
	<tr>
		<td align="right">
			<br/>
			<div class="field"><label>Morada Enc. Educação: </label>
		</td>
		
		<td>
			<input type="text" size="40" name = "morada_ee" value="<?PHP echo $dados[9]; ?>"/></div>
		</td>
	</tr>
	
	<tr>
		<td align="right">
			<br/>
			<div class="field"><label>Código-Postal Enc. Educação: </label>
		</td>
		
		<td>
			<input type="text" size="40" name = "cp_ee" value="<?PHP echo $dados[10]; ?>"/></div>
		</td>
	</tr>
	
	<tr>
		<td align="right">
			<br/>
			<div class="field"><label>Telemóvel Enc. Educação: </label>
		</td>
		
		<td>
			<input type="text" size="40" name = "tele_ee" value="<?PHP echo $dados[11]; ?>"/></div>
		</td>
	</tr>
	
	<tr>
		<td align="right">
			<br/>
			<div class="field"><label>E-Mail Enc. Educação: </label>
		</td>
		
		<td>
			<input type="text" size="40" name = "email_ee" value="<?PHP echo $dados[12]; ?>"/></div>
		</td>
	</tr>
</table>
</form>
	
<button type="button" name="confirm">Confirmar!</button> 
<?PHP	
include 'rodape.php';
?>

It gives me error in the foreach:

~foreach ($error as $key => $values)

What error ?

What error ?

Notice: Undefined variable: error in C:\wamp\www\site\profile.php on line 117

Warning: Invalid argument supplied for foreach() in C:\wamp\www\site\profile.php on line 117

Move $error = array(); from line 14 to line 10.

Move $error = array(); from line 14 to line 10.

Is almost there, it appears de box with the image error, but no message and it doesn't appears the messagem saying that it was updated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.