Hi everyone,
I can’t understand what happens… When I try my site in WAMP, I have the follow errors: Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO (…)
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in (…)
The same happened with the connect to mysql, but I solved using mysqli extension. But in this case is totally diferente. When I use the mysqli_query or mysqli_num_rows that are the alternatives presented I receive again other error, in PHP Manual says: "function.mysqli-query doesn't exist. Closest matches:"
Someone know solve this problem???
When I use MySQL
<?php
session_start();
if (isset($_SESSION["manager"])){
header("location:index.php");
exit();
}
?>
<?php
if(isset($_POST["username"])&&isset($_POST["password"])){
$manager=preg_replace('#[^A-Za-z0-9]#i','',$_POST["username"]);
$password=preg_replace('#[^A-Za-z0-9]#i','',$_POST["password"]);
$cnn= include "../lojascript/connect_mysql.php";
$sql=mysql_query($cnn, "SELECT id FROM admin WHERE username='$manager' AND password='$password' LIMIT 1");
$existCount=mysql_num_rows($sql);
if ($existCount==1){
while ($row = mysqli_fetch_array($sql)){
$id=$row["id"];
}
$_SESSION["id"]=$id;
$_SESSION["manager"]=$manager;
$_SESSION["password"]=$password;
header("location:index.php");
exit();
}else {
echo 'Informação incorrecta <a href="index.php"> Click here</a>';
exit();
}
}
?>
When I use MySQLi
<?php
session_start();
if (isset($_SESSION["manager"])){
header("location:index.php");
exit();
}
?>
<?php
if(isset($_POST["username"])&&isset($_POST["password"])){
$manager=preg_replace('#[^A-Za-z0-9]#i','',$_POST["username"]);
$password=preg_replace('#[^A-Za-z0-9]#i','',$_POST["password"]);
$cnn = include "../lojascript/connect_mysql.php";
$query= "SELECT id FROM admin WHERE username='$manager' AND password='$password' LIMIT 1";
$result= mysqli_query($cnn,$query) or die(mysqli_error());
$num_row = mysqli_num_rows($result);
if ($num_row==1)
{
while ($row = mysqli_fetch_array($result)){
$_SESSION["id"]=$row["id"];
}
$_SESSION["id"]=$id;
$_SESSION["manager"]=$manager;
$_SESSION["password"]=$password;
header("location:index.php");
exit();
}else {
echo 'Informação incorrecta <a href="index.php"> Click here</a>';
exit();
}
}
?>