+ Reply to Thread
Results 1 to 7 of 7

Thread: problems after problems

  1. #1
    gamewars is offline x10Hosting Member gamewars is an unknown quantity at this point
    Join Date
    Jul 2009
    Posts
    16

    problems after problems

    Im back with another problem. Same as usual for your help I'll give you mine. I will code in html for you or graphic design for any web site you need help with.


    so basicaly whats wrong is that all my info is not showing up on the table. click on the link to see the problem.



    http://gamewars.x10hosting.com/availablexbox360wars.php


    code


    <?php
    $con = mysql_connect("localhost","gamewars_gamewars","xxx xxx");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    mysql_select_db("gamewars_xbox360postedwars", $con);
    $result = mysql_query("SELECT * FROM post");
    echo "<table border='1'>
    <tr>
    <th>firstname</th>
    <th>lastname</th>
    <th>quantity</th>
    <th>items</th>
    <th>players</th>
    </tr>";
    while($row = mysql_fetch_array($result))
    {
    echo "<tr>";
    echo "<td>" . $row['firstName'] . "</td>";
    echo "<td>" . $row['lastName'] . "</td>";
    echo "<td>" . $row['quantity'] . "</td>";
    echo "<td>" . $row['items'] . "</td>";
    echo "<td>" . $row['players'] . "</td>";
    echo "</tr>";
    }
    echo "</table>";
    mysql_close($con);
    ?>
    Last edited by gamewars; 08-27-2009 at 05:33 PM.

  2. #2
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: problems after problems

    Step 1. Do not post your username/password combination. Edit it out. Better yet, go change the password.

    Instead of $row['firstName'] , try $row[0], etc.

    Looks like your table columns are not named exactly as you think they are.
    That, or there is no info in those cols to begin with. You can browse a table using phpMyAdmin from the cPanel.
    Nothing is always absolutely so.

  3. #3
    gamewars is offline x10Hosting Member gamewars is an unknown quantity at this point
    Join Date
    Jul 2009
    Posts
    16

    Re: problems after problems

    Quote Originally Posted by descalzo View Post
    Step 1. Do not post your username/password combination. Edit it out. Better yet, go change the password.

    Instead of $row['firstName'] , try $row[0], etc.

    Looks like your table columns are not named exactly as you think they are.
    That, or there is no info in those cols to begin with. You can browse a table using phpMyAdmin from the cPanel.


    Thanks a lot email me when ever you need help sorry about the password i did at first then it changed it back for some reason thanks.

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: problems after problems

    What can you deduce from the behavior? The "while" loop block is guaranteed to print HTML table row and cell elements, even if $row['firstName'] & al. aren't defined. That no HTML <tr> or <td> are printed tells you that $result is empty. Either the query is returning an empty result or there's an error. You'll need to add error checks to figure out which. This is one reason why you should always include error handling code in your scripts. You could use the outdated "or die (mysql_error(...))" while testing, but you'll need to change it for the production version, so you might as well do it the right way from the get-go.

    First, move the db connection code to a different script (that link is particularly important for you to read). The more files hold your password, the more opportunities there are for someone to steal it. Also, if you ever change your password, it's much easier to do if it's only used in a single file.

    Next, let's refactor the code that prints the table into a function so that you can use it in other scripts. Here's a simplistic gridView.php to start with:
    PHP Code:
    // gridView.php
    function gridView($rslt$fields) {
        if (
    $rslt->rowCount()) {
            echo 
    '<table><thead><tr>'implode('</th><th>'$fields), '</tr></thead><tbody>';
            
    $parity=False;
            while (
    $row $rslt->fetch(PDO::FETCH_NUM)) {
                
    // 'parity' class is so you can style even & odd rows differently
                
    echo '<tr class="',($parity 'odd' 'even'),'"><td>'implode('</td><td>'$row) , '</td></tr>';
                
    $parity = !$parity;
            }
            echo 
    '</tbody></table>';
        } else {
            echo 
    '<p>No results.</p>';
        }

    Now an error logging/printing function.
    PHP Code:
    // printError.php
    function printError($exc) {
        global 
    $dbg$devEmail;
        if (
    $dbg) {
            echo 
    "<pre>$exc</pre>";
        } else {
            echo 
    "Something went wrong on our end. An error was logged and we'll look into it.";
            
    error_log($msg);
            
    // if you want to be e-mailed a copy of the error, define $devEmail and uncomment the following
            #error_log($msg, 1, $devEmail);
        
    }

    Tying it all together: let's stop using the old MySQL driver (which is horribly outdated) and switch to PDO. Among the many benefits is easier error handling via exceptions.
    PHP Code:
    $dbg 1;
    // localDB.php defines local_db_connect
    include_once('localDB.php');
    include_once(
    'gridView.php');
    include_once(
    'printError.php');

    $fields = array('firstName''lastName''quantity''items''players');
    $db local_db_connect('PDO');
    $db->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);

    try {
        
    $posts $db->query("SELECT `" implode("`, `",  $fields) . "` FROM post");
        
    gridView($posts$fields);
    } catch (
    PDOException $exc) {
        
    printError($exc);

    Some posting tips: use proper punctuation. Remember, Mr. Period is "your friend at the end." Use whichever of [php], [html] or [code] tags are appropriate around your source code to make it easier to read. They will preserve formatting, separate the code from the rest of your post and (for [php] and [html]) colorize the source, making it easier for people to parse.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  5. #5
    gamewars is offline x10Hosting Member gamewars is an unknown quantity at this point
    Join Date
    Jul 2009
    Posts
    16

    Re: problems after problems

    im still getting the problem its not working.

  6. #6
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: problems after problems

    Change your query to:

    PHP Code:
    $result mysql_query("SELECT firstName, lastName, quantity, items, players  FROM post"); 
    and see what happens.

    Also, did you look at the db to make sure those fields actually have values?
    Nothing is always absolutely so.

  7. #7
    gamewars is offline x10Hosting Member gamewars is an unknown quantity at this point
    Join Date
    Jul 2009
    Posts
    16

    Re: problems after problems

    yaaaaa i finaly fixed a proble on my own it was a stupid mistake the names were not the samebut thanks for all of your help my web site is done

+ Reply to Thread

Similar Threads

  1. Paid account.. Will it fix problems?
    By altrock182182 in forum Free Hosting
    Replies: 3
    Last Post: 01-14-2008, 04:23 PM
  2. NOTE: For all problems regarding phpBB3 RC6
    By CrownVictoriaCop in forum Free Hosting
    Replies: 1
    Last Post: 10-14-2007, 03:35 PM
  3. Problems...problems...problems...
    By eternal-empire in forum Free Hosting
    Replies: 4
    Last Post: 09-21-2007, 03:53 PM
  4. problems, problems
    By joandajer in forum Free Hosting
    Replies: 5
    Last Post: 01-29-2006, 04:47 PM
  5. more problems after reseting pass
    By rahul2006 in forum Free Hosting
    Replies: 6
    Last Post: 11-10-2005, 08:06 AM

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