Web Hosting Talk







View Full Version : problems opening a mysql database using PHP


greatone88
01-31-2005, 03:16 PM
Howdy all,

I got to be missing something obvious as I am unable to open a mysql database with the webhosting I have. I keep on getting the following error message. I really cant see where I am doing anything wrong. I am starting to learn php and mysql and I can't even do this basic thing :( Any help would be appreciated :)

Thanks,

Jimbo

Here is the error message :

Parse error: parse error, unexpected T_VARIABLE in /home/mainlink/public_html/dev/php6_1.php on line 11

Here is my code :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>StatTracker Customers</TITLE>
</HEAD>

<BODY BGCOLOR="#FFFFFF">
<pre>
<? php
// Open the database connection
$connection=mysql_connect("localhost","mainlink_golfer","golfer");

// Select the Stattracker Database
mysql_select_db("mainlink_stattracker", $connection);

// Run the Query on the stattracker thru the connection
$result = mysql_query ("SELECT * FROM customer", $connection);

// While there are still rows in the result set, fetch the current row into the array $row
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
// Print out each element in the row
foreach ($row as $attribute)
print "($attribute) ";
print "\n";
}
?>
</pre>
</BODY>
</HTML>

rysolag
01-31-2005, 05:18 PM
take that MYSQL_NUM out of the while loop so there's just the one argument to mysql_fetch_array:

while ($row = mysql_fetch_array($result))
{
// Print out each element in the row
foreach ($row as $attribute)
print "($attribute) ";
print "\n";
}

greatone88
01-31-2005, 05:33 PM
Darn :( Still get the same error after I updated the code with your suggestion rysolag.

BTW Line 11 is :

$connection=mysql_connect("localhost","mainlink_golfer","golfer");


I know the userid and password and the host are correct. Is it possible that SQL or PHP is not installed correctly on the server ?? I don't think it is a ID10T error on my part, but you never know :)

Thanks,

Jimbo

greatone88
01-31-2005, 06:27 PM
Just noticed this in the phpMyAdmin in my website control panel. Is this the way it should look ??

MySQL
Create new database:
No Privileges
Show processes
Databases
Export
Log out


I notice the text No Privileges right below the create database link.

greatone88
01-31-2005, 06:50 PM
You are not going to believe it. The text editor I am using ( Araneae 4.5.2 ) must have corrupted the php file. I typed in the script using notepad and uploaded it and it worked like a champ !!!

Sorry for not thinking of it earlier :(

I did that after I installed IIS on my machine, downloaded and installed the lastest stable PHP and MySQL and still came up with the same error :) HEHE


Thanks,
Jimbo

S-Comm
01-31-2005, 06:55 PM
Sometimes, your handy Notepad is better than anything. ;)