SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Member
    Join Date
    Nov 2009
    Location
    Devon, UK
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem with SELECT query

    I'm working through Kevin Yank's book, PHP & MYSQL ed.4 and things were going well until I tried selecting more than 1 column of my database. This part of the code seemed to be the cause of my problem; It just wouldn't function at all. In desperation I tried the downloaded code from the books website, altering only the password to access my server.

    Code:
    $result = mysqli_query($link, 'SELECT id, joketext FROM joke');
    if (!$result)
    {
    	$error = 'Error fetching jokes: ' . mysqli_error($link);
    	include 'error.html.php';
    	exit();
    }
    
    while ($row = mysqli_fetch_array($result))
    {
    	$jokes[] = array('id' => $row['id'], 'text' => $row['joketext']);
    }
    
    include 'jokes.html.php';
    All the necessary files are uploaded.
    Can someone help please?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    pls move either to php or to Questions forum
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    try backtick-ing the sql. So
    Code:
    SELECT `id`, `joketext` FROM `joke`
    Ryan B | My Blog | Twitter

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by rguy84 View Post
    try backtick-ing the sql.
    that's not it

    the backticks are optional, and actually get in the way
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,074
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    There's nothing wrong with the query. What page of the book is this from?
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    oh look, i just saw that i replied earlier to the thread, instead of reporting it

    i meant to report it so that a moderator could move it to the php forum (it has to be a php error because SELECT id, joketext FROM joke is basically bulletproof)

    alternatively to the Questions forum, which is intended to let people ask questions about stuff they're having trouble with in any of the sitepoint books

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    SitePoint Member
    Join Date
    Nov 2009
    Location
    Devon, UK
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your reply SpacePhoenix. The complete code is on page 148.

  8. #8
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Rudy, some all-in-one packages, like xampp, have weird bugs. I Have seen in other forums that their SQL was legit, their php code was fine, yet an error was thrown. Why? cause that version of that package required you to back tick the field and table names in the query string.

    Since I know you know sql inside and out, and hate back ticking myself, I was suggesting that just in case.
    Ryan B | My Blog | Twitter

  9. #9
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    understood, but if it's just "that version of that package" then it shouldn't become your default strategy for any mysql error message

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  10. #10
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,074
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Were any error messages displayed or did you get no output at all? The script in question seems to be giving a number of people grief as I've seen a few threads about problems with it. Did you install php and mysql seperaratly onto the apache server or did you use WAMP?
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  11. #11
    SitePoint Member
    Join Date
    Nov 2009
    Location
    Devon, UK
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Apache HTTP Server has encountered a problem .... etc. followed by the cannot display webpage page. I installed the php and mysql separately following the instructions in Kevin's book exactly. This is so frustrating!

  12. #12
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,074
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    A corrupt install of php and/or mysql is a possibility.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  13. #13
    SitePoint Member
    Join Date
    Nov 2009
    Location
    Devon, UK
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi
    Thank you so much. I've now downloaded WAMP and everything works perfectly!

  14. #14
    SitePoint Member
    Join Date
    Dec 2009
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had the exact same problem on the exact same code. Turns out the issue is with a .dll file with the same name in both PHP and MYSQL. You need to set a Windows PATH variable for your PHP directory *before* the one to the MYSQL directory and reboot your computer.

    This explanation lead me in the right direction:

    talkincode.com/php528-and-mysql-51-crashing-apache-22-on-windows-804.html


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
  •