Ciao a tutti ho un problema con il mio file regverify.php
Inanzitutto eseguendo una query insert into, non viene riconosciuta e quindi significa che non sono connesso.
Infatti:
Codice PHP:
include("functions_custom.php");include("register.php");include("config.php");
$link = mysql_connect('localhost', $db_user, $db_psw);if (!$link) { die('Not connected : ' . mysql_error());}
// make foo the current db$db_selected = mysql_select_db($db_name, $link);if (!$db_selected) { die ('Can\'t use '.$db_name.' : ' . mysql_error());}
$sql = "INSERT INTO `users`(`username`) VALUES (\'ciao\')"; /* Questa query non va.. */
Dal file config.php ottengo le informazioni necessarie per il mio script di connessione (ovviamente non vi mostro le credenziali)
Codice PHP:
$host = "localhost"; $db_user = "user"; $db_psw = "password"; $db_name = "my_database";
Poi ho un altro problema:
Dovrei controllare se l'username immesso dall'utente durante la registrazione è già esistente, stessa cosa farei con l'email, avvertendo con un alert personalizzato.
Ma non funziona, qualcosa sbaglio ed infatti in questo codice completo:
Codice PHP:
<?php ini_set("display_errors", 1); error_reporting(E_ALL); ?>
<?php
/*** * MyPCMS (My Powerful Content Management System) ** Version 0.0.3 beta standard** About team in > "http://mypcms.com/about/team"***/
include("functions_custom.php");include("register.php");include("config.php");
$link = mysql_connect('localhost', $db_user, $db_psw);if (!$link) { die('Not connected : ' . mysql_error());}
// make foo the current db$db_selected = mysql_select_db($db_name, $link);if (!$db_selected) { die ('Can\'t use '.$db_name.' : ' . mysql_error());}
$sql = "INSERT INTO `users`(`username`) VALUES (\'ciao\')";
$username = $_POST['username'];$password = $_POST['password'];$email = $_POST['email'];$action = $_POST['action'];
if(isset($username) && isset($password) && isset($email)) {
echo "<link href=\"css/custom_alert.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" /> <script src=\"//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js\"></script> <script src=\"js/custom_alert.js\"></script> <script type=text/javascript>_alert('LOL!','Sono isset!')</script>"; if(isset($action) && ($action=="Submit New Registration")) {
$sql = mysql_query("SELECT `username` FROM `users`");
while($u_namealreadyex = mysql_fetch_array($sql)) { if(in_array($username, explode(",", $u_namealreadyex))) {
echo "<link href=\"css/custom_alert.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" /> <script src=\"//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js\"></script> <script src=\"js/custom_alert.js\"></script> <script type=text/javascript>_alert('Error!','Username already exists, choose another, try again','register.php')</script>";
}
else if(! in_array($username, explode(",", $u_namealreadyex))) {
$salt = generateRandomImpossibleTosolveString("64"); $securepw = sha1(sha1($salt).md5($password)); $now = TIME_NOW; $query=mysql_query("INSERT INTO users (username, password, email) VALUES (".$username.", ".$securepw.", ".$email.")");
while($done=mysql_fetch_array($query)) {
$user = array( "username" => $username, "password" => $securepw, "email" => $email, "memregdate" => $now, "lastactive" => $now, "lastvisit" => $now
);
}
}
}
$sql=mysql_query("SELECT `email` FROM `users`");
while($mailalreadyex = mysql_fetch_array($sql)) {
if(in_array($email, explode(",", $mailalreadyex))) {
echo "<link href=\"css/custom_alert.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" /> <script src=\"//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js\"></script> <script src=\"js/custom_alert.js\"></script> <script type=text/javascript>_alert('Error!','Email already exists, choose another, try again','register.php')</script>";
}
else if(! in_array($email, explode(",", $mailalreadyex))) {
$salt = generateRandomImpossibleTosolveString("64"); $securepw = sha1(sha1($salt).md5($password)); $now = TIME_NOW; $query=mysql_query("INSERT INTO users (username, password, email) VALUES (".$username.", ".$securepw.", ".$email.")");
while($done=mysql_fetch_array($query)) {
$user = array( "username" => $username, "password" => $securepw, "email" => $email, "memregdate" => $now, "lastactive" => $now, "lastvisit" => $now
);
}
}
}
}
}
?>
Restituisce questi errori:
Codice PHP:
Warning: explode() expects parameter 2 to be string, array given in /membri/hydrerscript/regverify.php on line 55
Warning: in_array() expects parameter 2 to be array, null given in /membri/hydrerscript/regverify.php on line 55
Warning: explode() expects parameter 2 to be string, array given in /membri/hydrerscript/regverify.php on line 64
Warning: in_array() expects parameter 2 to be array, null given in /membri/hydrerscript/regverify.php on line 64
Warning: sha1() expects at most 2 parameters, 3 given in /membri/hydrerscript/functions_custom.php on line 19
Warning: substr() expects at least 2 parameters, 1 given in /membri/hydrerscript/functions_custom.php on line 19
Notice: Use of undefined constant TIME_NOW - assumed 'TIME_NOW' in /membri/hydrerscript/regverify.php on line 69
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /membri/hydrerscript/regverify.php on line 73
Warning: explode() expects parameter 2 to be string, array given in /membri/hydrerscript/regverify.php on line 100
Warning: in_array() expects parameter 2 to be array, null given in /membri/hydrerscript/regverify.php on line 100
Warning: explode() expects parameter 2 to be string, array given in /membri/hydrerscript/regverify.php on line 110
Warning: in_array() expects parameter 2 to be array, null given in /membri/hydrerscript/regverify.php on line 110
Warning: sha1() expects at most 2 parameters, 3 given in /membri/hydrerscript/functions_custom.php on line 19
Warning: substr() expects at least 2 parameters, 1 given in /membri/hydrerscript/functions_custom.php on line 19
Notice: Use of undefined constant TIME_NOW - assumed 'TIME_NOW' in /membri/hydrerscript/regverify.php on line 115
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /membri/hydrerscript/regverify.php on line 119
Come risolvere tutto?