SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot martin's Avatar
    Join Date
    Jun 2001
    Location
    London
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    First Ever PHP MySQL script help!

    I've finally managed to get PHP and MySQL working on my Linux box. This is my first real PHP script and the connection to the database seems to be working but I get the following error:

    Parse error, expecting 'T_STRING' or 'T_VARIABLE' or'T_NUM_STRING in /myfiles/test.php line 1

    This only happens when I add "my_sql_fetch_array" section of code.If I take it out I get no errors.

    P.S. How do I cut and paste PHP code into here to show you? I dont want to retype it!
    Martin

  2. #2
    SitePoint Addict jamesbond's Avatar
    Join Date
    Feb 2001
    Location
    The Netherlands
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It should be mysql_fetch_array instead of my_sql_fetch_array

    To copy&paste the code:

    You select the code with your mouse (keep the left mouse button pressed down)
    Then right click, select copy
    Then go the sitepoint window and do right click again and select paste.

    Oops sorry, you're on a linux box...

  3. #3
    SitePoint Zealot martin's Avatar
    Join Date
    Jun 2001
    Location
    London
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Miss typed question!

    Sorry, I miss typed my question! I've managed to copy and paste my script now, as you can see I'm using mysql_fetch_array - not my_sql_fetch_array any ideas?

    PHP Code:
    <?php

    $dbconnect 
    mysql_connect ("localhost""root""martinsql");
    if (!
    $dbconnect) {
        echo( 
    "<P>Unable to connect to the ".
        
    "database server at this time.</P>");
    exit();
    }


    mysql_select_db ("powerhouse"$dbconnect);
    if (! @
    mysql_select_db ("powerhouse")) {
        echo(
    "<P>Unable to locate the PowerHouse ".
        
    "database at this time.</P>");
    exit();
    }
    ?>

    <P>List of PowerHouse Staff</P>

    <?php

    $result 
    mysql_query("SELECT name FROM staff");
    if (!
    $result) {
        echo(
    "<P>Error performing query: ".
        
    mysql_error(). "</P>");
    exit();
    }


    while ( 
    $row mysql_fetch_array($result) ) {
            echo (
    "<P>.$row["name"]."</P>");
    }

    ?>
    Martin

  4. #4
    SitePoint Addict jamesbond's Avatar
    Join Date
    Feb 2001
    Location
    The Netherlands
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should replace :

    echo ("<P>.$row["name"]."</P>");

    by

    echo "<P>$row[name]</P>";


    Now it should work

  5. #5
    SitePoint Zealot martin's Avatar
    Join Date
    Jun 2001
    Location
    London
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks

    Thanks James Bond,

    That now works! I would just like to say as a general comment tha t this site is very friendly and fast - keep up the excellent work.
    Martin


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
  •