Ho questo codice che funziona perfettamente per quando riguarda l'inserimento ma non mi controlla se vengono inseriti dati doppi nel database, nonostante abbia inserito la funzioni di controllo suggeritemi in qusto forum. Potrebbe qualcuno gentilmente dirmi dove stò sbagliando visto che sono alle primissime armi?
Ecco il 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']);
}
mysql_select_db($database_server, $server);
$controllo = "SELECT user FROM prova WHERE user = '".$_POST['user']."'";
$verifica = mysql_query($controllo);
if ($verifica) {
echo " query ok";
} else {
echo " query fallita - " . mysql_error();
}
$sessione = mysql_num_rows($verifica);
if ($sessione == 12) {
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("Devi Compilare tutti i campi");
}
}
?>![]()
![]()