Codice PHP:
<?php
//Prelevo l' azione
require_once(dirname(__FILE__) . '/../inc.php');
require_once(dirname(__FILE__) . '/../member2.php');
$action = @$_GET['action'];
//Azione di default
if(strlen($action) == 0){
//utenti per pagina
$utenti_per_page = @$_GET['xpage'];
if(strlen($utenti_per_page) == 0){
$utenti_per_page = 1;
}
//Pagina di inizio
if(!IsSet($_GET['start'])){
$start = 0;
}else{
$start = $_GET['start'];
}
//Costruziona automatica della query per visualizzare gli utenti
$strSQL = "SELECT * FROM utenti";
//Qui controllo quanti sono i records presenti nella tabella per effettuare la paginazione !
$result = mysql_query($strSQL);
$tot_rec = mysql_num_rows($result);
//Numero pagine
$num_page = ceil($tot_rec/$utenti_per_page);
$current_page = ceil(($start/$utenti_per_page) + 1);
//Libero la memoria
mysql_free_result($result);
//Fine questione paginazione :-)
$strSQL .= " ORDER BY id DESC LIMIT $start, $utenti_per_page";
//Eseguo la query visualizzo i risultati
$result = mysql_query($strSQL);
//Link per inserimento articolo
echo "<a href=\"utenti.php?action=aggiungi\">Aggiungi Articolo</a>
";
//Visualizzo tutte le ultime News
while($row = mysql_fetch_array($result))
{
//Prelevo i dati dall' array
$intUtentiID = $row['id'];
$strUser = $row['user'];
$UserPubblicazione = $row['user_register'];
echo "[*]<a href=\"utenti.php?action=aggiungi&id=$intUtentiID\" title=\"Modifica User\">$strUser</a>\n";
}
//Libero la memoria
mysql_free_result($result);
//Paginazione
//Visualizzo i numeri di pagina
if($num_page > 1)
{
echo "<p align=\"center\">Altre pagine:";
//Ciclo FOR per elencare i numeri pagina
for($page = 1; $page <= $num_page; $page++){
if($page == $current_page){
echo "[b]$page[/b]";
}else{
echo "<a href=\"utenti.php?start=".($page - 1) * $utenti_per_page."\">$page</a>";
}
}
}
}
//Form aggiunta/modifica Articolo
if($action == "aggiungi"){
$intUtentiID = @$_GET['id'];
//Controllo se prelevare informazioni
//relativo utente da aggiornare...
if(strlen($intUtentiID) != 0){
//Query SQL
$strSQL = "SELECT * FROM utenti"
. " WHERE id = $intUtentiID";
//Eseguo la query e recupero i dati
$result = mysql_query($strSQL);
$row = mysql_fetch_array($result);
//recupero dati...
$intUtentiID = $row['id'];
$strEmail = $row['mail'];
$strName = $row['name'];
$strFirstname = $row['firstname'];
$intSex = $row['sex'];
$strbirthDay = $row['birthDay'];
$strbirthMonth = $row['birthMonth'];
$strbirthYear = $row['birthYear'];
$strbirth = $row['birth'];
$strdir = $row['dir'];
$strip = $row['ip'];
$struser_level = $row["user_level"];
$struser_title = $row["user_title"];
$struser_register = $row["user_register"];
$stractivationHash = $row["activationHash"];
$stractive = $row["active"];
//Libero la memoria
mysql_free_result($result);
}
?>
<h1>Aggiungi/Modifica Utenti</h1>
<form method="post" action="utenti.php?action=aggiungi_2">
<input type="hidden" name="intUtentiID" value="<?php echo @$intUtentiID;?>">
Nome<input name="name" type="text" id="name" value="<?php if(isset($_POST['name'])){echo $_POST['name'];}else { echo $strName; }?>" />
Cognome<input name="firstname" type="text" id="firstname" value="<?php if(isset($_POST['firstname'])){echo $_POST['firstname'];} else { echo $strFirstname; }?>" />
<select name="sex">
<option selected="selected" value="">SELEZIONA</option>
<option value="0" <?php if($row["sex"]=="0") echo 'selected'?>>Maschio</option>
<option value="1" <?php if($row["sex"]=="1") echo 'selected'?>>Femmina</option>
</select>
Giorno<input name="birthDay" type="text" id="birthDay" value="<?php if(isset($_POST['birthDay'])){echo $_POST['birthDay'];} else { echo $strbirthDay; }?>" />
Mese<input name="birthMonth" type="text" id="birthMonth" value="<?php if(isset($_POST['birthMonth'])){echo $_POST['birthMonth'];} else { echo $strbirthMonth; }?>" />
Giorno<input name="birthYear" type="text" id="birthYear" value="<?php if(isset($_POST['birthYear'])){echo $_POST['birthYear'];} else { echo $strbirthYear; }?>" />
completo data di nascita: <input name="birth" type="text" id="birth" value="<?php if(isset($_POST['birth'])){echo $_POST['birth'];} else { echo $strbirth; }?>" />
Dir<input name="dir" type="text" id="dir" value="<?php if(isset($_POST['dir'])){echo $_POST['dir'];} else { echo $strdir; }?>" />
ip<input name="ip" type="text" id="ip" value="<?php if(isset($_POST['ip'])){echo $_POST['ip'];} else { echo $strip; }?>" />
user_level<input name="user_level" type="text" id="user_level" value="<?php if(isset($_POST['user_level'])){echo $_POST['user_level'];} else { echo $struser_level; }?>" />
user_title<input name="user_title" type="user_title" id="user_title" value="<?php if(isset($_POST['user_title'])){echo $_POST['user_title'];} else { echo $struser_title; }?>" />
user_register<input name="user_register" type="text" id="user_register" value="<?php if(isset($_POST['user_register'])){echo $_POST['user_register'];} else { echo $struser_register; }?>" />
activationHash<input name="activationHash" type="text" id="activationHash" value="<?php if(isset($_POST['activationHash'])){echo $_POST['activationHash'];} else { echo $stractivationHash; }?>" />
active<input name="active" type="text" id="active" value="<?php if(isset($_POST['active'])){echo $_POST['active'];} else { echo $stractive; }?>" />
<input type="submit" value="Aggiungi Utente"><input type="reset" value="Annulla Modifiche">
</form>
<?php
}
if($action == "aggiungi_2"){
//Recupero tutti dati
// Dati Inviati dal modulo
$user = (isset($_POST['user'])) ? trim($_POST['user']) : ''; // Metto nella variabile 'user' il dato inviato dal modulo, se non viene inviato dò di default ''
$pass = (isset($_POST['pass'])) ? trim($_POST['pass']) : ''; // Metto nella variabile 'pass' il dato inviato dal modulo, se non viene inviato dò di default ''
$mail = (isset($_POST['mail'])) ? trim($_POST['mail']) : ''; // Metto nella variabile 'mail' il dato inviato dal modulo, se non viene inviato dò di default ''
$birthFull = "".$_POST["birthDay"]."/".$_POST["birthMonth"]."/".$_POST["birthYear"]."";
$birthDay = (isset($_POST["birthDay"])) ? trim($_POST["birthDay"]): '';
$birthMonth = (isset($_POST["birthMonth"])) ? trim($_POST["birthMonth"]): '';
$birthYear = (isset($_POST["birthYear"])) ? trim($_POST["birthYear"]): '';
$name = (isset($_POST["name"])) ? trim ($_POST["name"]): '';
$sex = (isset($_POST["sex"])) ? trim ($_POST["sex"]): '';
$firstname = (isset($_POST["firstname"])) ? trim($_POST["firstname"]): '';
$register_user = (isset($_POST["user_register"])) ? trim($_POST["register_user"]): '';
// Filtro i dati inviati se i magic_quotes del server sono disabilitati per motivi di sicurezza
if (!get_magic_quotes_gpc()) {
$user = addslashes($user);
$pass = addslashes($pass);
$mail = addslashes($mail);
$sex = addslashes($sex);
$birthFull = addslashes($birthFull);
$birthDay = addslashes($birthDay);
$birthMonth = addslashes($birthMonth);
$birthYear = addslashes($birthYear);
$name = addslashes($name);
$firstname = addslashes($firstname);
}
$user_register = date("d-m-Y");
if(strlen($intUtentiID) == 0){ //Aggiungo l'utente
// Query per l'inserimento dell'utente nel database
$strSQL = "INSERT INTO utenti (user,";
$strSQL.="pass,";
$strSQL.="mail,";
$strSQL.="name,";
$strSQL.="firstname,";
$strSQL.="sex,";
$strSQL.="birthDay,";
$strSQL.="birthMonth,";
$strSQL.="birthYear,";
$strSQL.="birth,";
$strSQL.="dir,";
$strSQL.="ip,";
$strSQL.="user_level,";
$strSQL.="user_title,";
$strSQL.="user_register,";
$strSQL.="activationHash,";
$strSQL.="active)";
$strSQL.= "VALUES('".$user."',";
$strSQL.="'".$pass."',";
$strSQL.="'".$mail."',";
$strSQL.="'".$name."',";
$strSQL.="'".$firstname."',";
$strSQL.="".$sex.",";
$strSQL.="'".$birthDay."',";
$strSQL.="'".$birthMonth."',";
$strSQL.="'".$birthYear."',";
$strSQL.="'".$birthFull."',";
$strSQL.="'".$user_hash."',";
$strSQL.="'".$_SERVER["REMOTE_ADDR"]."',";
$strSQL.="'".$user_level."',";
$strSQL.="'".$user_title."',";
$strSQL.="'".$user_register."',";
$strSQL.="'".$activationHash."',";
$strSQL.="'".$active."')";
}else{ //Modifico l'utente
$strSQL = "UPDATE utenti SET"
. " name = ".$name.","
. " firstname = ".$firstname.", "
. " sex = '".$sex."', "
. " birthDay = '".$birthDay."', "
. " birthMonth = '".$birthMonth."', "
. " birthYear = '".$birthYear."', "
. " birth = '".$birth."', "
. " user_level = '".$user_level."', "
. " user_title = '".$user_title."', "
. " user_title = '".$register_user."', "
. " activationHash = '".$activationHash."', "
. " active = '".$active."'"
. " WHERE id = ".$_GET["id"]."";
}
//Eseguo la query SQL
if(mysql_query($strSQL)){
echo "Uente aggiunto/modificato con successo !
";
echo "<a href=\"utenti.php\">Torna alla gestione articoli</a>";
}else{
echo "Errori riscontrati durante l'inserimento
";
echo "Errore: ".mysql_error();
}
}
?>
Vi ringrazio molto e spero che mi riuscite a capire il motivo.