I'm getting this error when I execute my form and it brings up the corresponding .php page.

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:


<?

$link=mysql_connect('host', 'database', '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'];


}



?>

From what I've found, this should work. I've seen where others have had this problem but I have yet to find the solution. Any help would be appreciated.

Thanks

    without looking at your database dump file... my first guess would be the # sign in the column name. I would rename the column and see if that fixes it. Php and mysql are notorious for not liking special characters as column and variable names.

      I changed all the column headers 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'

        that is your database connect script. You need to check it for a database name.

          Ok..I got it to find the database and it return the values with an echo statement. How do I assign column names to variables? Thanks

            You might also look at this...

            $result=mysql_query($query);

            Try
            $result=mysql_query($query,$link);

            so it knows what connection for the query...

              $data=mysql_fetch_array($results);

              $var1=$data[0];
              $var2=$data[1];

              etctra

              you can also find out what your data offsets are by using this

              echo('<pre>');
              print_r($data);
              echo('</pre>');

              that will print out the first record of your array with all the offsets. the <pre> just makes it easier to read.

                cbrknight - I appreciate you taking the time to help me with this. Unfortunately I'm very new to all of this. I'm trying to put together a "web portal" for a client to access and look at their accounts. I'm not very familiar with the language yet.

                When I used this: echo $row['guarantor']; It worked just find.

                Now I want to use the print command so that I can format and put the information exactly where I want it on the page. Or can I use the echo command above within html formatting to get the same result?

                Thanks again...very much appreciated.

                  you can use echo $row['guarantor'];
                  or set

                  $guarantor = $row['guarantor'];

                  and use echo $guarantor;

                  I believe you can print also...

                  but I never us print so couldnt tell you the pros and cons of echo vs. print

                    as to html I would do it something like this

                    <tr>
                    <td>Guarantor Name: <?php echo $guarantor; ?> </td>
                    </tr>

                    or you can

                    echo('
                    <tr>
                    <td>Guarantor Name: $guarantor </td>
                    </tr>
                    ')
                    With the second method all the html is processed through php and you have to be careful with your quotes

                      Thanks! Now that I see it, it's simple. Sometimes I make it harder than it should be. I'll give it a try and post my results.

                        I think I learn everthing in PHP the hard way... Good luck

                          Ok...one more quick question...where do I put, for example, $guarantor = $row['guarantor']; in the code?

                            anywhere after the mysql_fetch_array.... and before you echo it out....

                              That worked! You have no idea how much I appreciate your help. I've been fighting with this stuff for about 3 or 4 days. Slowly coming to understand though. Thanks Again.

                                No problem dont forget to Set link to RESOLVED

                                  Write a Reply...