SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict manipura's Avatar
    Join Date
    Apr 2001
    Location
    Calgary,AB
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    My script or my host's Problem?

    When I run this script on f2s.com it doesn't work, I have been up all night and wondering if I'm dumb or my host is dumb. All the database stuff works fine, just no script I can run on the site connecting to the DB will work.

    I haven't programmed in PHP for awhile so I'm wondering if its me or not.

    PHP Code:
    <?php
    //connection to the db
    $host="db.nanaimo-online.f2s.com:3306";
    $user="user";
    $pass="pass";
    $db="db";

    $conn = @mysql_connect("$host""$user""$pass");
        if (!
    $conn) {
        print (
    "<p>Unable to make a connection to the server at this time.</p>");
        exit();
        }
        
    mysql_select_db("$db");
        if (! @
    mysql_select_db("$db")) {
        print (
    "<p>Unable to connect to the database at this time.</p>");
        exit();
        }
    // connection is made


    $sql "select * from calgary";
    $result "mysql_query($sql);

    while(
    $row = mysql_fetch_array($result)){

    $id = $row["id"];

    echo "
    $id";
    }

    ?>
    I get an error saying
    Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /web/sites/221/nanaimo/www.nanaimo-online.f2s.com/testcalgary.php on line 28


    Line 28 = $id = $row["id"];

    There is a field in the table that is named "id". Now I just don't know whats wrong!


  2. #2
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try changing line 28 to
    $id = $row[id];

    For whatever reason I have never been able to get a script to work with
    $row["colname"]
    I have always had to use
    $row[colname]

    Kevin

  3. #3
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using quotes is fine and is the correct way of accessing associative arrays. The real problem is this line:

    $result = "mysql_query($sql);
    ck :: bringing chris to the masses.

  4. #4
    SitePoint Addict manipura's Avatar
    Join Date
    Apr 2001
    Location
    Calgary,AB
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $row["colname"]
    has always worked for me.
    Same with
    echo "$input";
    But that didn't work on f2s.com either.

    I have
    echo ($input);
    now...

    Now my problem is................
    The last line of the script.

    It says
    Parse error: parse error in /web/sites/221/nanaimo/www.nanaimo-online.f2s.com/testcalgary.php on line 33

    Line 33 is where the "?>" is...........
    I tried "PHP?>"
    but ther didn't work either

  5. #5
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you post the code again?
    ck :: bringing chris to the masses.

  6. #6
    SitePoint Addict manipura's Avatar
    Join Date
    Apr 2001
    Location
    Calgary,AB
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All is well...

    Thank you very much guys!

  7. #7
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?
    mysql_select_db
    ("$db");
        if (! @
    mysql_select_db("$db")) {
        print (
    "<p>Unable to connect to the database at this time.</p>");
        exit();
        }
    // connection is made


    $sql "select * from calgary";
    $result "mysql_query($sql);

    while(
    $row = mysql_fetch_array($result)){

    $id = $row["id"];

    echo "
    $id";
    }

    ?>
    He either forgot to take out that last }, or he forgot to put a } else { in there.
    Last edited by Defender1; Aug 20, 2001 at 01:12.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  8. #8
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The last } closes the while loop.
    ck :: bringing chris to the masses.


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
  •