Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 18th, 2003, 12:48 PM
Registered User
Points: 10, Level: 1
Points: 10, Level: 1 Points: 10, Level: 1 Points: 10, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Karlstad, Värmland, Sweden.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to SqUaRe48 Send a message via MSN to SqUaRe48
Default Problem..

Hi there!
I have problems getting data out of the db. Here's my code:

$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);
$result = mysql_query("SELECT * FROM employees",$db);

$varden = mysql_fetch_array($result,MYSQL_ASSOC)
?>
<?=$varden['first'];?>
<?=$varden['last'];?>
<?=$varden['address'];?>
<?=$varden['position'];?>
<?
mysql_close();
?>

It's telling me:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\inetpub\wwwroot\afab\hello.php on line 27

What have I done wrong?

Best regards,
Martin Johansson
+46 70 300 33 20
Squaremedia HB
martin@cdos.org
Reply With Quote
  #2 (permalink)  
Old June 26th, 2003, 05:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by SqUaRe48

What have I done wrong?
I'd guess it's because you haven't specified root's password in your connection. I dare say the database is refusing connection as a result, so none of the remaining work gets done. You really ought to use "or die()" at each stage of the connection operation, to output a message, should it fail.

Dan
Reply With Quote
  #3 (permalink)  
Old July 5th, 2003, 07:44 PM
Registered User
 
Join Date: Jul 2003
Location: , , Canada.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you must feed function 3 properties. if password is empty then use "".

Reply With Quote
  #4 (permalink)  
Old July 7th, 2003, 02:27 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Daniel Walker
I'd guess it's because you haven't specified root's password in your connection. I dare say the database is refusing connection as a result, so none of the remaining work gets done. You really ought to use "or die()" at each stage of the connection operation, to output a message, should it fail.
This is a good approach for developing and testing your site, but I'd never use "or die(...)" in a live site. If there's a problem, it's much more user-friendly to redirect the user to some error page that says "We are experiencing problems with our database. The system administrator has been notified, please try your request again later."


Quote:
quote:Originally posted by jae_green
 you must feed function 3 properties. if password is empty then use "".
This is also technically incorrect, since the default value for the password param is the empty string (blank password). I'd be surprised if the first of the following function calls works and the other doesn't:

Code:
$conn = mysql_connect("localhost", "root")
            or die('no password failed');
$conn = mysql_connect("localhost", "root", "")
            or die('blank password failed');

Take care,

Nik
http://www.bigaction.org/
Reply With Quote
  #5 (permalink)  
Old September 18th, 2003, 04:39 PM
Registered User
 
Join Date: Sep 2003
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just for added emphasis... even though the problem is old by now.. adding in the following helps in debugging when a script has multiple queries..

$sql8 = "select * from tbl"; //sql statement
$RS8 = MYSQL_QUERY($sql8) or die("Invalid query 8: " . mysql_error());

the mysql_error() is so very helpful

Rob



Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off




All times are GMT -4. The time now is 05:23 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.