SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Threaded View

  1. #1
    SitePoint Member
    Join Date
    Apr 2009
    0 Post(s)
    0 Thread(s)

    Question mysql_query() string?


    I am a beginner site builder , I am reading Build Your Own Database Driven Website Using PHP & MySQL 3rd Edition by Kevin Yark.

    I have an obstacle, and if you guys look at this code really quick and give me some answers, I safe time and would be really appreciated.

    PHP Code:
    $jokelist = @mysql_query('SELECT joketext 
            FROM joke, author WHERE name=$name AND'
    this code does't read the variable "$name" how can I make it read it?
    it gives this error:" Unknown column '$name' in 'where clause' "
    it works if write the name manually.

    Quote Originally Posted by oddz View Post
    PHP Code:
    $jokelist = @mysql_query("SELECT joketext 
            FROM joke, author WHERE name='
    $name' AND"); 
    Use double quotes not single quotes when you like to embed variables and have them evaluated in a string. If name is a string then you must also quote that.

    Last edited by MertTheGreat; May 12, 2009 at 15:23.


Posting Permissions

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