Allora, io ho questi 2 files:
registration.php
Codice PHP:
<?php
//Start session
session_start();
//Include database connection details
require_once('config.php');
//Array to store validation errors
$errmsg_arr = array();
//Validation error flag
$errflag = false;
//Connect to mysql server
$link = mysql_connect($host, $username, $password);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db($db_name, $link);
if(!$db) {
die("Unable to select database");
}
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
//Sanitize the POST values
$fname = clean($_POST['fname']);
$lname = clean($_POST['lname']);
$login = clean($_POST['login']);
$password = clean($_POST['password']);
$cpassword = clean($_POST['cpassword']);
//Input Validations
if($fname == 'bill') {
$errmsg_arr[] = 'tu non ti chiami bill gates';
$errflag = true;
}
if($lname == 'gates') {
$errmsg_arr[] = 'sisi e io sono tua nonna XDDDD';
$errflag = true;
}
if($login == '') {
$errmsg_arr[] = 'Non hai inserito la tua login id';
$errflag = true;
}
if($password == '') {
$errmsg_arr[] = 'Non hai inserito la tua password';
$errflag = true;
}
if($cpassword == '') {
$errmsg_arr[] = 'Non hai la conferma password';
$errflag = true;
}
if( strcmp($password, $cpassword) != 0 ) {
$errmsg_arr[] = 'Le password non corrispondono';
$errflag = true;
}
//Check for duplicate login ID
if($login != '') {
$qry = "SELECT * FROM members WHERE login='$login'";
$result = mysql_query($qry);
if($result) {
if(mysql_num_rows($result) > 0) {
$errmsg_arr[] = 'Username giá esistente';
$errflag = true;
}
@mysql_free_result($result);
}
else {
die("Query failed");
}
}
//If there are input validations, redirect back to the registration form
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: register-form.php");
exit();
}
//Create INSERT query
$qry = "INSERT INTO members(firstname, lastname, login, passwd) VALUES('$fname','$lname','$login','".md5($_POST['password'])."')";
$result = @mysql_query($qry);
//Check whether the query was successful or not
if($result) {
echo "Registrazione avvenuta con successo";
exit();
}else {
die("Query failed");
}
?>
e config.php
Codice PHP:
<?php
$host="localhost"; // Host name
$username="browsergamemio"; // Mysql username
$password=""; // Mysql password
$db_name="my_browsergamemio"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
?>
Eppure se tento di registrarmi mi dà un "Query failed"! Dove sbaglio?