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
Post
by phelpsa » Thu Feb 17, 2005 1:48 pm
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)){
echo "Members links: $columnїsite]";
?>
Sorry if it's something obvious, but I'm new to PHP.
Adam
feyd |
shiznatix
DevNet Master
Posts: 2745 Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:
Post
by shiznatix » Thu Feb 17, 2005 1:53 pm
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 » Thu Feb 17, 2005 2:06 pm
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
shiznatix
DevNet Master
Posts: 2745 Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:
Post
by shiznatix » Thu Feb 17, 2005 2:13 pm
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 » Thu Feb 17, 2005 2:15 pm
Yes, it does exist and there is data in it.
Adam
shiznatix
DevNet Master
Posts: 2745 Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:
Post
by shiznatix » Thu Feb 17, 2005 3:07 pm
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 » Thu Feb 17, 2005 3:20 pm
shiznatix
DevNet Master
Posts: 2745 Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:
Post
by shiznatix » Thu Feb 17, 2005 3:22 pm
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 » Thu Feb 17, 2005 3:32 pm
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
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)){
echo "Members links: $rowїsite]";
}
?>
Please help.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Feb 17, 2005 3:37 pm
phelpsa
Forum Commoner
Posts: 48 Joined: Thu Feb 17, 2005 1:05 pm
Post
by phelpsa » Thu Feb 17, 2005 3:41 pm
feyd wrote: please use
Code: Select all
tags are down, not [quote][/quote]
Sorry
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Feb 17, 2005 3:46 pm
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 » Thu Feb 17, 2005 3:57 pm
Sorry for my ignorance, but where do I put it?
Adam
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Feb 17, 2005 3:58 pm
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 » Thu Feb 17, 2005 4:01 pm
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