Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-25-2012, 05:29 AM   PM User | #1
loopsnhoops
New Coder

 
Join Date: Aug 2011
Posts: 24
Thanks: 6
Thanked 0 Times in 0 Posts
loopsnhoops is an unknown quantity at this point
Unhappy 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
loopsnhoops is offline   Reply With Quote
Old 04-25-2012, 07:46 AM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Change
PHP Code:
$table mysql_query($query,$connection); 
to
PHP Code:
$table mysql_query($query,$connection) or die(mysql_error()); 
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Reply

Bookmarks

Tags
error, mysql, php, select, table

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:44 AM.


Advertisement
Log in to turn off these ads.