Tom_LR Posted November 9, 2006 Share Posted November 9, 2006 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. Quote Link to comment Share on other sites More sharing options...
Tom_LR Posted November 9, 2006 Author Share Posted November 9, 2006 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' Quote Link to comment Share on other sites More sharing options...
AndyB Posted November 10, 2006 Share Posted November 10, 2006 "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 suitmysql_select_db($db_name) or die ("Can't open database!"); [/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.