Taking info forum database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

phelpsa
Forum Commoner
Posts: 48
Joined: Thu Feb 17, 2005 1:05 pm

Taking info forum database

Post by phelpsa »

What is wrong with this script?

Code: Select all

<?php
$location = "localhost";
$username = "";
$password = "";
$database = "xmb_members";

$conn = mysql_connect("$location","$username","$password");
if (!$conn) die ("Could not connect MySQL");
mysql_select_db($database,$conn) or die ("Could not open database");

$query = "SELECT * FROM users";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
while($row = mysql_fetch_array($result))&#123;
    echo "Members links: $column&#1111;site]";

?>
Sorry if it's something obvious, but I'm new to PHP.

Adam


feyd | :roll:
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

you started the while loop with a { but you never ended it, put a } on the last line. also $column dosn't exist, but $row does. so it would be $row['site']
phelpsa
Forum Commoner
Posts: 48
Joined: Thu Feb 17, 2005 1:05 pm

Post by phelpsa »

I have fixed those and there is another error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/www/hillclim/forum/links.php on line 13

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/www/hillclim/forum/links.php on line 14

Please be patient, I'm a newbie.

Adam
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

are u sure table users exists? does it have any data in it?
phelpsa
Forum Commoner
Posts: 48
Joined: Thu Feb 17, 2005 1:05 pm

Post by phelpsa »

Yes, it does exist and there is data in it.

Adam
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

try
$query = "SELECT * FROM users ORDER BY site DESC";
or somthing to that effect.
phelpsa
Forum Commoner
Posts: 48
Joined: Thu Feb 17, 2005 1:05 pm

Post by phelpsa »

Okay, be very patient with me.

It now says: Could not open database

:? :? :? :? :? :? :?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

either your database name is wrong or your username/pass dosn't have access to that db
phelpsa
Forum Commoner
Posts: 48
Joined: Thu Feb 17, 2005 1:05 pm

Post by phelpsa »

shiznatix wrote:either your database name is wrong or your username/pass dosn't have access to that db
OOOOOPPPPPPSSSSS

I made a stupid mistake.

I put the table name instead of the database name :oops: :oops: :oops:

It's still coming up with the same error though.

Here's what it looks like at the moment:

Code: Select all

<?php
$location = "localhost";
$username = "****";
$password = "****";
$database = "hillclim";

$conn = mysql_connect("$location","$username","$password");
if (!$conn) die ("Could not connect MySQL");
mysql_select_db($database,$conn) or die ("Could not open database");

$query = "SELECT * FROM xmb_members";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
while($row = mysql_fetch_array($result))&#123;
    echo "Members links: $row&#1111;site]";
&#125;
?>
Please help.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

please use

Code: Select all

tags while the

Code: Select all

tags are down, not [quote]
phelpsa
Forum Commoner
Posts: 48
Joined: Thu Feb 17, 2005 1:05 pm

Post by phelpsa »

feyd wrote:please use

Code: Select all

tags while the

Code: Select all

tags are down, not [quote][/quote]

Sorry
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what does this show? Maybe it's the wrong database name..

Code: Select all

$conn = mysql_connect($location,$username,$password) or die(mysql_error());

$query = mysql_query('SHOW DATABASES');
$output = '<pre>';
while($db = mysql_fetch_assoc($query))
  $output .= var_export($db, true) . "\n";
echo $output .'</pre>';
note: use your previous $location, etc for this.
phelpsa
Forum Commoner
Posts: 48
Joined: Thu Feb 17, 2005 1:05 pm

Post by phelpsa »

Sorry for my ignorance, but where do I put it?

Adam
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

create a seperate page with your connection information and the code posted. Run it, and make sure the database names are what you think they are.
phelpsa
Forum Commoner
Posts: 48
Joined: Thu Feb 17, 2005 1:05 pm

Post by phelpsa »

Ok, basically, it came up with loads and loads oof these:

array (
'Database' => 'Acrapmad',
)
array (
'Database' => 'Ap30euMit',
)
array (
'Database' => 'Aportbyt',
)
array (
'Database' => 'Atudentn',
)
array (
'Database' => 'Awdataba',

Adam
Post Reply