Jump to content

Invalid query: Unknown column 'DCS' in 'field list'


Tom_LR

Recommended Posts

I have an html form that posts to a .php script. Form asks for an account number then onto .php script to find the account number and return the account information (name, address, balance, etc.) from that account. From the documentation I've read, the SELECT should work the way it's written but it's not. When I hit submit from the form page and it goes to the .php page here is the entire error: 

Invalid query: Unknown column 'DCS' in 'field list' Whole query: SELECT DCS#, CLIREF, GUAR, PAT, ADDR1, ADDR2, CITY, ST, ZIP, SS#, DOB, PHONE, DBAL, TBAL, PAID FROM crossroads10 WHERE CLIREF='ZQ02037/8558'

Here is my code

[code=php:0]


<?

$link=mysql_connect('host', 'databasel', 'password');
if (!$link) {
die('Could not connect: ' .mysql_error());
}

else
{
// Connected to the database
print("Successfully connected to the MySQL database server.<br>\n");
}


$cliacct=$_POST['clientnum'];

$query = "SELECT DCS#, CLIREF, GUAR, PAT, ADDR1, ADDR2, CITY, ST, ZIP, SS#, DOB, PHONE, DBAL,
TBAL, PAID FROM crossroads10 WHERE CLIREF='$cliacct'";

$result=mysql_query($query);

if (!$result) {
  $message  = 'Invalid query: ' . mysql_error() . "\n";
  $message .= 'Whole query: ' . $query;
  die($message);
}


while ($row = mysql_fetch_assoc($result)) {
  echo $row['GUAR'];
  echo $row['PAT'];
  echo $row['ADDR1'];
  echo $row['ADDR2'];
  echo $row['CITY'];
  echo $row['ST'];
  echo $row['ZIP'];
  echo $row['SS#'];
  echo $row['DOB'];
  echo $row['PHONE'];
  echo $row['DBAL'];
  echo $row['TBAL'];
  echo $row['PAID'];


}



?>
[/code]

I put a return after DBAL so you could see it all. Also, in the error it shows 'DCS' as the invalid column. DCS# is a column header, not DCS and I am asking for DCS#. It doesn't matter if I remove DCS# completely from the SELECT command, it then shows the next column to be invalid. Any help would be greatly, greatly appreciated.
Link to comment
Share on other sites

I changed the column headings to lowercase and removed the "#" signs. Now I get this error.

Invalid query: No Database Selected Whole query: SELECT dcs, cliref, guar, pat, addr1, addr2, city, st, zip, social, dob, phone, dbal, tbal, paid FROM crossroads10 WHERE cliref='ZQ02037/8558'
Link to comment
Share on other sites

"No database selected" is pretty well self-evident.  Your code as written merely connects to the SQL server then attempts to retrieve data from a table in an undefined database.  After your connection, select the database with the lines:

[code]$db_name = "your_database_name_goes_here"; // edit to suit
mysql_select_db($db_name) or die ("Can't open database!"); [/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.