/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] T_DNUMBER error in php/sql combi???

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!

[CODE]
<!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.000webhost.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>
[/CODE]

This is the error I am getting:

[CODE]Parse error: syntax error, unexpected T_DNUMBER in /home/a9362702/public_html/comped2.php on line 15[/CODE]

comped2.php is the 1st code i gave you. It is online at
[URL=”http://thelinker.net63.net/comped2.php”]This place[/URL]

to post a comment
PHP

21 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 18.2008 — You need to quote the host name in the mysql_connect() function call.
Copy linkTweet thisAlerts:
@sturz001authorJul 18.2008 — Wow, that worked BUT i now have another error
[CODE]Parse error: syntax error, unexpected '=' in /home/a9362702/public_html/comped2.php on line 34[/CODE]
Copy linkTweet thisAlerts:
@ellisglJul 18.2008 — 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.
Copy linkTweet thisAlerts:
@sturz001authorJul 18.2008 — 
you should not use "-" in a variable name since that would make PHP think you are trying to subtract a constant from a variable.[/QUOTE]


Thanks - I guess I should read the W3C standards First!

Now have lots of errors - this is becoming a pain in the *@##

[CODE]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[/CODE]


Here is my page code as it is at the mo:
[CODE]<!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.000webhost.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>[/CODE]
Copy linkTweet thisAlerts:
@ellisglJul 18.2008 — 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.
Copy linkTweet thisAlerts:
@sturz001authorJul 18.2008 — 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?
Copy linkTweet thisAlerts:
@ellisglJul 18.2008 — Short tags are not affecting you. Just a heads up.
Copy linkTweet thisAlerts:
@sturz001authorJul 18.2008 — Thanks, am looking now
Copy linkTweet thisAlerts:
@ellisglJul 18.2008 — The "white list" is usually in your control panel. This is a firewall function of the server.
Copy linkTweet thisAlerts:
@sturz001authorJul 19.2008 — Sorry, Is there another reason this script is blocking itself? The only thing I found about IP's and blocking was a block list [B]FOR THE WHOLE SITE WHICH WAS EMPTY[/B] Now really Confused.? Have got a help ticket and is waiting for a reply
Copy linkTweet thisAlerts:
@NogDogJul 19.2008 — 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.
Copy linkTweet thisAlerts:
@sturz001authorJul 20.2008 — My Host is Running MySQL and PHPMyAdmin. When I created my database I was told to use the [I]sql1.000webhost.com[/I] address [B]NOT[/B] [I]localhost[/I] I will check all the domains and things and try localhost. I am using 000webhost.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.000webhost.com, where my website is.

----UPDATE----

Whoops, My bad the address was [I][B]my[/B]sql1.000webhost.com[/I]

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!
Copy linkTweet thisAlerts:
@NogDogJul 20.2008 — Thanks. I think my post count says it all for "brownie points." ?

See my sig for links....
Copy linkTweet thisAlerts:
@sturz001authorJul 20.2008 — 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
Copy linkTweet thisAlerts:
@ellisglJul 20.2008 — AVAST pops up saying there's malware.. HTML:Agent-L[Expl] - looks like it's a pop under ad.
Copy linkTweet thisAlerts:
@sturz001authorJul 21.2008 — what does? sorry not very clear. My site does not contain viruses - where has it got that from? Is it a seperate thing
Copy linkTweet thisAlerts:
@ellisglJul 21.2008 — Your host has a pop under add that has malware according to Avast.
Copy linkTweet thisAlerts:
@sturz001authorJul 21.2008 — 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?
Copy linkTweet thisAlerts:
@ellisglJul 21.2008 — I wouldn't worry about it.. Just stating what I saw..
Copy linkTweet thisAlerts:
@ellisglJul 21.2008 — I have a site that hasn't been updated in years..
Copy linkTweet thisAlerts:
@sturz001authorJul 21.2008 — 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!
×

Success!

Help @sturz001 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...