plz help with this sql query!

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
adbinc
Forum Newbie
Posts: 1
Joined: Mon Apr 14, 2008 6:47 am

plz help with this sql query!

Post 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:
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: plz help with this sql query!

Post 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";
 
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: plz help with this sql query!

Post by onion2k »

There's really nothing anyone can do to help without knowing what the error it's giving is.
Post Reply