Results 1 to 3 of 3

Thread: SQL select Is giving me problems. can anyone help?

  1. #1
    Join Date
    Dec 2009
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation SQL select Is giving me problems. can anyone help?

    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

  2. #2
    Join Date
    Feb 2010
    Location
    virginia beach, va usa
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Not an SQL issue

    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

  3. #3
    Join Date
    Dec 2009
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default thanks , it's fine

    i got it figured out but i thong i definitely need the book on sql programming. where can i get it please. thanks
    Last edited by Hollywood; 03-20-2010 at 02:23 AM. Reason: i definitelyneed it

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •