-2

I need to connect my sql with php and get some data in a variable, this is my code:

<?php 
$servername = "localhost";
$username = "imsdybug_pappagallo";
$password = "Vasivafa";

// Create connection
$conn = mysqli_connect($servername, $username, $password,"imsdybug_admin");

$result = mysqli_query($conn,"SELECT * FROM profilo_pappagallo;");
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){


 $pappagallo = $row['sesso'];
 echo $pappagallo;
 }
 ?>

1 Answers1

1

You're using the mysqli in the wrong way. It looks like you confound with mysql which is deprecated, here is the proper way :

<?php 
$servername = "localhost";
$username = "imsdybug_pappagallo";
$password = "Vasivafa";

// Create connection
$conn = new mysqli($servername, $username, $password, "imsdybug_admin");

$result = $conn->query("SELECT * FROM profilo_pappagallo;");

while($row = $result->fetch_assoc()) {
    $pappagallo = $row['sesso'];
    echo $pappagallo;
}
?>
executable
  • 2,788
  • 3
  • 16
  • 39