Free Web Hosting Forum
(#1 (permalink))
Old
Junior Member
Tarman is on a distinguished road
 
Posts: 6
Join Date: Jul 2008
Default Database connect problem - 07-16-2008, 08:05 AM

I keep getting this error when trying to connect to my database any assistance would be helpful.

This is the database connect function
Code:
<?
function database_connect()
{
$dbhost     = "mysql1.000webhost.com";					// Database host
$dbname     = "a1863106_items";			// Database name
$dbusername = "a1863106_tar";			// Database user name
$dbuserpw   = "hidden";						// Database password

mysql_pconnect($dbhost, $dbusername, $dbuserpw);  	//Connects to the mysql database area
$result = mysql_select_db($dbname);   //Connects to the specific database and saves the result as result.
if (!$result)
	return false;  //Connected
else
	return true;  //not connected
}
?>

This is the webpage
Code:
<?
// start the session 
session_start();
ob_start();
include ('includes/allfunctions.php');
header("Cache-control: private"); //IE 6 Fix 
?>
<title>DDO Items</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<body>
<table width="100%" border="1" cellspacing="1" cellpadding="1">
  <tr> 
    <? include ('includes/header.php');
	?>
  </tr>
  <tr> 
    <td height="500">
<?
//Connect to the database all fields are good so far				
	database_connect();
	$sql = "SELECT * FROM 'DDO Items' WHERE 1";
	   while($row = mysql_fetch_array($result)) {
    	    echo '<tr>';
        	echo '<td>'.$row['ItemName'].'</td>';
        	echo '</tr>';
}
?>
	</td>
  </tr>
    <td align="center" valign="bottom"><? include ('includes/footer.php')?>
   </td>
   </table>
</html>
This is the error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a1863106/public_html/gloves.php on line 22

Line 22 from above to help find it easier is:
PHP Code:
while($row mysql_fetch_array($result)) { 
Reply With Quote
(#2 (permalink))
Old
Red-X's Avatar
Senior Member
Red-X is on a distinguished road
 
Posts: 365
Join Date: Jun 2008
Send a message via AIM to Red-X
Default 07-16-2008, 08:25 AM

Try this <?php not <?. I think that's the error hope that helps
Reply With Quote
(#3 (permalink))
Old
Junior Member
Tarman is on a distinguished road
 
Posts: 6
Join Date: Jul 2008
Default 07-16-2008, 02:22 PM

Sorry still no luck any other possible suggestions?
Reply With Quote
(#4 (permalink))
Old
Administrator
admin has disabled reputation
 
Posts: 421
Join Date: Apr 2008
Default 07-16-2008, 03:30 PM

can you enter database by phpmyadmin? If yes - its all fine with database and problem somewhere with script coding.


Aurimas,
Head Admin & CEO
www.000webhost.com
Reply With Quote
(#5 (permalink))
Old
Junior Member
Tarman is on a distinguished road
 
Posts: 6
Join Date: Jul 2008
Default 07-17-2008, 01:03 AM

Yes I can enter PHP my admin....I understand the database is good I am not sure what I am missing in my PHP.

Once again here is my codeing
Code:
<?
//Connect to the database all fields are good so far				
	database_connect();
	$sql = "SELECT * FROM 'DDO Items' WHERE 1";
	$result = mysql_query($sql);
	   while($row = mysql_fetch_array($result)) {
    	    echo '<tr>';
        	echo '<td>'.$row['ItemName'].'</td>';
        	echo '</tr>';
}
?>
Reply With Quote
(#6 (permalink))
Old
Red-X's Avatar
Senior Member
Red-X is on a distinguished road
 
Posts: 365
Join Date: Jun 2008
Send a message via AIM to Red-X
Default 07-17-2008, 01:11 AM

Try this..

PHP Code:
echo "<td>" $row["ItemName"] . "</td>"
Reply With Quote
(#7 (permalink))
Old
Mr.Whisper's Avatar
Member
Mr.Whisper is on a distinguished road
 
Posts: 67
Join Date: May 2008
Send a message via MSN to Mr.Whisper
Default 07-18-2008, 07:39 AM

I usually use this

Code:
<?
$sql = "SELECT * FROM my_table WHERE condition=condition";
$query = mysql_query($sql);
$rows = mysql_num_rows($query);
$i = 0;
while($i < $rows){
	$result = mysql_fetch_array($query);
	echo $rows['field'];
	$i++;
}
?>
so, at first you was lost query function(you forgot to defing $result) and then on your new code. it still show warning? so i think my code will work fine.

i always use basic syntax. i tried to fix problem that occur with advance syntax


OSS-Zone

We present Freeware & Opensource to Everyone!
Reply With Quote
(#8 (permalink))
Old
Junior Member
Tarman is on a distinguished road
 
Posts: 6
Join Date: Jul 2008
Default 07-18-2008, 02:30 PM

Thanks for all the help and suggestions. I got it to work Here is the code if it could help somebody else.

Code:
<?
//Connect to the database all fields are good so far

$sql = 'SELECT * FROM `a1863106_items`.`DDO Items` WHERE `ItemType` LIKE CONVERT(_utf8 \'%Armor%\' USING latin1) COLLATE latin1_general_ci'; 		
	database_connect();
	$result = mysql_query($sql) or die(mysql_error());
	   while($row = mysql_fetch_array($result)) {
			echo '<tr>';
        	echo '<td>'.$row['ItemName'].'</td>';
			echo '<td>'.$row['ItemDescription'].'</td>';
			echo '<td>'.$row['Type'].'</td>';
			echo '<td>'.$row['QuestName'].'</td>';
			echo '<td>'.$row['lvl'].'</td>';		
			echo '<td>'.$row['Notes'].'</td>';
        	echo '</tr>';
}

$sql = 'SELECT * FROM `a1863106_items`.`DDO Items` WHERE `ItemType` LIKE CONVERT(_utf8 \'%Docent%\' USING latin1) COLLATE latin1_general_ci'; 		
	database_connect();
	$result = mysql_query($sql) or die(mysql_error());
	   while($row = mysql_fetch_array($result)) {
			echo '<tr>';
        	echo '<td>'.$row['ItemName'].'</td>';
			echo '<td>'.$row['ItemDescription'].'</td>';
			echo '<td>'.$row['Type'].'</td>';
			echo '<td>'.$row['QuestName'].'</td>';
			echo '<td>'.$row['lvl'].'</td>';		
			echo '<td>'.$row['Notes'].'</td>';
        	echo '</tr>';
}


?>
Reply With Quote
(#9 (permalink))
Old
Junior Member
KazanDaemon is on a distinguished road
 
Posts: 22
Join Date: Jul 2008
Default 08-20-2008, 05:21 PM

Quote:
Originally Posted by Tarman View Post
Yes I can enter PHP my admin....I understand the database is good I am not sure what I am missing in my PHP.

Once again here is my codeing
Code:
<?
//Connect to the database all fields are good so far				
	database_connect();
	$sql = "SELECT * FROM 'DDO Items' WHERE 1";
	$result = mysql_query($sql);
	   while($row = mysql_fetch_array($result)) {
    	    echo '<tr>';
        	echo '<td>'.$row['ItemName'].'</td>';
        	echo '</tr>';
}
?>
try ...FROM `DDO Items` WHERE...
database field names MUST BE quoted by (`) char, not (')
Reply With Quote
(#10 (permalink))
Old
YaThisHostRox's Avatar
Senior Member
YaThisHostRox is on a distinguished road
 
Posts: 346
Join Date: Jul 2008
Location: In a place where I don't answer IMs
Send a message via AIM to YaThisHostRox Send a message via MSN to YaThisHostRox Send a message via Yahoo to YaThisHostRox Send a message via Skype™ to YaThisHostRox
Default 08-24-2008, 10:43 PM

Use ` not '. I make that mistake muchos.
Reply With Quote
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.6.9
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0
vBulletin Skin developed by: vBStyles.com