Jump to content

[SOLVED] Database Not Displaying... Noob


savagenoob

Recommended Posts

I am having a hell of a time getting my MySql table to display...

Here is the code...

 

<?php 

// load the configuration file. 

mysql_connect("localhost","root","xxxxxx"); 

//select which database you want to edit
mysql_select_db("database"); 
        
        $result = mysql_query("SELECT * FROM clients ORDER BY ID",$connect); 

        
        while($myrow = mysql_fetch_assoc($result)) 
             {//begin of loop 

               //now print the results: 
               echo "<b>Policy Number: "; 
               echo $myrow['PolicyNumber']; 
               echo "<b>First Name: "; 
               echo $myrow['First_Name']; 
               echo "<b>Last Name: "; 
               echo $myrow['Last_Name']; 

               echo "<br><a href=\"edit.php?PolicyNumber=$myrow[PolicyNumber]\">Edit</a> 
                 || <a href=\"delete.php?PolicyNumber=$myrow[PolicyNumber]\">Delete</a><br><hr>";

             }//end of loop 

?> 

 

anyone?

Link to comment
https://forums.phpfreaks.com/topic/137758-solved-database-not-displaying-noob/
Share on other sites

You need to put in place some error handling.

 

<?php 

// load the configuration file. 

mysql_connect("localhost","root","xxxxxx"); 

//select which database you want to edit
mysql_select_db("database"); 
        
if ($result = mysql_query("SELECT * FROM clients ORDER BY ID",$connect)) {
  if (mysql_num_rows($result)) { 
    while ($myrow = mysql_fetch_assoc($result)) {//begin of loop 
      //now print the results: 
      echo "<b>Policy Number: "; 
      echo $myrow['PolicyNumber']; 
      echo "<b>First Name: "; 
      echo $myrow['First_Name']; 
      echo "<b>Last Name: "; 
      echo $myrow['Last_Name']; 

      echo "<br><a href=\"edit.php?PolicyNumber={$myrow['PolicyNumber']}\">Edit</a> 
                 || <a href=\"delete.php?PolicyNumber={$myrow['PolicyNumber']}\">Delete</a><br><hr>";

    }//end of loop
  } else {
    echo "No results found";
  }
} else {
  echo mysql_error();
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.