Salve ragazzi ho questo problema:
Ho creato un form di iscrizione utenti ed ora vorrei effettuare un controllo affinchè uno stesso utente posse iscriversi una sola volta,
quindi un controllo sull'esistenza ne database dei dati, come posso fare
Salve ragazzi ho questo problema:
Ho creato un form di iscrizione utenti ed ora vorrei effettuare un controllo affinchè uno stesso utente posse iscriversi una sola volta,
quindi un controllo sull'esistenza ne database dei dati, come posso fare
hai due strade : o rendi unico i campi sul database in modo che possano contenere solo una volta lo stesso dato...oppure controlli prima di inserire i dati che nn ci sia già qualche utente con stessi dati ...es così :
$controllo = "SELECT * FROM utenti WHERE nome_utente = $_POST['dato_inserito dall'utente'] ";
$verifica = mysql_query ($controllo) or mysql_error();
$sessione = mysql_num_rows ($verifica);
if ($sessione == 1) {
echo " esiste già l'utente"
}else{
esegui la registrazione
![]()
Ho provato a fare come dici ma ho il seguente errore:
syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
Per meglio far capire il tutto posto il mio codice:
<?php require_once('Connections/server.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
$controllo = "SELECT * FROM prova WHERE user = $_POST['user'] ";
$verifica = mysql_query ($controllo) or mysql_error();
$sessione = mysql_num_rows ($verifica);
if ($sessione == 1) {
echo " esiste già l'utente"
}else{
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO prova (`user`, nome) VALUES (%s, %s)",
GetSQLValueString($_POST['user'], "text"),
GetSQLValueString($_POST['nome'], "text"));
mysql_select_db($database_server, $server);
$Result1 = mysql_query($insertSQL, $server) or die(mysql_error());
}
?>
echo " esiste già l'utente"; >> mancava il punto e virgola
}else{
e aggiungi alla fine un'altra } che mi sembra manchi![]()