Article:
 |
|
Using MySQL from PHP
|
| Subject: |
|
Connect to MySQL DB |
| Date: |
|
2006-05-09 17:00:30 |
| From: |
|
Cleo
|
|
|
|
I have a hosting account with GODADDY.com where I've been assigned a MySQL database. But I'm having trouble connecting to it. My code is as follows:
//Connect To Database
$hostname="mysql.secureserver.net";
$username="cdphillips";
$password="*******";
$dbname="cdphillips";
$usertable="Contacts";
$yourfield = "F_Name";
$conn=mysql_connect($hostname,$username, $password) or die ('Error connecting to mysql');
mysql_select_db($dbname);
# Check If Record Exists
$query = "SELECT * FROM $usertable";
$result = mysql_query($query);
if($result)
{
while($row = mysql_fetch_array($result))
{
$name = $row["$yourfield"];
echo "Name: ".$name."
";
}
}
What's wrong please?
|
Showing messages 1 through 7 of 7.
-
Connect to MySQL DB
2007-12-15 08:23:06
krsbuilt
[View]
-
Connect to MySQL DB
2009-06-22 20:04:54
mfoster978
[View]
-
Connect to MySQL DB
2009-07-05 20:17:09
Reloaded2010
[View]
-
Connect to MySQL DB
2007-11-04 03:21:29
dashtimothy2000
[View]
-
Connect to MySQL DB
2006-05-31 23:12:22
PrabhjotSingh
[View]
-
Connect to MySQL DB
2006-06-03 05:16:23
sandeep_raju
[View]
-
Connect to MySQL DB
2006-06-02 13:08:43
Aethenoth
[View]
mysql_connect($hostname,$username, $password) or die ('Error connecting to mysql');
mysql_select_db($dbname);
it might work. since you were making the mysql cnnection a variable, your database connection couldn't use it. now if you make the mysql connection not a variable then anything in the script can access it.