SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,388
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    mysql_fetch_array not working

    This code is pretty straightforward, but I can't get the data to display. I get the following error for the fetch_array line:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\achievements_add.php on line 95

    I don't know what part of the argument is invalid.

    Thanks,
    Steve


    PHP Code:
    <ul>
    <?php

    $sqlb 
    = @mysql_query('SELECT mlID, mlModelName FROM model_listing');

    while (
    $sqlc mysql_fetch_array($sqlb)){
        
    $mlID $sqlc['mlID'];
        
    $mlModelName $sqlc['mlModelName'];
    echo 
    "<li><strong>$mlID </strong> . $mlModelName</li>";
    }

    ?>
    </ul>

  2. #2
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    your query is failing, but because you are not doing any error handling you don't know it. look up mysql_query() in the php manual and, at a minimum, follow their example for error handling.

  3. #3
    SitePoint Addict
    Join Date
    Aug 2005
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's sort of silly to suppress errors when developing, add a [or die()] to see what is going on.

    PHP Code:
    $sqlb mysql_query('SELECT mlID, mlModelName FROM model_listing') or die ( 'Query Error: ' mysql_error () ); 

  4. #4
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,388
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by printf View Post
    It's sort of silly to suppress errors when developing, add a [or die()] to see what is going on.

    PHP Code:
    $sqlb mysql_query('SELECT mlID, mlModelName FROM model_listing') or die ( 'Query Error: ' mysql_error () ); 
    Using that code, I get:

    Query Error: Access denied for user 'ODBC'@'localhost' (using password: NO)

    I'll look it up.

  5. #5
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Basically means that your mysql_connect() parameters are incorrect
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  6. #6
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,388
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spikeZ View Post
    Basically means that your mysql_connect() parameters are incorrect
    I am using the same script that worked fine yesterday. I left the top part alone (which contained the connect info) and changed the table info to reflect the new table, treating it like a template. I will go ahead and input data in the form fields for this CMS page and see if it inserts data into the table. The code above is supposed to list table contents so I can look up the info for reference when filling out input boxes elsewhere on the page.

    Thanks!

  7. #7
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,388
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It looks like I simply put the code in the wrong place on the page. When I filled out the form, the page returned with the above content at the bottom, exactly where I wanted it. Here's the code so far, if you're curious:

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>AE Website CMS: Add Achievements</title>
    <meta http-equiv="content-type"
        content="text/html; charset=iso-8859-1" />
    <link rel="stylesheet" type="text/css" href="associatedcss.css">
    <STYLE type="text/css">
    p.border{border-top : 1px #cecece solid;}
    </style>

    </head>

    <body>


    <?php if (isset($_POST['achYear'])):


     
    $dbcnx = @mysql_connect('localhost''root''');
    if (!
    $dbcnx) {
      exit(
    '<p>Unable to connect to the database server at this time.</p>');
    }

    if (!@
    mysql_select_db('aewebsite')) {
      exit(
    '<p>Unable to locate the database at this time.</p>');
    }



    // ADD INFO TO DATABASES




      
    $achYear $_POST['achYear'];
      
    $achModelName $_POST['achModelName'];
      
    $achModelGroup $_POST['achModelGroup'];
      
    $achType $_POST['achType'];
      
    $mlID $_POST['mlID'];
      
    $sqla "INSERT INTO achievements 
    (mlID, achYear, achModelName, achModelGroup, achType) 
        VALUES 
    ('mlID', '
    $achYear', '$achModelName', '$achModelGroup', '".mysql_real_escape_string($achType)."')";

      if (@
    mysql_query($sqla)) {
        echo 
    '<p>New Achievement successfully added</p>';
      } else {
        echo 
    '<p>Error adding new Achievement entry: ' .
            
    mysql_error() . '</p>';
      }



    ?>

    <p><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Add another entry</a></p>
    <p><a href="Achievement_list.php">Return to Achievement list</a></p>


    <?php else: //USER ADDS NEW INFO 



    ?>

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <h2>Achievement</h2>
    <p>Remember to add a backslash( \ ) before every single-quote character.</p>
    <p>Use [EM] and [/EM] tags around publication names.</p>

    <label><p><strong>Year of Achievement,</strong> 4 spaces, req, "2007":</p>
    <input type="text" name="achYear" /></label><br />

    <label><p><strong>Model Name,</strong> req, "B44":</p>
    <input type="text" name="achModelName" /></label><br />

    <label><p><strong>Model Group,</strong> 80 spaces, req:<br />
    "1:8 pan car, 1:12 pan car, 1:10 pan car, 1:10 buggy, 1:10 truck, 1:10 gas truck, 1:18, 1:10 TC, 1:10 gas TC, 1:8 gas truck, 1:8 buggy, 1:10 monster truck"</p>
    <input type="text" name="achModelGroup" /></label><br />

    <label><p><strong>Award Name,</strong> req (100 chars) "Car of the Year [EM](Radio Control Car Action)[/EM]"</p>
    <textarea name="achType" rows="2" cols="35"></textarea></label><br />

    <label><p><strong>Model_Listing's mlID,</strong> req (see below):</p>
    <input type="text" name="mlID" /></label><br />

    <br />
    <input type="submit" value="SUBMIT" />
    </form>




    <?php endif; ?>

    <ul><p class="border"><small>

    <?php
    $sqlb 
    = @mysql_query('SELECT mlID, mlModelName FROM model_listing')
     or die ( 
    'Query Error: ' mysql_error () ); 

    while (
    $sqlc mysql_fetch_array($sqlb)) {
        
    $mlID $sqlc['mlID'];
        
    $mlModelName $sqlc['mlModelName'];
    echo 
    "<li><strong>'$mlID' </strong> . '$mlModelName'</li>";
    }
    ?>
    </small></ul>


    </body>
    </html>


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
  •