CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   PHP MYSQL SELECT Handling problems (http://www.codingforums.com/showthread.php?t=258559)

loopsnhoops 04-25-2012 05:29 AM

PHP MYSQL SELECT Handling problems
 
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 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 07:46 AM

Change
PHP Code:

$table mysql_query($query,$connection); 

to
PHP Code:

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



All times are GMT +1. The time now is 08:25 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.