...

View Full Version : PHP MYSQL SELECT Handling problems



loopsnhoops
04-25-2012, 06:29 AM
Hi,

I have been trying to display my data from two columns onto a table in html. I am using myhosting.com and I am new to their system. I had just started thinking I had gotten a grasp on how to use their PHPMyAdmin and MYSQL system but then I got an odd error. Can you please tell me if this is their system's fault or the result of my bad coding?

Thanks and offered solutions will result in many thanks!

Here is the code:


<?php

$Server="xxxx";
$User="xxxx";
$Password="xxxx";
$Database="xxxx";

$connection = mysql_connect($Server, $User, $Password);
if(!$connection){
die("Couldn't Connect" . mysql_error());
}
echo "Connection Working";

mysql_select_db($Database, $connection);

$query = "SELECT * FROM Test";

$table = mysql_query($query,$connection);

echo "<table border='1'>";
echo "<tr> <th>id</th> <th>name</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $query )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo $row['id'];
echo "</td><td>";
echo $row['name'];
echo "</td></tr>";
}

echo "</table>";

?>

and here is the error:

Connection Working Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /usr/local/pem/vhosts/113282/webspace/httpdocs/show.php on line 23
id name
Resource id #3

abduraooft
04-25-2012, 08:46 AM
Change
$table = mysql_query($query,$connection); to

$table = mysql_query($query,$connection) or die(mysql_error());



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum