So this works:
$name=mysqli_real_escape_string($conn,$_POST['name']);
$password=mysqli_real_escape_string($conn,$_POST['password']);
$sql= "SELECT password FROM Accounts WHERE username='$name';";
$result= $conn->query($sql);
$row=mysqli_fetch_assoc($result);
but this doesn't:
$name=mysqli_real_escape_string($conn,$_POST['name']);
$password=mysqli_real_escape_string($conn,$_POST['password']);
//$sql= "SELECT password FROM Accounts WHERE username='$name';";
$stmt = $conn->prepare("SELECT password FROM Accounts WHERE username=?");
$stmt->bind_param("s",$name);
$stmt->execute();
$result= $stmt->get_result();
$row=mysqli_fetch_assoc($result);
$stmt->close();
Why would the first one work, but not the second one? I have PHP 7 installed on my server. I wanna make input secure to avoid SQL injection, but prepared statements aren't working for some reason
EDIT: so using bind_param() and fetch() fixed the problem for me. But I'm still curious why get_result() didn't work. Does get_result() provide just the value selected, whereas my old $result =query() returned the entire row?
My guess is maybe the two methods return different types of data/formats?