+ Reply to Thread
Results 1 to 8 of 8

Thread: Php Help

  1. #1
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    Php Help

    I need help with a script that displays my mysql table. I keep getting this error.

    PHP Code:
    Parse errorsyntax errorunexpected $end in /home/leafy/public_html/roster.php on line 31 

    Here is the code:

    PHP Code:
    <?php
    $username
    ="leafy_admin";
    $password="removed";
    $database="leafy_roster";
    mysql_connect(localhost,$username,$password);
    @
    mysql_select_db($database) or die( "Unable to select database");
    $query="SELECT * FROM leafy_clanemail";
    $result=mysql_query($query);
    $num=mysql_numrows($result);
    mysql_close();
    echo 
    "<b><center>Night Assassins Clan Roster</center></b><br><br>";
    $i=0;
    while (
    $i $num) {
    $name=mysql_result($result,$i,"field1-name");
    $email=mysql_result($result,$i,"field2-name");
    $rank=mysql_result($result,$i,"field3-name");

    echo 
    "<b>$field1-name 
    $field2-name2</b><br>$field3-name<br>;
    $i++;
    }
    ?>
    Can you find out anything wrong with it?
    Last edited by leafypiggy; 12-04-2007 at 04:04 PM.

  2. #2
    knightcon's Avatar
    knightcon is offline x10Hosting Member knightcon is an unknown quantity at this point
    Join Date
    Nov 2007
    Location
    Sydney, Australia
    Posts
    69

    Re: Php Help

    Your missing a closing quotation marks. Try this code instead...

    PHP Code:
     <?php 
    $username
    ="leafy_admin"
    $password="nightassassins"
    $database="leafy_roster"
    mysql_connect(localhost,$username,$password); 
    @
    mysql_select_db($database) or die( "Unable to select database"); 
    $query="SELECT * FROM leafy_clanemail"
    $result=mysql_query($query); 
    $num=mysql_numrows($result); 
    mysql_close(); 
    echo 
    "<b><center>Night Assassins Clan Roster</center></b><br><br>"
    $i=0
    while (
    $i $num) { 
    $name=mysql_result($result,$i,"field1-name"); 
    $email=mysql_result($result,$i,"field2-name"); 
    $rank=mysql_result($result,$i,"field3-name"); 

    echo 
    "<b>$field1-name  
    $field2-name2</b><br>$field3-name<br>"
    $i++; 
    }
    ?>

  3. #3
    Mohron is offline x10Hosting Member Mohron is an unknown quantity at this point
    Join Date
    Nov 2007
    Posts
    49

    Re: Php Help

    Here's a great way to find php syntax errors.
    http://www.meandeviation.com/tutoria...-syntax-check/

  4. #4
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    Re: Php Help

    thanks, ill check it out, and can you remove my pass from the script, lol, I forgot to take it out.
    Edit:
    It just gave me another error. Meanwhile, I tried this script from w3schools:

    PHP Code:
    <?php
    $con 
    mysql_connect("localhost","leafy_admin","*REMOVED*");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }

    mysql_select_db("leafy_roster"$con);

    $result mysql_query("SELECT * FROM leafy_clanemail");

    echo 
    "<table border='1'>
    <tr>
    <th>Name</th>
    <th>Email</th>
    <th>Rank</th>
    </tr>"
    ;
    while(
    $row=mysql_fetch_array($result));
      {
      echo 
    "<tr>";
      echo 
    "<td>" $row['name'] . "</td>";
      echo 
    "<td>" $row['email'] . "</td>";
      echo 
    "<td>" $row['rank'] . "</td>";
      echo 
    "</tr>";
      }
    echo 
    "</table>";mysql_close($con);
    ?>
    I get this error:

    HTML Code:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/leafy/public_html/rosterw3schools.php on line 18
    Last edited by leafypiggy; 12-04-2007 at 04:09 PM. Reason: Automerged Doublepost

  5. #5
    xbeto78 is offline x10Hosting Member xbeto78 is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    5

    Re: Php Help

    The while loop does not need a semicolon at the end of the line. It only needs an opening and closing brace.


    while(
    $row=mysql_fetch_array($result
    ))
    {
    echo
    "<tr>"
    ;
    echo
    "<td>" . $row['name'] . "</td>"
    ;
    echo
    "<td>" . $row['email'] . "</td>"
    ;
    echo
    "<td>" . $row['rank'] . "</td>"
    ;
    echo
    "</tr>"
    ;
    }
    echo
    "</table>";mysql_close($con
    );
    ?>

  6. #6
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    Re: Php Help

    changed that, now getting this:

    PHP Code:
    Warningmysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/leafy/public_html/rosterw3schools.php on line 2
    Could not connect: Can'
    t connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2
    Temporery or do I need to link it to the new MYSQL server.

  7. #7
    Slothie's Avatar
    Slothie is offline Lord Of The Keys Slothie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Singapore
    Posts
    1,432

    Re: Php Help

    Are you by any chance, on stoli?

    If you are, link yourself to the new mysql server

    Easiest 70 points you'll make on x10

    Feel free to add my reputation by clicking on the if you found my post helpful to you :P


    If I am not responding to your PMs, that means I am ignoring you. Take a hint.



    09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0


  8. #8
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    Re: Php Help

    yeah Im on Stoli. What is the new IP?
    Edit:
    I changed the server for MYSQL but I am still getting the
    PHP Code:
    Warningmysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/leafy/public_html/rosterw3schools.php on line 18 
    error
    Last edited by leafypiggy; 12-05-2007 at 05:30 PM. Reason: Automerged Doublepost

+ Reply to Thread

Similar Threads

  1. tons of PHP Resources
    By Chris S in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 01-16-2009, 10:07 AM
  2. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM
  3. Sigo con problemas con phpbb2
    By reciecho in forum Soporte
    Replies: 7
    Last Post: 10-20-2007, 06:28 PM
  4. "PHP Startup: Invalid Library" - Interesting error
    By javaguy78 in forum Free Hosting
    Replies: 5
    Last Post: 03-27-2007, 02:33 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