- Code: Select all
<?php
if (isset($azione)) //if the submit button
has been pressed it
calls the connection
and insert the user.
{
$host="localhost";
$user="***";
$pass="***";
if (!@mysql_connect($host,$user,$pass))
{
echo("<p>Unable to connect due to: ".mysql_error()."</p>");
exit();
}
if (!@mysql_select_db("test"))
{
echo("<p>Unable to open DB due to: ".mysql_error()."</p>");
exit();
}
/* now I select the user to see if there is
already an existing user with the same nick */
$sqlquery="SELECT * FROM utenti WHERE nick='$nick'";
$result=@mysql_query($sqlquery);
if (!$result)
{
echo("<p>Unable to exec query due to ".mysql_error()."</p>");
exit();
}
if (mysql_num_rows($result)!=0)
{
echo("<P>Exising user:</P>");
$utente=mysql_fetch_array($result);
?>
<table width="700">
<tr>
<td width="25%">
<?=$utente['nick']?>
</td>
<td width="25%">
<?=$utente['cognome']?>
</td>
<td width="25%">
<?=$utente['nome']?>
</td>
<td width="25%">
<?=$utente['email']?>
</td>
</tr>
</table>
<?
}
else //nick not found in the table
{
$sqlquery="INSERT INTO utenti (`ID`, `nick`, `PWD`, `nome`, `cognome`,
`email`) VALUES ('', $nick, $pwd, $nome, $cognome, $email)";
if (!@mysql_query($sqlquery))
{
echo("<P>Error inserting user: ".mysql_error()."</P>");
exit();
}
else
{
echo("<P>Utente registrato, grazie!</P>");
echo("Torna alla <a href=\"welcome.php\">home</a> per il login");
exit();
}
}
}
else //first time I call the page, so I present the register form.
{
?>
<form method="post" action="register.php">
Nick:<input type="text" name="nick" size="20"><br>
PWD:<input type="text" name="pwd" size="20"><br>
Nome:<input type="text" name="nome" size="20"><br>
Cognome:<input type="text" name="cognome" size="20"><br>
E-mail:<input type="text" name="email" size="20"><br>
<input type="submit" name="azione" value="GO">
</form>
<?
}
?>
All the code up here is inside the body tag. Problem is that the first IF is NEVER entered, as if the $azione variable is always =NULL, even after I submit the form.
Any help?
Thanks a lot,
Leo.


: