[Chugalug] another LAMP problem

Mike Harrison cluon at geeklabs.com
Thu Mar 14 23:12:27 UTC 2013


<?php
$con=mysqli_connect("localhost","dbuser","dbpasswd","dbname");
if (mysqli_connect_errno($con)) { echo "Failed to connect to MySQL: " . mysqli_connect_error() ; } ;
$result = mysqli_query($con, "SELECT uniq,name FROM customers") ;
if(!$result) {
   echo "MySQL Error: " . mysqli_error($con) . "\n";
} else {
   while ( $row = mysqli_fetch_array($result,MYSQLI_ASSOC) ) {
     print $row['uniq'] . ' ' . $row['name'] . " <br>\n" ;
   } ;
}
?>

The slight variation above just worked on my system,

I demand the brackets be in the format as above. Not on their own lines,
but that's a personal religion thing. I can affirm that my beliefs work 
well for me when applied consistently.



============================================================
Mike Harrison   bogon at geeklabs.com  cell: 423.605.6943

On Thu, 14 Mar 2013, Garrett Gaston wrote:

> Having overcome my last LAMP problem I've hit another problem almost immediately. My apache server seems to be working just fine as does php, I'm able to execute phpinfo()
> without a problem. I wrote a little php to query a few lines in a VERY simple MySQL database. When the page loads it's a blank web page, no errors and no results. There are two
> entries in the table that I'M trying to query so I would expect to see two lines outputted as html. The code is below. Any ideas? Note that fname & lname are just variable I
> retrieved from an html form via $_POST.
> 
> // Create connection
> $con=mysqli_connect("localhost","lrngsql","xyz","bank");
> 
> // Check connection
> if (mysqli_connect_errno($con))
>   {
>   echo "Failed to connect to MySQL: " . mysqli_connect_error();
>   }
> 
> $result = mysqli_query($con, "SELECT fname, lname FROM person");
> 
> if(!$result)
> {
>     echo "MySQL Error: " . mysqli_error($con) . "\n";
> }
> 
> else
> {
>     while($row = mysqli_fetch_array($result))
>     {
>         echo $row['fname'] . " " . $row['lname'];
>         echo "<br />";
>     }
> }
> 
>


More information about the Chugalug mailing list