Hello I'm new to php and mySQL. Basically I have a table of users and I want to echo the id, name and surname of the users if their "valid" integer is equal to 1, here is my attempt;
<?php
$servername = "aaa";
$username = "aaa";
$password = "aaa";
$dbname = "aaa";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT ID, Name, Surname, Valid FROM myTable";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
if($row["Valid"] = 1) {echo "id: " . $row["ID"]. " - Name: " . $row["Name"]. " " . $row["Surname"]. "<br>";
}
}
} else {
echo "0 results";
}
$conn->close();
?>
Using this code gives me a list of all the users, even though their valid integers are zero.
Thanks,