-1

I am trying to get a mysql select to work but it doesn't give any results back. I'd like to get 1 result back from the database by using a form / dropdown.

The searchstring needs to check if those 3 selects exists in the database and echo them in a table.

Here is my code.

<?php

$year=$_POST['year'];
$month=$_POST['month'];
$day=$_POST['day'];
$colid=$_POST['colid'];

{
echo "
<table><tr><td><b>Titel</b></td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><b>Bestandsnaam</b></td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><b>Categorie</b></td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><b>Categorie</b></td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><b>Bekijk post op</b></td>
";
}

include_once"include/db/mysqldb.php";
$query=mysql_query("SELECT * FROM 'urenoverzicht' WHERE colid='$colid' AND year='$year' AND month='$month' AND day='$day'");

while($data = mysql_fetch_array($query))

  $id = $data['id'];
  $year = $data['year'];
  $month = $data['month'];
  $day = $data['day'];
  $hours = $data['hours'];

{
echo "
<tr><td>".$year."</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>".$month."</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>".$day."</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>".$hours."</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><a href='change.php?id=".$id."'>Bewerk</a></td><p>
";
echo "</tabel>";

}
?>

I think it has to do with my query but i can't seem to find it, please help if you can direct me on the right path.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    remove single quotes around table name. **Stop** using deprecated `mysql_*`API. Use `mysqli_` or `PDO` with prepared statements. – Jens Mar 07 '16 at 19:41
  • Check for errors after executing an SQL statement. – Jens Mar 07 '16 at 19:41
  • As others have said, remove the quotes around your table name (or change them to ``` if you really want it "quoted" in some way. One way to test your query would be to output the query that's being generated (put it in a variable before passing it to the query function), then run the query directly in MySQL (CLI, SQL app, phpMyAdmin, etc) and see what you get. – Davis Mar 07 '16 at 19:53

1 Answers1

0

Yes, you have to remove the quotes around your table name and check if the column year is not of numeric type, if it is, you have to remove the quotes around the variable too.

hectorlr22
  • 123
  • 1
  • 9