0

I am trying to insert a date variable into a function to execute a mysql statement using it and retrieve a value from my database. However, the MySQL statement is executed and the date I am passing is correct, however, I am not getting the values I want back. Instead, I am getting nothing back. Here is the code in question:

<?php

function conn(){
    $user = 'root';
    $pass = '';
    $db = 'proj';
    $connection = mysqli_connect( "localhost", $user,$pass,$db);
    if($connection){}
    else{ die("Connection failed. Reason: ".mysqli_connect_error());}
    return $connection;
}
function getRoom($dt){
    $connection = conn();
    $sql = "SELECT * FROM reservation WHERE Check_out = $dt";
    $result = $connection->query($sql);
    $row = mysqli_fetch_assoc($result);
    $rn = $row['Room_Num'];
    return $rn;
}
$date = '2017-03-25';

echo getRoom($date);
plank223
  • 29
  • 6
  • I found the answer to my question using the duplicate question that Fred -ii- linked. Thank you btw. All I needed to do is enclose the $dt variable in the SQL statement in single quotes. – plank223 Apr 29 '17 at 20:52
  • Watch out for [sql injection](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) –  Apr 29 '17 at 21:12

0 Answers0