Log in

View Full Version : SQL select Is giving me problems. can anyone help?



Hollywood
01-02-2010, 12:17 AM
I'm typically a novice in web design and i'm trying to learn it using cold fusion as my server technology but i'm having problem with my select statements.
/*****example****/
assuming i have a database named mydatabase (Microsoft access) that contains a table named students and i want to select fields form the table based on the value entered on the form input field, i would probably use something like this as the result page
<cfquery name="Getstudents" datasource="mydatabase">
SELECT * FROM students
WHERE Name(name of student in the table) = <cfqueryparam value="#Form.Name#" CFSQLType="CF_SQL_VARCHAR">
</cfquery>
note: name = from the name of the students table
#form.name# = name of the form input field

My problem is that when ever a value that does not exist in the table is entered into the form input field, the result will display nothing at all, so i want to know how to set an error message to display whenever an invalid value is entered into the form input field, please help.
Any assistance of any sort will be highly appreciated.
my email is luckiano2k6@yahoo.com
thanks

rawl747
02-07-2010, 06:40 PM
You need to test your output for before displaying it and if there is none, display that the name entered was not in the database. One method is to perform a Select Count(*) first into a variable for the same "where clause" and if the count is zero then you know that you will get no records. But most programmers just test the properties of the returned recordset and if it has zero records, then conditionally throw up a "name not found in database" page with a link to return to the query page.

This is very basic query logic display handling stuff and you would benefit from getting a good book on SQL programming. Even a used book that was 2 or 3 years old from Alibris or Amazon would give you a lot of insight into how to code database applications.

Rule 1: always test your input values before you submit them to the database in a query

Rule 2: always test your output from the database query before you try to display it to the user and especially be aware of how NULL values will effect your results.

If you don't know what a NULL is or how NULL values effect database queries then definitely get that book on SQL programming!

Good luck.
rawl747

Hollywood
03-20-2010, 02:15 AM
i got it figured out :) but i thong i definitely need the book on sql programming. where can i get it please. thanks