Grazie. comunque il codice è un po' lungo ed è questo
Codice PHP:
<?php require_once('Connections/mysql.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
// *** Redirect if username exists
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
$MM_dupKeyRedirect="regerror.html";
$loginUsername = $_POST['Username'];
$LoginRS__query = sprintf("SELECT Username FROM utenti WHERE Username=%s", GetSQLValueString($loginUsername, "text"));
mysql_select_db($database_mysql, $mysql);
$LoginRS=mysql_query($LoginRS__query, $mysql) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
//if there is a row in the database, the username was found - can not add the requested username
if($loginFoundUser){
$MM_qsChar = "?";
//append the username to the redirect page
if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
$MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
header ("Location: $MM_dupKeyRedirect");
exit;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO utenti (Username, Password, Nome, Cognome, Eta) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['Username'], "text"),
GetSQLValueString($_POST['Password'], "text"),
GetSQLValueString($_POST['Nome'], "text"),
GetSQLValueString($_POST['Cognome'], "text"),
GetSQLValueString($_POST['Eta'], "int"));
mysql_select_db($database_mysql, $mysql);
$Result1 = mysql_query($insertSQL, $mysql) or die(mysql_error());
$insertGoTo = "regsuccess.html";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_mysql, $mysql);
$query_rs = "SELECT * FROM utenti";
$rs = mysql_query($query_rs, $mysql) or die(mysql_error());
$row_rs = mysql_fetch_assoc($rs);
$totalRows_rs = mysql_num_rows($rs);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0014)about:internet -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Registrati</title>
<style type="text/css">
<!--
.Stile1 {font-family: "Comic Sans MS"}
-->
</style>
</head>
<body>
<form action="<?php echo $editFormAction; ?>" method="POST" name="form1" id="form1">
<p class="Stile1">Inserisci i tuoi dati e l' username e la password che vuoi per registrarti</p>
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right"><span class="Stile1">Username</span>:</td>
<td><input type="text" name="Username" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><span class="Stile1">Password</span>:</td>
<td><input type="text" name="Password" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><span class="Stile1">Nome</span>:</td>
<td><input type="text" name="Nome" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><span class="Stile1">Cognome</span>:</td>
<td><input type="text" name="Cognome" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><span class="Stile1">Eta</span>:</td>
<td><input type="text" name="Eta" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Registrati" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p> </p>
<p> </p>
</body>
</html>
<?php
mysql_free_result($rs);
?>