PHP to connect to mysql database for the first time: Errors

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

Post Reply
Snot
Forum Newbie
Posts: 12
Joined: Wed Jun 11, 2008 2:33 pm

PHP to connect to mysql database for the first time: Errors

Post by Snot »

This is my first time working with php and databases and I would like some advice trying to connect them.

This is my database table fields

http://www.tarantuladatabase.com/tf.jpg

This is my field values

http://www.tarantuladatabase.com/fv.jpg

I am using two php files one of them is called connect.php and it only has the information to connect to my database. The other files is called echo.php. The form is at

http://www.tarantuladatabase.com/assets ... earch.html

When I try and connect I am getting this error message

Code: Select all

Warning: include(includes/connect.php) [function.include]: failed to open stream: No such file or directory in /home/e0120590/public_html/tarantuladatabase.com/assets/php/echo.php on line 38
 
Warning: include() [function.include]: Failed opening 'includes/connect.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/e0120590/public_html/tarantuladatabase.com/assets/php/echo.php on line 38
 
Warning: mysql_query() [function.mysql-query]: Access denied for user 'e0120590'@'localhost' (using password: NO) in /home/e0120590/public_html/tarantuladatabase.com/assets/php/echo.php on line 40
 
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/e0120590/public_html/tarantuladatabase.com/assets/php/echo.php on line 40
 
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/e0120590/public_html/tarantuladatabase.com/assets/php/echo.php on line 43
 
Warning: mysql_close(): no MySQL-Link resource supplied in /home/e0120590/public_html/tarantuladatabase.com/assets/php/echo.php on line 48
I am kinda stuck right here so any advice would be greatly appreciated.

Here are the files I'm working with http://www.tarantuladatabase.com/3_Files.zip
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Re: PHP to connect to mysql database for the first time: Errors

Post by Ambush Commander »

I would suggest you start by looking for the includes/connect.php file mentioned in the error messages. Apparently, it doesn't exist, and making it exist (maybe there are docs in the source code about it) will help you out greatly.
Snot
Forum Newbie
Posts: 12
Joined: Wed Jun 11, 2008 2:33 pm

Re: PHP to connect to mysql database for the first time: Errors

Post by Snot »

Thanks so much for the help

This phase of my tarantula database project has really slowed everything down. Learning PHP code is way more difficult than setting up the database.

I am trying to match my php code up with the form found here. http://www.tarantuladatabase.com/assets/pages/search.html The big problem is that I've done so much guess work with the database that I'm not sure if its even set up like I need it to be.

But aside from that I have a php file called connect.php that is working and connecting to my database after my file path issue got in order. I also have a file called echo.php that contains my non working php code.
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/e0120590/public_html/tarantuladatabase.com/assets/php/echo.php on line 43
This is my php code

Code: Select all

<?
include("connect.php");
// now you are connected and can query the database
$request = mysql_query("select field1,field2 from table");
 
// loop through the results with mysql_fetch_array()
while($row = mysql_fetch_array($request)){
  echo $row[0]." / ".$row[1]."<br>\n";
}
 
// don't forget to close the mysql connection
mysql_close();
?>
Its just a copy and paste gig I got off of some php link I was reading. All i changed was the path to my connect.php file and the $results to $request so I expected the errors and now..

I'm just trying to find out if my database has enough information in it to even be search able? http://www.tarantuladatabase.com/fv.jpg and what I need to do to get my php file talking to it?

Any advice or links or anything to point me on the right track would be great. I have been reading and trying to learn php but its really confusing me hehe
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: PHP to connect to mysql database for the first time: Errors

Post by Ollie Saunders »

So what errors are you getting know what that new code?
Snot
Forum Newbie
Posts: 12
Joined: Wed Jun 11, 2008 2:33 pm

Re: PHP to connect to mysql database for the first time: Errors

Post by Snot »

The new code and the error message is in the post above.
1. <?
2. include("connect.php");
3. // now you are connected and can query the database
4. $request = mysql_query("select field1,field2 from table");
5.
6. // loop through the results with mysql_fetch_array()
7. while($row = mysql_fetch_array($request)){
8. echo $row[0]." / ".$row[1]."<br>\n";
9. }
10.
11. // don't forget to close the mysql connection
12. mysql_close();
13. ?>
and the error is here
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/e0120590/public_html/tarantuladatabase.com/assets/php/echo.php on line 43
But like I said I think I'm to the point where I need some php information or some examples on how to tie it into my form unless someone want's to hold my hand with the php for awhile 8)

Everything I have read since I got it to connect to the database has went right over my head :cry:
User avatar
lonelywolf
Forum Commoner
Posts: 28
Joined: Tue Jun 10, 2008 6:15 am

Re: PHP to connect to mysql database for the first time: Errors

Post by lonelywolf »

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource...
If you get this warning, maybe the problem is your select query.
$request = mysql_query("select field1,field2 from table");
You can check above statement.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: PHP to connect to mysql database for the first time: Errors

Post by Ollie Saunders »

Show the contents of connect.php, censor your db pass before you post it though.
Snot
Forum Newbie
Posts: 12
Joined: Wed Jun 11, 2008 2:33 pm

Re: PHP to connect to mysql database for the first time: Errors

Post by Snot »

* 1 / Arboreal
2 / Terrestrial
3 / Fossorial
4 /
I made this happn lol but not sure what it means


and here is my new code in echo.php

Code: Select all

<?
include("connect.php");
// now you are connected and can query the database
$query = "SELECT * FROM `common_traits` `habitat``humidity``speed``size``location``aggression`";
$request = mysql_query($query);
if($request == false)
{
   user_error(mysql_error() . "<br />\n$query");
}
 
// loop through the results with mysql_fetch_array()
while($row = mysql_fetch_array($request)){
  echo $row[0]." / ".$row[1]."<br>\n";
}
 
// don't forget to close the mysql connection
mysql_close();
?>
I am reading stuff and making some progress but it's just not added up. Nothing I have read tells me how to make my from do work.

I copyed the code off of a page I was reading that tells me how to code php i'm kinda picking stuff up bit by bit so i'm really thankful for any help you can give me. I think I learn code better when I can see an example of what should be happening.

oh here is the code from connect.php

Code: Select all

<?
/*--------- DATABASE CONNECTION INFO---------*/
$hostname="localhost";
$mysql_login="e0120590_tester";
$mysql_password="*****";
$database="e0120590_tarantuladatabase";
 
// connect to the database server
if (!($db = mysql_pconnect($hostname, $mysql_login , $mysql_password))){
  die("Can't connect to database server.");    
}else{
  // select a database
    if (!(mysql_select_db("$database",$db))){
      die("Can't connect to database.");
    }
}
?>
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: PHP to connect to mysql database for the first time: Errors

Post by Ollie Saunders »

Ok this is looking pretty good.

Try changing:

Code: Select all

$query = "SELECT * FROM `common_traits` `habitat``humidity``speed``size``location``aggression`";
to:

Code: Select all

$query = "SELECT * FROM `common_traits`";
Snot
Forum Newbie
Posts: 12
Joined: Wed Jun 11, 2008 2:33 pm

Re: PHP to connect to mysql database for the first time: Errors

Post by Snot »

Post Reply