Forum Moderators: coopster

Message Too Old, No Replies

MySql error - need help please

table doesn't exist? but it does...

         

canecorsos

3:32 pm on Jul 15, 2004 (gmt 0)

10+ Year Member



Hi everyone, In my script below I'm getting an error.. The database is testdb user and password are also testdb the table name is user

<?php
$db = mysql_connect("localhost","testdb","testdb");
mysql_select_db ("testdb");
$result = mysql_query("SELECT id, name FROM user") or die ('Queryproblem:' . mysql_error());
if (mysql_num_rows($result) >= 1){
while ($rows = mysql_fetch_row($result)) {
echo "<tr><td><a href='$rows[2]'>$rows[1]</a></td></tr>";
}
} else {
echo 'No records returned';
}
?>

returns Queryproblem:Table 'testdb.user' doesn't exist

why is it bringing in the testdb.user part when it should only be looking for table user

dreamcatcher

4:03 pm on Jul 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World. My guess is you have the database named wrong:

mysql_select_db ("testdb");

Are you sure your database is named testdb? Its adding the .user because thats what its trying to find.

Double check your syntax:

$db = mysql_connect("localhost","username","password");
mysql_select_db ("database_name");

canecorsos

7:22 pm on Jul 15, 2004 (gmt 0)

10+ Year Member



Yeah.. I know that it is correct as far as database name is testdb and the table is user and the username and password are correct

in this script
<?php
$db = mysql_connect("localhost","testdb","testdb");
mysql_select_db ("testdb");

if (!$db) {
die('Could not connect');
}

?>

it returns nothing - which means it connected with testdb? Is there a way to make it return something so that I know that it did connect? And how about connecting to the table user and having it return something like "YES WE ARE CONNECTED"?

Thanks for your help

[edited by: jatar_k at 7:34 pm (utc) on July 15, 2004]
[edit reason] no personal urls thanks [/edit]

dreamcatcher

9:11 pm on Jul 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try the following:


$db = mysql_connect("localhost","testdb","testdb");
mysql_select_db ("testdb", $db);

To check what the exact error is, simply use mysql_error(). I see you have used this already.


if (!$db)
{
die(mysql_error());
}