Hey so I'm practicing a php code and I keep getting an error message and I'm not sure what I am doing wrong any help would be greatly appreciated ultimately my goal is to view all records in the database on one page. Here is the error message [TABLE] [TR] [TH]User Name[/TH] [TH]First Name[/TH] [TH]Last Name[/TH] [TH]Gender[/TH] [TH]Date of Birth[/TH] [TH]Email[/TH] [/TR] [/TABLE] [TABLE="class: xdebug-error"] [TR] [TH="bgcolor: #f57900, colspan: 5, align: left"]( ! ) Notice: Undefined variable: result in C:\wamp\www\******\********\viewrecord.php on line 42[/TH] [/TR] [TR] [TH="bgcolor: #e9b96e, colspan: 5, align: left"]Call Stack[/TH] [/TR] [TR] [TH="bgcolor: #eeeeec, align: center"]#[/TH] [TH="bgcolor: #eeeeec, align: left"]Time[/TH] [TH="bgcolor: #eeeeec, align: left"]Memory[/TH] [TH="bgcolor: #eeeeec, align: left"]Function[/TH] [TH="bgcolor: #eeeeec, align: left"]Location[/TH] [/TR] [TR] [TD="bgcolor: #eeeeec, align: center"]1[/TD] [TD="bgcolor: #eeeeec, align: center"]0.0009[/TD] [TD="bgcolor: #eeeeec, align: right"]375136[/TD] [TD="bgcolor: #eeeeec"]{main}( )[/TD] [TD="bgcolor: #eeeeec"]..\viewrecord.php:0[/TD] [/TR] [/TABLE] [TABLE="class: xdebug-error"] [TR] [TH="bgcolor: #f57900, colspan: 5, align: left"]( ! ) Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\wamp\www\*******\*******\viewrecord.php on line 42[/TH] [/TR] [TR] [TH="bgcolor: #e9b96e, colspan: 5, align: left"]Call Stack[/TH] [/TR] [TR] [TH="bgcolor: #eeeeec, align: center"]#[/TH] [TH="bgcolor: #eeeeec, align: left"]Time[/TH] [TH="bgcolor: #eeeeec, align: left"]Memory[/TH] [TH="bgcolor: #eeeeec, align: left"]Function[/TH] [TH="bgcolor: #eeeeec, align: left"]Location[/TH] [/TR] [TR] [TD="bgcolor: #eeeeec, align: center"]1[/TD] [TD="bgcolor: #eeeeec, align: center"]0.0009[/TD] [TD="bgcolor: #eeeeec, align: right"]375136[/TD] [TD="bgcolor: #eeeeec"]{main}( )[/TD] [TD="bgcolor: #eeeeec"]..\viewrecord.php:0[/TD] [/TR] [TR] [TD="bgcolor: #eeeeec, align: center"]2[/TD] [TD="bgcolor: #eeeeec, align: center"]0.0053[/TD] [TD="bgcolor: #eeeeec, align: right"]383600[/TD] [TD="bgcolor: #eeeeec"]mysql_fetch_array ( )[/TD] [TD="bgcolor: #eeeeec"]..\viewrecord.php:42[/TD] [/TR] [/TABLE] and here is the code that I have. <?php// Inialize session session_start(); // Retrieve username and password from database according to user's input $DB_HOST='******'; $DB_USR='****'; $DB_PWD=*****; $DB_SCHEMAS='******'; $DB_CON = mysqli_connect($DB_HOST,$DB_USR,$DB_PWD,$DB_SCHEMAS); //DB connection check function DB_CON_CHECK() { global $DB_CON; if(!$DB_CON){ die("Database connection failed: ". mysqli_error()); } } // display data in table //echo "<p><b>View All</b> | <a href='view-paginated.php?page=1'>View Paginated</a></p>"; // display data in table echo "<table border='1' cellpadding='10'>"; echo "<tr> <th>User Name</th> <th>First Name</th> <th>Last Name</th> <th>Gender</th> <th>Date of Birth</th> <th>Email</th></tr>"; // loop through results of database query, displaying them in the table print "<*****>"; while($row = mysql_fetch_array($result)) { // echo out the contents of each row into a table echo "<tr>"; echo '<td>' . $row['UNAME'] . '</td>'; echo '<td>' . $row['FNAME'] . '</td>'; echo '<td>' . $row['LNAME'] . '</td>'; echo '<td>' . $row['GEN'] . '</td>'; echo '<td>' . $row['DOB'] . '</td>'; echo '<td>' . $row['EMAIL'] . '</td>'; echo '<td><a href="edit.php?id=' . $row['resid'] . '">Edit</a></td>'; echo '<td><a href="delete.php?id=' . $row['resid'] . '">Delete</a></td>'; echo "</tr>"; } // close table> echo "</table>"; ?> PHP: Thanx in advance
You haven't done the actual mysql query and $result is not set. Do this: $result = mysql_query("SELECT * FROM TABLE_NAME WHERE 1"); Amit
I don't think that worked... when I did it, it says [TABLE] [TR] [TH]User Name[/TH] [TH]First Name[/TH] [TH]Last Name[/TH] [TH]Gender[/TH] [TH]Date of Birth[/TH] [TH]Email[/TH] [/TR] [/TABLE] [TABLE="class: xdebug-error"] [TR] [TH="bgcolor: #f57900, colspan: 5, align: left"]( ! ) Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\*******\******\viewrecord.php on line 42[/TH] [/TR] [TR] [TH="bgcolor: #e9b96e, colspan: 5, align: left"]Call Stack[/TH] [/TR] [TR] [TH="bgcolor: #eeeeec, align: center"]#[/TH] [TH="bgcolor: #eeeeec, align: left"]Time[/TH] [TH="bgcolor: #eeeeec, align: left"]Memory[/TH] [TH="bgcolor: #eeeeec, align: left"]Function[/TH] [TH="bgcolor: #eeeeec, align: left"]Location[/TH] [/TR] [TR] [TD="bgcolor: #eeeeec, align: center"]1[/TD] [TD="bgcolor: #eeeeec, align: center"]0.3780[/TD] [TD="bgcolor: #eeeeec, align: right"]375776[/TD] [TD="bgcolor: #eeeeec"]{main}( )[/TD] [TD="bgcolor: #eeeeec"]..\viewrecord.php:0[/TD] [/TR] [TR] [TD="bgcolor: #eeeeec, align: center"]2[/TD] [TD="bgcolor: #eeeeec, align: center"]3.0025[/TD] [TD="bgcolor: #eeeeec, align: right"]389976[/TD] [TD="bgcolor: #eeeeec"]mysql_fetch_array( )[/TD] [TD="bgcolor: #eeeeec"]..\viewrecord.php:42[/TD] [/TR] [/TABLE]
Hello, Please check following code. <?php// Inialize session session_start(); // Retrieve username and password from database according to user's input $DB_HOST='******'; $DB_USR='****'; $DB_PWD=*****; $DB_SCHEMAS='******'; $DB_CON = mysqli_connect($DB_HOST,$DB_USR,$DB_PWD,$DB_SCHEMAS); //DB connection check function DB_CON_CHECK() { global $DB_CON; if(!$DB_CON){ die("Database connection failed: ". mysqli_error()); } } mysql_select_db("myDB"); $result = mysql_query("SELECT * FROM TABLE_NAME"); echo "<table border='1' cellpadding='10'>"; echo "<tr> <th>User Name</th> <th>First Name</th> <th>Last Name</th> <th>Gender</th> <th>Date of Birth</th> <th>Email</th></tr>"; // loop through results of database query, displaying them in the table print "<*****>"; while($row = mysql_fetch_array($result)) { // echo out the contents of each row into a table echo "<tr>"; echo '<td>' . $row['UNAME'] . '</td>'; echo '<td>' . $row['FNAME'] . '</td>'; echo '<td>' . $row['LNAME'] . '</td>'; echo '<td>' . $row['GEN'] . '</td>'; echo '<td>' . $row['DOB'] . '</td>'; echo '<td>' . $row['EMAIL'] . '</td>'; echo '<td><a href="edit.php?id=' . $row['resid'] . '">Edit</a></td>'; echo '<td><a href="delete.php?id=' . $row['resid'] . '">Delete</a></td>'; echo "</tr>"; } // close table> echo "</table>"; ?>
Hello , You are doing something wrong here : >>> // Retrieve username and password from database according to user's input $DB_HOST='******'; $DB_USR='****'; $DB_PWD=*****; $DB_SCHEMAS='******'; $DB_CON=mysqli_connect($DB_HOST,$DB_USR,$DB_PWD,$DB_SCHEMAS); <<<<<<<<< Just connect your data base in this way : $DB_CON = mysql_connect("localhost", "root", "") or die(mysql_error()); //DB connection check function DB_CON_CHECK() { global $DB_CON; if(!$DB_CON){ die("Database connection failed: ". mysqli_error()); } } Every thing will be surely fine. I have tested in this way 100% ok. If you still find any problem , let me know...