problem uploading 3 values on mysql db
Posted: Wed Feb 24, 2010 10:34 am
Hi guys, i am entering now in the world of php, i am experimenting on coding only with arduino and c++..
now i am building my site and i have to create a database for users, i am starting to save only 3 values..
name surname and email.... this is my code:
the result after compiling correctly the 3 forms is a empty page with this link: data.php?sent=true
nothing saved on db....
Please can you help me?? In italy nobody can give me an advise..
now i am building my site and i have to create a database for users, i am starting to save only 3 values..
name surname and email.... this is my code:
Code: Select all
<?php
if(isset($_GET['sent'])) {
$rules = array(
'email' => array('req', 'email' => true),
'name' => array('req', 'minlength' => 3),
'surname' => array('req', 'minlenght' => 2),
);
$errors = array();
foreach($rules as $name => $rule) {
if((! isset($_POST[$name])) || empty($_POST[$name])) {
$errors[$name] = 'Obbligatorio';
continue;
}
if(isset($rule['email']))
if(preg_match('/^[a-z0-9][_\.a-z0-9-]+@([a-z0-9][0-9a-z-]+\.)+([a-z]{2,4})$/i', $_POST[$name]) == false) {
$errors[$name] = 'Email non valida';
continue;
}
if(isset($rule['minlength']))
if(strlen($_POST[$name]) < $rule['minlength']) {
$errors[$name] = 'Minimo ' . $rule['minlength'] . ' caratteri';
continue;
}
if(isset($rule['length']))
if(strlen($_POST[$name]) != $rule['length']) {
$errors[$name] = 'Inserisci ' . $rule['length'] . ' caratteri';
continue;
}
if(isset($rule['values']))
if(! in_array($_POST[$name], $rule['values'])) {
$errors[$name] = 'Obbligatorio';
continue;
}
}
if(count($errors) > 0)
$showform = true;
else {
$showform = false;
$dbConn = @mysqli_connect('ipserver', 'nomesql', 'pass', 'Sqlnomedb');
if(! $dbConn)
$error = 'Qualcosa non ha funzionato.<br />Per favore, riprova più tardi';
else {
$query = "INSERT INTO concorso (email, name, surname) VALUES('$_POST[email]' , '$_POST[name]' , '$_POST[surname]')";
mysqli_query($dbConn, $query);
}
}
}
else
$showform = true;
if($showform) {
?>
<form action="?sent=true" method="post">
<center><p style="color: white; font-size:15px; margin:7px 0px 5px 20px;"><b>Informazioni personali</b></p></center>
<label for="email"><p style="color: white; font-size:12px; margin:0px 0px 0px 10px;"><b>Indirizzo email</b><?= isset($errors['email']) ? ' <span class="error">' . $errors['email'] . '</span>' : ''; ?></label><br />
<input type="text" name="email" id="email" value="<?=$_POST['email'];?>" style="margin:0px 0px 7px 20px;" />
<label for="name"><p style="color: white; font-size:12px; margin:0px 0px 0px 10px;"><b>Nome</b><?= isset($errors['name']) ? ' <span class="error">' . $errors['name'] . '</span>' : ''; ?></label><br />
<input type="text" name="name" id="name" value="<?=$_POST['name'];?>" style=" margin:0px 0px 7px 20px;" />
<label for="surname"><p style="color: white; font-size:12px; margin:0px 0px 0px 10px;"><b>Cognome</b><?= isset($errors['surname']) ? ' <span class="error">' . $errors['surname'] . '</span>' : ''; ?></label><br />
<input type="text" name="surname" id="surname" value="<?=$_POST['surname'];?>" style=" margin:0px 0px 7px 20px;" /></center>
<!--<center><a href="domanda1.php"><p style="font-size:15px;"><b>Continua!</b></p></a></center>-->
<input type="image" src="img/inviabtn.png" />
<?
} elseif(isset($error)) { ?>
<center><?= $error; ?></center>
<?
} else { ?>
<br /><br /><br /><br /><h1><center>Grazie di aver partecipato!<br />Ti invieremo una mail se sarai selezionato tra i vincitori.<center></h1>
<?
} ?>nothing saved on db....
Please can you help me?? In italy nobody can give me an advise..