Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP connecting to mysql database for the first time: Errors
Old 06-12-2008, 05:15 PM PHP connecting to mysql database for the first time: Errors
Snot's Avatar
Super Talker

Posts: 132
Name: Chase
Trades: 0
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/***...es/search.html

When I try and connect I am getting this error message

Code:
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.

I know its just bad php coding on my part but i'm not sure where. Is my connect.php file working like it should?

Here are the files I'm working with http://www.tarantuladatabase.com/3_Files.zip
__________________

Please login or register to view this content. Registration is FREE
Snot is offline
Reply With Quote
View Public Profile Visit Snot's homepage!
 
 
Register now for full access!
Old 06-12-2008, 05:33 PM Re: PHP connecting to mysql database for the first time: Errors
choskins102's Avatar
Super Talker

Posts: 137
Name: Casey
Trades: 3
Can we see the code that you are using. It looks like the username/password combo is not correct for your database.
choskins102 is offline
Reply With Quote
View Public Profile
 
Old 06-12-2008, 05:53 PM Re: PHP connecting to mysql database for the first time: Errors
Snot's Avatar
Super Talker

Posts: 132
Name: Chase
Trades: 0
I am using the user name tester and the password forum.
__________________

Please login or register to view this content. Registration is FREE
Snot is offline
Reply With Quote
View Public Profile Visit Snot's homepage!
 
Old 06-12-2008, 05:59 PM Re: PHP connecting to mysql database for the first time: Errors
Snot's Avatar
Super Talker

Posts: 132
Name: Chase
Trades: 0
It was the file path.

Now I have a new error message.

Well I think from here the problems are in my echo.php file.


Quote:
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
__________________

Please login or register to view this content. Registration is FREE
Snot is offline
Reply With Quote
View Public Profile Visit Snot's homepage!
 
Old 06-12-2008, 06:25 PM Re: PHP connecting to mysql database for the first time: Errors
PeachyJuice's Avatar
Super Talker

Posts: 116
Name: Michele T.
Location: Ny, Ny
Trades: 1
That does seem to be your problem. If you post your PHP code then we can actually give you some helpful help =)
__________________
Freelance web+graphic designer and PHP developer.

Please login or register to view this content. Registration is FREE
PeachyJuice is offline
Reply With Quote
View Public Profile
 
Old 06-12-2008, 06:43 PM Re: PHP connecting to mysql database for the first time: Errors
Snot's Avatar
Super Talker

Posts: 132
Name: Chase
Trades: 0
I really haven't learned what goes in the echo.php file yet so I really don't have anything it. I was mostly just trying to make sure that the connect.php file was working.

Don't get me wrong I would love to here your advice on what my next step should be. I have a feeling its a lot of php code reading but if you have any examples that I could see that would be very helpful.

Quote:
<?
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($result)){
echo $row[0]." / ".$row[1]."<br>\n";
}

// don't forget to close the mysql connection
mysql_close();
?>
__________________

Please login or register to view this content. Registration is FREE
Snot is offline
Reply With Quote
View Public Profile Visit Snot's homepage!
 
Old 06-12-2008, 09:20 PM Re: PHP connecting to mysql database for the first time: Errors
choskins102's Avatar
Super Talker

Posts: 137
Name: Casey
Trades: 3
Well, the problem seems to be your while loop...you have $result when it should be $request.

Code:
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();
?>
choskins102 is offline
Reply With Quote
View Public Profile
 
Old 06-12-2008, 10:49 PM Re: PHP connecting to mysql database for the first time: Errors
Snot's Avatar
Super Talker

Posts: 132
Name: Chase
Trades: 0
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/***...es/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.

Quote:
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:
<?
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
__________________

Please login or register to view this content. Registration is FREE
Snot is offline
Reply With Quote
View Public Profile Visit Snot's homepage!
 
Old 06-12-2008, 11:20 PM Re: PHP connecting to mysql database for the first time: Errors
choskins102's Avatar
Super Talker

Posts: 137
Name: Casey
Trades: 3
It doesn't matter about the size of the table. 1 result or 1000 results, you can still search for specific results and display them. I would also suggest some type of message if the results equal 0.

Code:
$count = mysql_num_rows($request);
if ($count == 0)
{
echo "There are no results to display. Try your search again.";
}
choskins102 is offline
Reply With Quote
View Public Profile
 
Old 06-13-2008, 12:03 AM Re: PHP connecting to mysql database for the first time: Errors
Snot's Avatar
Super Talker

Posts: 132
Name: Chase
Trades: 0
Quote:
* 1 / Arboreal
2 / Terrestrial
3 / Fossorial
4 /
I made this happen lol but not sure what it means


and here is my new code

Code:
<?
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();
?>
Where do I put that code?

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.
__________________

Please login or register to view this content. Registration is FREE
Snot is offline
Reply With Quote
View Public Profile Visit Snot's homepage!
 
Old 06-13-2008, 12:28 AM Re: PHP connecting to mysql database for the first time: Errors
choskins102's Avatar
Super Talker

Posts: 137
Name: Casey
Trades: 3
Try this:

Code:
<?
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");
}
// Count rows
$count = mysql_num_rows($request);
if ($count == 0)
{
echo "There are no results to display.";
}
// loop through the results with mysql_fetch_array()
while($row = mysql_fetch_array($request)){
  echo $row['fieldname']." / ".$row['fieldname]."<br>\n";
}

// don't forget to close the mysql connection
mysql_close();
?>
The count function will count the number of row and if 0 is found, it will display a message. Also, I have adjusted the code that displays your results. I use this because it is easier to know exactly which rows are being displayed. Just change it from fieldname to your actually name (ie. habitat, humidity, etc.)

The $count variable can also be used to display the number of results that were found, if you want to go that route.

Code:
echo "There were ".$count."results found.";

Last edited by choskins102; 06-13-2008 at 12:33 AM..
choskins102 is offline
Reply With Quote
View Public Profile
 
Old 06-13-2008, 01:02 AM Re: PHP connecting to mysql database for the first time: Errors
Snot's Avatar
Super Talker

Posts: 132
Name: Chase
Trades: 0
I think i got it??? I think it got it http://www.tarantuladatabase.com/***...es/search.html
__________________

Please login or register to view this content. Registration is FREE
Snot is offline
Reply With Quote
View Public Profile Visit Snot's homepage!
 
Reply     « Reply to PHP connecting to mysql database for the first time: Errors
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.32497 seconds with 12 queries