ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
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?


1 to 3 of 3
  1. Connect to MySQL DB
    2007-12-15 08:23:06  krsbuilt [View]

  2. Connect to MySQL DB
    2007-11-04 03:21:29  dashtimothy2000 [View]

  3. Connect to MySQL DB
    2006-05-31 23:12:22  PrabhjotSingh [View]

1 to 3 of 3