+ Reply to Thread
Results 1 to 10 of 10

Thread: whats wrong?

  1. #1
    maxyes is offline x10Hosting Member maxyes is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    24

    whats wrong?

    Code:
      <?php
    
    $link = mysql_connect("localhost", "mysql_user", "mysql_password");
    mysql_select_db("database", $link);
    
    $result = mysql_query("SELECT * FROM table1", $link);
    $num_rows = mysql_num_rows($result);
    
    echo "$num_rows Rows\n";
    
    ?> 
    is it the php version?

  2. #2
    cowctcat's Avatar
    cowctcat is offline x10 Lieutenant cowctcat is an unknown quantity at this point
    Join Date
    Nov 2007
    Location
    In front of a computer
    Posts
    401

    Re: whats wrong?

    what is the error that you get
    --cowctcat

  3. #3
    maxyes is offline x10Hosting Member maxyes is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    24

    Re: whats wrong?

    something about line 7 error. I dont quite know because my http is down.

  4. #4
    Anna's Avatar
    Anna is offline I am just me Anna is a name known to allAnna is a name known to all
    Join Date
    Aug 2007
    Location
    Sweden
    Posts
    6,569

    Re: whats wrong?

    it's in the echo, you need to concatenate (ie add the variable to the string) the string with the variable.

    echo $num_rows . " Rows\n";

    that should work

    for info on various ways to use echo: http://se2.php.net/echo
    Last edited by Anna; 08-29-2008 at 05:02 PM.

  5. #5
    Scoochi2's Avatar
    Scoochi2 is offline x10 Sophmore Scoochi2 is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Southport!
    Posts
    185

    Re: whats wrong?

    Quote Originally Posted by LadyAnna View Post
    it's in the echo, you need to concatenate (ie add the variable to the string) the string with the variable.

    echo $num_rows . " Rows\n";
    No you don't. You only need to do that for single quotes. Double quotes is perfectly fine.


    maxyes, can you post the exact error that you see? Copy-paste it straight here. (when you can)
    Last edited by Scoochi2; 08-29-2008 at 05:21 PM.
    If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts:

  6. #6
    maxyes is offline x10Hosting Member maxyes is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    24

    Re: whats wrong?

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/topclans/public_html/index.php on line 7
    Rows
    I think its to do with the databse mayby

  7. #7
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: whats wrong?

    check to make sure that the query is properly executing without any hidden errors.
    PHP Code:
    if ($result) {
      echo 
    "good";
    } else {
      echo 
    "bad " mysql_error();

    Also, you don't need the $link if you've only got one open mysql connection. Just thought you might find that handy.

    Quote Originally Posted by http://www.php.net/mysql_query
    link_identifier

    The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level error is generated.
    Last edited by xPlozion; 08-29-2008 at 08:06 PM.

  8. #8
    maxyes is offline x10Hosting Member maxyes is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    24

    Re: whats wrong?

    bad No database selected :s what should i do?

  9. #9
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: whats wrong?

    try this and see what you get:
    PHP Code:
    <?php
    mysql_connect
    ("localhost""mysql_user""mysql_password");
    mysql_select_db("database");

    $result mysql_query("SELECT * FROM table1");
    if (
    $result) {
      
    $num_rows mysql_num_rows($result);
      echo 
    "$num_rows Rows\n";
    } else {
      echo 
    "bad " mysql_error();


    ?>

  10. #10
    scopey is offline x10Hosting Member scopey is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    62

    Re: whats wrong?

    It's a good idea when you're testing a script to put 'or die(mysql_error())' next to all your 'mysql_query()' statements. It'll just stop and print the error it's getting.

    Anyway... Make sure you have your database name right. It'll be named 'maxyes_database' or something similar.
    Last edited by scopey; 08-29-2008 at 10:39 PM.
    - When in doubt, refer to the PHP manual.

+ Reply to Thread

Similar Threads

  1. What is wrong?
    By VeggieBoy in forum Off Topic
    Replies: 10
    Last Post: 03-08-2008, 05:44 AM
  2. Wrong Disk Usage Reading
    By 818Papi in forum Free Hosting
    Replies: 4
    Last Post: 01-29-2008, 09:06 PM
  3. phpmyadmin wrong username and password?
    By shaunNO2007 in forum Free Hosting
    Replies: 0
    Last Post: 01-17-2008, 12:24 PM
  4. SOme thing wrong with addon domain
    By dharmil in forum Free Hosting
    Replies: 2
    Last Post: 08-24-2006, 12:13 PM
  5. Help please, Server down or something wrong?
    By flyingwolf in forum Free Hosting
    Replies: 15
    Last Post: 05-19-2005, 12:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers