Hi,
i trying to do a registration form (easiest thing ever) but i'm having trouble doing the validation :S
<?php
include 'db_connect.php';
?>
<html>
<head>
<title>Adminstração</title>
</head>
<body style="color=#FFFFFF" bgcolor="#666666">
<table width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<form method="post" action="">
<td align="center" valign="middle">
<table width="300px" cellpadding="0" cellspacing="3" bgcolor="#FFFFFF" style=" border: 1px solid #000000;">
<tr>
<td style=" border-style:none;">
<br>
</td>
</tr>
<tr>
<td align="right" style="font-size: 13;font-family: Arial, Helvetica, sans-serif;font-weight: bold;border-style:none;">
Utlizador:
</td>
<td style=" border-style:none;">
<input name="user" type="text">
</td>
</tr>
<tr>
<td align="right" style="font-size: 13;font-family: Arial, Helvetica, sans-serif;font-weight: bold;border-style:none;">
Password:
</td>
<td style=" border-style:none;">
<input name="password" type="password">
</td>
</tr>
<tr>
<td colspan="2" align="center" style=" border-style:none;">
<input type="submit" name="registar" value="Registar">
</td>
</tr>
<tr>
<td style=" border-style:none;">
<br>
</td>
</tr>
</table>
<span class="style1" style="font-size: 13;font-family: Arial, Helvetica, sans-serif;font-weight: bold;color: red;"> </span>
</td>
</form>
</tr>
</table>
</body>
</html>
<?PHP
if(isset($_POST['registar']))
{
$username = $_POST['user'];
$password = $_POST['password'];
if (empty($username) OR empty($password))
{
echo "<script>alert('Todos os campos são obrigatórios.')
location.href = 'add_user.php';</script>";
}
if ($username!="" && $password!="")
{
$sel_user="SELECT * FROM utilizadores";
$user=mysql_query($sel_user, $connect);
$row_user=mysql_fetch_assoc($user);
if ($username=$row_user['username'])
{
"<script>alert('O nome do utilizador ja existe.')</script>";
}
else
{
$sql="INSERT INTO utilizadores (username, password) VALUES ('".$username."','".sha1($password)."')";
$result = mysql_query($sql);
if(!$result)
{
echo "<script>alert('Erro a adicionar utilizador.')</script>";
}
else
{
echo "<script>alert('Utilizador adicionado com sucesso.');
location.href = 'admin.php';</script>";
}
}
mysql_close($connect);
}
}
?>
Please help me...