Warning: mysql_fetch_array():??

Discussion in 'PHP' started by faizdead, May 15, 2012.

  1. faizdead

    faizdead New Member

    Joined:
    Apr 26, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    this is my coding for php..i need it to extract information on my database.


    PHP:
    <HTML>
    <HEAD><TITLE>List of Registrations</TITLE><HEAD>
    <BODY>
    <TABLE BORDER="1">
    <tr>
    <th>Semester</th>
    <th>Subject name</th>
    <th>Section</th>
    <th>Name</th>
    </tr>
    <?php
    mysql_connect
    ("---","---","---") or die("Connection Failed");
    mysql_select_db("---")or die("Connection Failed");
    $name $_POST['card'];

    $result mysql_query("select s1.name, s2.subject_name, s3.semester,s4.section " .
    "from Student as s1, pelajar as s2, student_subject s3"." where semester = '$name' and"."(s3.matric = s1.matric)
    and "
    .
    " (s2.subject_code=s3.subject_code)");

    while (
    $line mysql_fetch_array($result))
    {

    echo 
    "<TR align=left>\n";
    echo 
    "<TD>"$record["semester"], "</TD>",
    "<TD>"$record["subject_name"], "</TD>",
    "<TD>"$record["section"], "</TD>",
    "<TD>"$record["name"], "</TD>";
    echo 
    "</TR>\n";
    }
    ?>



    </TABLE>
    </BODY>
    </HTML>




    and this error keep coming..why is it?

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
     
  2. pein87

    pein87 Active Member

    Joined:
    Aug 6, 2010
    Messages:
    173
    Likes Received:
    47
    Trophy Points:
    28
    Occupation:
    Web Dev
    Location:
    Limbo
    Your query needs work, you need to first check to see if it returns anything using phpmyadmin or mysql workbench.

    try this:



    PHP:
    $result mysql_query("SELECT s1.name, s2.subject_name, s3.semester,s4.section FROM Student as s1, pelajar as s2, student_subject s3 WHERE semester = '"$name ."' AND s3.matric = s1.matric
    AND s2.subject_code = s3.subject_code"
    );
    and see if it returns something by saying this:

    PHP:
    $rowFlag mysql_num_rows($result);

    if(
    $rowFlag <= 0)
    {
     
    // debug error here, no results returned.
    }
    else
    {
    // do output work
    }
    if that doesn't work try checking your query. Also no usernmae,password, or host is selected in the connect statement so your not connected to any resources and no database is selected either.
     
    Last edited: May 28, 2012
  3. Alex.Gabriel

    Alex.Gabriel New Member

    Joined:
    Oct 23, 2011
    Messages:
    86
    Likes Received:
    7
    Trophy Points:
    0
    Occupation:
    Linux system administrator
    Location:
    Italy
    Home Page:
    http://blog.evilcoder.net
    Where did you copy/paste this script ?
    You have defined
    Code:
    $line
    and queryed
    Code:
    $record
    PHP:
    <HTML>
    <HEAD><TITLE>List of Registrations</TITLE><HEAD>
    <BODY>
    <TABLE BORDER="1">
    <tr>
    <th>Semester</th>
    <th>Subject name</th>
    <th>Section</th>
    <th>Name</th>
    </tr>
    <?php
    mysql_connect
    ("---","---","---") or die("Connection Failed");
    mysql_select_db("---")or die("Connection Failed");
    $name $_POST['card'];

    $result mysql_query("select s1.name, s2.subject_name, s3.semester,s4.section " .
    "from Student as s1, pelajar as s2, student_subject s3"." where semester = '$name' and"."(s3.matric = s1.matric)
    and "
    .
    " (s2.subject_code=s3.subject_code)");

    while (
    $line mysql_fetch_array($result))
    {

    echo 
    "<TR align=left>\n";
    echo 
    "<TD>"$line["semester"], "</TD>",
    "<TD>"$line["subject_name"], "</TD>",
    "<TD>"$line["section"], "</TD>",
    "<TD>"$line["name"], "</TD>";
    echo 
    "</TR>\n";
    }
    ?>



    </TABLE>
    </BODY>
    </HTML>
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice