CODE FOR PHP ACCESSING DATABASE [SOLVED]

Hi, hope i got this in the right place.

I have a code that i would like some help with. I have yet to get this code to work. but am sure 95% of the work is right.

I am trying to pull information from mySQL and show it on a .php or .html. right now i am using it on .php. here is the code:
[php]

<?ph $username="localhost"; $password="*******"; $database="nufftotals"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM Totals"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "Bustersnm Stats

"; ?> <? $i=0; while ($i < $num) { $Wins=mysql_result($result,$i,"Wins"); $Wins=mysql_result($result,$i,"Wins"); $Poles=mysql_result($result,$i,"Poles"); $Points=mysql_result($result,$i,"Points"); ?> <? ++$i; } echo "
Races Wins Poles Top 5's Top 10's Avg Starts Points
<? echo "$Wins"; ?> <? echo "$Wins"; ?> <? echo "$Poles"; ?> <? echo "$Points; ?>
"; ?> ?> [/php] Then when i try to view it at http://www.nuffracingleague.com/PHPTEST/bustersnm.php

I get this error:
Parse error: parse error, unexpected T_VARIABLE in /home/nuffraci/public_html/PHPTEST/bustersnm.php on line 3

But i know the username is correct.

Thanks for all the help!!!

Admin Edit: Added [PHP] bbcode tags for readability. Please refer to http://phphelp.com/guidelines.php for posting guidelines.

First of all you should start your php with <?php OR <? NOT <?ph But I assume that was just a typo.

Next. Are your SURE your username is localhost as that seems to be an odd name for a username. Additionally, I am not sure, but it might also pose other problems since localhost is used in many other capacities referring to the local system. So if it IS localhost, I would suggest changing it to a more meaningful name perhaps something like busterlocal.

Next… Get rid of the @ on the mysql_select_db line (and any other lines at least while debugging). The @ preceding a function will suppress errors. When debugging you want to SEE the errors… Not suppress them.

Also on your mysql_connect line. First you should assign it’s return value to a variable. Something like $link is good. Next your “localhost” here should be quoted since it’s a literal string. so your link line should be like

[php]

$link = mysql_connect(‘localhost’,$username,$password);

[/php]

Alright that got ride of the error on line 3. The username was just the default i hvae inputed what it really is. Now i get an error on line 48 which would be this…Parse error: parse error, unexpected ‘/’ in /home/nuffraci/public_html/PHPTEST/bustersnm.php on line 48

echo “”;

<?php $link = mysql_connect('localhost',$nuffraci_nuff,$password); $username="nuffraci_nuff"; $password="password"; $database="nuffraci_totals"; mysql_connect(localhost,$username,$password); mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM Totals"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "Bustersnm Stats

"; ?> <? $i=0; while ($i < $num) { $Wins=mysql_result($result,$i,"Wins"); $Wins=mysql_result($result,$i,"Wins"); $Poles=mysql_result($result,$i,"Poles"); $Points=mysql_result($result,$i,"Points"); ?> <? ++$i; } echo "
Races Wins Poles Top 5's Top 10's Avg Starts Points
<? echo "$Wins"; ?> <? echo "$Wins"; ?> <? echo "$Poles"; ?> <? echo "$Points; ?>
"; ?> ?>

witch error?

Sorry i forgot the error
Parse error: parse error, unexpected ‘/’ in /home/nuffraci/public_html/PHPTEST/bustersnm.php on line 48

u have a quote missing:

<? echo "$Points[b]"[/b]; ?>

BINGO----Its alive…

Thanks, man. amazing one mistake like that…

[solved]

Sponsor our Newsletter | Privacy Policy | Terms of Service