problems with form info in SQL

Results 1 to 2 of 2

Thread: problems with form info in SQL

  1. #1
    Join Date
    Dec 1969

    Default problems with form info in SQL

    Hi, I am writing a search engine to get records from my database<BR>I am getting 2 variables from a form which sent the browser to the page containing this text. &#039searchby&#039 will contain either artist, title or label, which are all names of columns in my database and &#039searchfor&#039 will be a string that the user wants to search for. <BR>My problem is that I want to select text matching that in &#039searchfor&#039 but only in the column identified in searchby.<BR>At the moment, I&#039m not getting any errors with the text below, it&#039s just not finding any records when I know that it should be.<BR><BR>Any help with my problem would be greatly appreciated<BR><BR>Thanks in advance<BR>Dominic<BR><BR><BR>searchby=Request.For m("searchby")<BR>searchfor=Request.Form("searchfor ")<BR><BR>SQL="SELECT artist,title,label,format,format_sub,remarks FROM dance_vinyl WHERE &#039"&searchby&"&#039 = &#039"&searchfor&"&#039 ORDER BY artist"<BR><BR>Also, I actually want to select the data form ALL tables in the database file but it doesn&#039t like it if I use <BR>SELECT ...stuff... FROM * of stuff...<BR>any ideas why not?<BR><BR>Cheers

  2. #2
    Join Date
    Dec 1969

    Default RE: problems with form info in SQL

    Answer to first problem <BR><BR>Your SearchBy is a field name and should therefore not be enclosed within single quotes.<BR><BR>Answer to second problem<BR><BR>Your select doesn&#039t work because it is not valid SQL! As far as I am aware the only way you will be able to select data from all tables in the way you want is to perform a UNION query e.g.<BR><BR>SELECT artist,title<BR>FROM dance_vinyl<BR>UNION SELECT artist,title<BR>FROM artyfarty_classical<BR><BR>regards, Steve<BR><BR><BR><BR><BR><BR>

Posting Permissions

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