Reputation: 61
I am relatively new in php,i am facing a problem while i retrieving data from a table of my database...the name of the table is 'leave'.more importantly i have to say that i can easily retrieve data from another table of the same database.I am using a open source database and 'leave' table is created by me.is that the reason??Actually i don't find any reason for this problem.i am using mysql_fetch_row(),but i have an error as follow
Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\attendance_system\admin_leave.php on line 42
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'leave' at line 1
here is my code...please help me
code here
<?php
/*@session_start();
if (isset($_SESSION['username']) && $_SESSION['username']) {
} else {
header("Location: index.php");
}
$title = 'Leave Application';*/
include_once 'config.php';
include('header.php');
?>
<div class="grid_12">
<div class="contentpanel">
<h2 align="center">Leave Application</h2>
<?php
$sql = mysql_query('select * from leave');
?>
<table class="list" cellspacing="0" cellpadding="5" border="1">
<thead>
<tr>
<th> </th>
<th>Employee ID</th>
<th>Employee Name</th>
<th>User Name</th>
<th>Leave Days</th>
<th>Start Date</th>
<th>End Date</th>
<th>Reason</th>
</tr>
</thead>
<tbody>
<?php
while($w= mysql_fetch_row($sql) or die(mysql_error()))
{
echo
"<tr>
<td> </td>
<td>".$w[0]."</td>
<td>".$w[1]."</td>
<td>".$w[2]."</td>
<td>".$w[3]."</td>
<td>".$w[4]."</td>
<td>".$w[5]."</td>
<td>".$w[6]."</td>
</tr>";
}
?>
</tbody>
</table>
<br/>
<br/>
</div>
</div>
<?php include('footer.php'); ?>
Upvotes: 2
Views: 117
Reputation: 18569
Leave is a keyword in MySql
You need to put the table name in backticks.
Use this:
$sql = mysql_query('select * from `leave`');
Upvotes: 1