Results 1 to 10 of 10

Thread: Dont know what im doing wrong...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    448

    Dont know what im doing wrong...

    Im not sure what im doing wrong, it keeps returning Select Failed! every time. Can you help me fix the problem thanks!
    PHP Code:
    <? 
           mysql_connect("localhost","username","password") 
                or die("Unable to connect to SQL server"); 
            mysql_select_db("jokes") 
                or die("Unable to select database");
    $query = "SELECT * FROM jokes";

    $joke = mysql_query($query) or die("Select Failed!");
    ?>
    <?php echo $joke['JokeText'];?>
    Last edited by Muk108; Jan 6th, 2003 at 10:38 PM.

  2. #2
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    try this
    PHP Code:
    <? 
           mysql_connect("localhost","username","password") 
                or die("Unable to connect to SQL server"); 
            mysql_select_db("jokes") 
                or die("Unable to select database");
    $query = "SELECT * FROM jokes";

    $joke = mysql_query($query);
    if (!$joke){echo mysql_error();}
    ?>
    // and this won't work. it will echo Resource ID instead
    // need to add mysql_fecth_array() to get this
    <?php echo $joke['JokeText'];?>

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    448
    Its not returning any errors now, but i can't get it to print out the text from the database. Could you help me do this please. My database is layed out like this...
    Code:
    CREATE TABLE jokes (
      joke_id int(4) NOT NULL auto_increment,
      joke_name varchar(50) default NULL,
      joke_date datetime NOT NULL default '0000-00-00 00:00:00',
      joke_message text,
      PRIMARY KEY  (joke_id)
    ) TYPE=MyISAM;
    Do you think you could help me display what is in the message part? I am have problems with this. Thank You.

  4. #4
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    Originally posted by phpman
    try this
    PHP Code:
    <? 
           mysql_connect("localhost","username","password") 
                or die("Unable to connect to SQL server"); 
            mysql_select_db("jokes") 
                or die("Unable to select database");
    $query = "SELECT * FROM jokes";

    $joke = mysql_query($query);
    if (!$joke){echo mysql_error();}
        while ($row = mysql_fetch_array($joke)){
            echo $row['joke_id'];
            echo $row['joke_name'];
            echo $row['joke_message'];
            echo $row['joke_date'];
            echo"<br />"\n";

    ?>

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    448
    I tryed it exactly how you put it exept i change the username and password and it got this error. "Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in C:\HTTP\www\test2.php on line 15"

  6. #6
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    oh sorry, change this line

    echo"<br />"n";

    to this

    echo"<br />\n";

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    448
    After i fix that i get this error "Parse error: parse error, unexpected $ in C:\HTTP\www\test2.php on line 17"

  8. #8
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    hehe man I am not with it today. ad a } right after the last line you just fixed. so it all should look like this

    PHP Code:
    <? 
           mysql_connect("localhost","username","password") 
                or die("Unable to connect to SQL server"); 
            mysql_select_db("jokes") 
                or die("Unable to select database");
    $query = "SELECT * FROM jokes";

    $joke = mysql_query($query);
    if (!$joke){echo mysql_error();}
        while ($row = mysql_fetch_array($joke)){
            echo $row['joke_id'];
            echo $row['joke_name'];
            echo $row['joke_message'];
            echo $row['joke_date'];
            echo"<br />\n";
        }
    ?>

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    448
    Thank you very much for your help phpman. That works this time.

  10. #10
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Thumbs up


Posting Permissions

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



Click Here to Expand Forum to Full Width