PHP: Error Database not selected

0

Excuse me, I have this little problem that I could not solve, I have a web system which I want to update at a certain moment through mysql_query, but it tells me that I do not have the selected bd

This is the code to connect to the database and if you realize I have the selection of my database.

     $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "proyecto_terror";

    $conn = mysqli_connect($servername, $username, $password, $dbname);
    mysql_select_db("proyecto_terror");

Y Aquí tengo el resto del código que es donde hago mi select y mi update para que se actualice en la fila que yo deseo

$nick2 = $_GET["nickP"];
$sql = "SELECT * FROM usuario WHERE nick = '".$nick2."'";
$result = mysqli_query($conn, $sql) or die(mysqli_error($conn));
$datos = array();
if (mysqli_num_rows($result) > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
        $datos[] = $row;
$passA=$_POST["passA"];
$passR=$_POST["passR"]; 



if ($row["password"]==$passA) {
mysql_query("UPDATE usuario SET password = '$passR' WHERE id_usuario = '$row[id_usuario]'");
echo mysql_error();
}else {
    echo "no coinciden";
}

    }

And this is what I see on the screen when I click on update

Update

I solved this problem and it was mainly due to the fact that I was using two different ways of handling the information, in this case I used mysqli, for the connection and mysql for the update, I simply standardized on one, preferably using mysqli, for security .

    
asked by David 14.08.2016 в 22:16
source

1 answer

1

You have:

$conn = mysqli_connect($servername, $username, $password, $dbname);
mysql_select_db("proyecto_terror");

If the variable $ conn is the connection using mysqli you should use it in the select_db mysqli in the same way, to use the select_db in mysqli you can do it in the following way.

$conn = mysqli_connect($servername, $username, $password, $dbname);
$conn->select_db($dbname);

With that already the problem should be solved ...

    
answered by 15.08.2016 / 22:08
source