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
Old 02-17-2005, 10:44 PM php mysql connection
Novice Talker

Posts: 7
Trades: 0
I am learning php with my sql and I created on my server a dummy database with 3 tables.

I am trying to connect via this code and to retrieve results from my table shops :

<?php
$db = mysql_connect("MySQLHost", "u70150339", "260052");
mysql_select_db("d60146517", $db);
$query = "SELECT * FROM shops";
$result = mysql_query($query);
while ($record = mysql_fetch_row($result)) {
for ($i=0; $i<count($record); $i++) {
echo $record[$i]."<br>";
}
echo "<br>";
}

?>

Did I forget anything? That's the answer I get:
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /mnt/web_h/d26/s38/b01e75e9/www/php/Connect.php on line 15
nijinsky is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-17-2005, 11:39 PM
webcord's Avatar
Average Talker

Posts: 23
Trades: 0
Use "or die" to catch errors untill your comfortable


$db = mysql_connect("MySQLHost", "u70150339", "260052") or die("<hr>could not connect: <br>".mysql_error()."<hr>");
mysql_select_db("d60146517", $db) or die("<hr>Invalid database name: <br>".mysql_error()."<hr>");

$query = "SELECT * FROM shops";
$result = mysql_query($query) or die("<hr>Invalid query: <br>" . mysql_error()."<hr>");
__________________

Please login or register to view this content. Registration is FREE

-------------------------------------------------------------------

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
webcord is offline
Reply With Quote
View Public Profile
 
Old 02-18-2005, 06:09 AM
Gaffer Sports's Avatar
Ultra Talker

Posts: 397
Name: Steve
Location: Scotland
Trades: 1
Code:
<?php
$db = mysql_connect("MySQLHost", "u70150339", "260052");
mysql_select_db("d60146517", $db);
$query = "SELECT * FROM shops";
$result = mysql_query($query);
while ($record = mysql_fetch_row($result)) {
for ($i=0; $i<count($record); $i++) {
echo $record[$i]."<br>";
}
echo "<br>";
}

?>
There are a couple of errors there, in my opinion. Try this:

Code:
<?php

$db = mysql_connect("MySQLHost", "u70150339", "260052");
mysql_select_db("d60146517", $db);

$query = "SELECT * FROM shops";

$result = mysql_query($query);
$i=0;
while ($record = mysql_fetch_row($result))
 
{
   while ( $i<count($record))
   {
     echo $record[$i]."<br>";
     echo "<br>";
     $i++;
   }
}

?>
Steve.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
Gaffer Sports is offline
Reply With Quote
View Public Profile Visit Gaffer Sports's homepage!
 
Old 03-06-2005, 09:34 PM
Novice Talker

Posts: 7
Trades: 0
Thanks for your replies, it did work finally.....Thank you
__________________
Cecile
http://www.designer-quality.com
nijinsky is offline
Reply With Quote
View Public Profile
 
Old 03-07-2005, 07:42 PM
Novice Talker

Posts: 8
Trades: 0
and one notification..
it's better that you change your information below (such as username-password)

$db = mysql_connect("MySQLHost", "u70150339", "260052");
mysql_select_db("d60146517", $db);
__________________
Myonlineusers.com -
Please login or register to view this content. Registration is FREE

Free online counter for your site (For ex. 54 users online)
skorbord is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to php mysql connection
 

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 0.16812 seconds with 12 queries