Click to See Complete Forum and Search --> : [RESOLVED] T_DNUMBER error in php/sql combi???
sturz001
07-18-2008, 11:13 AM
hey folks!
I am trying to get records from a sql database in a php page. I want to display 2 fields & their values on the page as a table.
Unfortuantly, I am a newbie at server-side stuff and would like some help.
I have had my go but am getting ugly errors!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Our List of Jokes</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<?
$username="a9362702_admin";
$password="PASSWORD HERE";
$database="a9362702_games";
mysql_connect(sql1.**********.com,$username,$password);
mysql_select_db($database);
$query="SELECT * FROM tablename";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
?>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Game Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">Game URL</font></th>
</tr>
<?
$i=0;
while ($i < $num) {
$field1-name=mysql_result($result,$i,"gname");
$field2-name=mysql_result($result,$i,"gurl");
?>
<tr>
<td><font face="Arial, Helvetica, sans-serif"><? echo $field1-name; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $field2-name; ?></font></td>
</tr>
<?
$i++;
}
echo "</table>";
</body>
</html>
This is the error I am getting:
Parse error: syntax error, unexpected T_DNUMBER in /home/a9362702/public_html/comped2.php on line 15
comped2.php is the 1st code i gave you. It is online at
This place (http://thelinker.net63.net/comped2.php)
NogDog
07-18-2008, 11:30 AM
You need to quote the host name in the mysql_connect() function call.
sturz001
07-18-2008, 11:34 AM
Wow, that worked BUT i now have another error
Parse error: syntax error, unexpected '=' in /home/a9362702/public_html/comped2.php on line 34
ellisgl
07-18-2008, 12:54 PM
Lines 34 and 35:
$field1-name=mysql_result($result,$i,"gname");
$field2-name=mysql_result($result,$i,"gurl");
should be:
$field1_name=mysql_result($result,$i,"gname");
$field2_name=mysql_result($result,$i,"gurl");
you should not use "-" in a variable name since that would make PHP think you are trying to subtract a constant from a variable.
sturz001
07-18-2008, 01:14 PM
you should not use "-" in a variable name since that would make PHP think you are trying to subtract a constant from a variable.
Thanks - I guess I should read the W3C standards First!
Now have lots of errors - this is becoming a pain in the *@##
PHP Error Message
Warning: mysql_connect() [function.mysql-connect]: Host '66.197.160.197' is not allowed to connect to this MySQL server in /home/a9362702/public_html/comped2.php on line 15
PHP Error Message
Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'nobody'@'localhost' (using password: NO) in /home/a9362702/public_html/comped2.php on line 16
Free Web Hosting
Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/a9362702/public_html/comped2.php on line 16
PHP Error Message
Warning: mysql_query() [function.mysql-query]: Access denied for user 'nobody'@'localhost' (using password: NO) in /home/a9362702/public_html/comped2.php on line 18
PHP Error Message
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/a9362702/public_html/comped2.php on line 18
PHP Error Message
Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/a9362702/public_html/comped2.php on line 20
PHP Error Message
Warning: mysql_close(): no MySQL-Link resource supplied in /home/a9362702/public_html/comped2.php on line 22
Here is my page code as it is at the mo:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Our List of Jokes</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<?
$username="a9362702_admin";
$password="***";
$database="a9362702_games";
mysql_connect("sql1.**********.com",$username,$password);
mysql_select_db($database);
$query="SELECT * FROM tablename";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
?>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Game Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">Game URL</font></th>
</tr>
<?
$i=0;
while ($i < $num) {
$field1_name=mysql_result($result,$i,"gname");
$field2_name=mysql_result($result,$i,"gurl");
?>
<tr>
<td><font face="Arial, Helvetica, sans-serif"><? echo $field1_name; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $field2_name; ?></font></td>
</tr>
<?
$i++;
}
echo "</table>";
?>
</body>
</html>
ellisgl
07-18-2008, 01:19 PM
The DB connection is a host thing. You might have to add your IP to the "white list". Contact the hosting provider about it..
On a side note: don't use short tags "<?", use "<?php" - short tags will be eliminated in PHP 6.
sturz001
07-18-2008, 01:25 PM
Thanks. Could the short tags be causing the problem now? I will look at white lists and <?php ?> tags. Would I find this in PHPMyADmin or In MYSQl Management?
ellisgl
07-18-2008, 01:27 PM
Short tags are not affecting you. Just a heads up.
sturz001
07-18-2008, 01:28 PM
Thanks, am looking now
ellisgl
07-18-2008, 02:04 PM
The "white list" is usually in your control panel. This is a firewall function of the server.
sturz001
07-19-2008, 01:13 PM
Sorry, Is there another reason this script is blocking itself? The only thing I found about IP's and blocking was a block list FOR THE WHOLE SITE WHICH WAS EMPTY Now really Confused.:confused: Have got a help ticket and is waiting for a reply
NogDog
07-19-2008, 05:56 PM
Is the script running somewhere different than where the database is running? If not, just use "localhost" instead of an IP address. If the DB is on a remote host that can only be accessed via the 'net, then that DB host must have been configured to allow remote database connections, and usually you have to specify a port number to be used, e.g. "1.23.123.12:456". The database host admin would need to provide you with the port number to use.
sturz001
07-20-2008, 09:24 AM
My Host is Running MySQL and PHPMyAdmin. When I created my database I was told to use the sql1.**********.com address NOT localhost I will check all the domains and things and try localhost. I am using **********.com and on the free package. The host claims Mysql is not restricted. The site is running at .net68.net which redirects to a place on server13.**********.com, where my website is.
----UPDATE----
Whoops, My bad the address was mysql1.**********.com
Thanks NogDog for your continued Help. I will add your site url and a description if you can provide me with one. If I can give you any "brownie points" on the forum, tell me how and I will!
NogDog
07-20-2008, 11:47 AM
Thanks. I think my post count says it all for "brownie points." :)
See my sig for links....
sturz001
07-20-2008, 11:52 AM
Thanks, Nog Dog!
Your Link will be added to the address below when I can get the site up.
http://www.thelinker.net63.net/comped.php
Thread Marked Resolved
ellisgl
07-20-2008, 12:13 PM
AVAST pops up saying there's malware.. HTML:Agent-L[Expl] - looks like it's a pop under ad.
sturz001
07-21-2008, 10:29 AM
what does? sorry not very clear. My site does not contain viruses - where has it got that from? Is it a seperate thing
ellisgl
07-21-2008, 10:29 AM
Your host has a pop under add that has malware according to Avast.
sturz001
07-21-2008, 10:33 AM
My host says that it has no ads
I did not set this
Could this be on your computer?
Is any other [clean] computers regeristing the same result? I have AVG 8 and not coming up eith anything
also that address I have given does not exist yet. Only comped2.php, which is a test exists. Also comped.html exisits which uses XML.
--Resolved--
The site displays my hosts 404 page which displays a popup ad, which avast must have on it's black list. Once my page is up 404 won't be displayed - problem should be solved. Will change FTP password just in case of attack.
--ellisgl!!!---
please supply me with a link to add as thanks to my website. Any way i can give "brownie points" to you?
ellisgl
07-21-2008, 10:35 AM
I wouldn't worry about it.. Just stating what I saw..
ellisgl
07-21-2008, 10:42 AM
I have a site that hasn't been updated in years..
sturz001
07-21-2008, 10:44 AM
I'll just state your nick and these forums! Thanks 2 u and nog dog! I now need to face next challenge..... a form too add records with. If I can't code my way round using nowlege from this tread, I guess another thread will be on it's way!