Page 1 of 1

plz help with this sql query!

Posted: Mon Apr 14, 2008 6:54 am
by adbinc
i am workin wid my college project of airline reservation system.i made a form which insert details in my databse..but when iam retriving details ..it is giving error!

Code: Select all

 
<?php
include("conf.php");
$server = $_SESSION['server'];
$db_user= $_SESSION['db_user'];
$db_pass = $_SESSION['db_pass'];
$db_name = "adbinc_bookings";
$cxn = mysql_connect($server,$db_user,$db_pass,$db_name) 
            or die ("User name or password is wrong.");
 
$query = "SELECT * FROM $table ORDER BY rid ASC LIMIT 0,30";
 
$result = mysql_query($cxn,$query) or die ("Couldnt execute query.");
$num = mysql_num_rows($result);
 
echo "<b><center>Database Output</center></b><br><br>";
 
while ($row = mysql_fetch_assoc($result)){
 
  echo "<b> " . $row['fname'] . " " . $row['lname'] . " </b><br>" . $row['fno'] 
 
.
       "<br>" . $row['src'] . "<br>" . $row['dest'] . "" . $row['rid'] . 
 
"<hr><br>\n";
}
?> :crazy:

Re: plz help with this sql query!

Posted: Mon Apr 14, 2008 8:12 am
by aceconcepts
You are using a variable as the table name.

Either use a table name that exists or enclose your variable with single quotes:

Code: Select all

 
$table=tblName;
$query = "SELECT * FROM '$table' ORDER BY rid ASC LIMIT 0,30";
 

Re: plz help with this sql query!

Posted: Mon Apr 14, 2008 8:26 am
by onion2k
There's really nothing anyone can do to help without knowing what the error it's giving is.