Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

288
Views
Passing date variables as a parameter to a function in PHP?

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);
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!