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
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.matricAND 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.
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><?phpmysql_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>