troubleshooting Question

PHP Variable

Avatar of Stevie Zakhour
Stevie Zakhour asked on
PHPDatabasesMySQL Server
15 Comments1 Solution49 ViewsLast Modified:

Hi All


Using PHP, I can pull data from a mysql database. The php code contains a query, I want to pass a date parameter though I'm getting an error. See below.


Notice: Undefined variable: search in /var/www/hello/test.php on line 32

The code is below


<html>
<head> <meta charset="UTF-8"> <title>Daily Lookup</title> </head> <body>  <div class="container">    <h2 align="center">Daily Lookup</h2><br />         <div class="form-group">                 <div class="input-group">                         <span class="input-group-addon">Date</span>                                 <input type="date" name="search" id="search" placeholder="Enter\Select Date" class="form-control" />                                         </div>                     </div>                     <br /> <?php error_reporting(-1); ini_set('display_errors', 'On'); try{     $pdo = new PDO("mysql:host=x.x.x.x;dbname=xx", "xx", "xx");     // Set the PDO error mode to exception     $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e){     die("ERROR: Could not connect. " . $e->getMessage()); } // Attempt select query execution try{ $result = $pdo->query("SELECT id, date, location, managerstoday1, managerstoday2, managerstomorrow1, managerstomorrow2, anything  FROM report where date = '".$search."'");


The error refers to the undefined value in the query, which is. If I replace $search in the query with a date and run the php code (file name is test.php) no error pops up and I can see the data. 

'".$search."'


Could you guide me on how to resolve this please? Thank you

ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 15 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 15 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros