I cannont get connected to my database, is there something Im doing wrong?

I cannont get connected to my database, is there something Im doing wrong? I am not using a local host but GoDaddy MyPHPAdmin. This is my first time coding in PHP and my first time setting up a Database. So I can be perfectly clear I have a registration form on one HTML page and the PHP code that pushes to the database on the next page (which I saved as a PHP). Also the passwords dont check to see if they match.

What I’m trying to do is have a registration form push to MySQL.

Here is my configuration:
DRIVER={MySQL ODBC 3.51 Driver}; SERVER=myelstonfamily.db.##########.hostedresource.com; PORT=3306; DATABASE=myelstonfamily; USER=myelstonfamily; PASSWORD=‘your password’; OPTION=0;

My PHP code
[php]

$host=“myelstonfamily.db.##########.hostedresource.com”;
$username=“myelstonfamily”;
$password=“password”;
$dbname=“myelstonfamily”;
$usertable=“Registration”;

mysql_connect("$host","$username", “$password”) or die (“”);
mysql_select_db($dbname) or die (“cannot select DB”);

$id=$_POST[‘id’];
$username=$_POST[‘username’];
$password=$_POST[‘password’];
$password=md5($pass);
$confirm_password=$_POST[‘confirm_password’];
if ($password == $confirm_pasword)
{
echo “Passwords Match”;
}
else
{
echo “Passwords Don’t Match”;
};

$Fname =$_POST[‘fname’];
$lname =$_POST[‘lname’];
$email =$_POST[‘email’];
$address =$_POST[‘address’];
$city =$_POST[‘city’];
$state =$_POST[‘state’];
$zip =$_POST[‘zip’];
$phone =$_POST[‘phone1’];
$phone =$_POST[‘phone2’];
$dob =$_POST[‘Birthday’];
$sex =$_POST[‘sex’];
$spouse =$_POST[‘spouse’];
$sdob =$_POST[‘sBirthday’];
$anniversary =$_POST[‘anniversary’];
$facebook =$_POST[‘facebook’];
$twitter =$_POST[‘twitter’];
$google =$_POST[‘googleplus’];
$linage =$_POST[‘linage’];
$parents =$_POST[‘parents’];
$grandparents =$_POST[‘grandparents’];

$result = mysql_query
(“SELECT * FROM Registration WHERE
username=’$username’”);
if($result == 1)

      {
    	echo "Error User name already exists";
      }
     else
      {
  mysql_query("INSERT INTO Registration 
	( username, password,fname,lname,email,address,city,state,zip,phone1,phone2,birthday,sex,spouse,
              sbirthday,anniversary,facebook,twitter,googleplus,linage,parents,grandparents)

  VALUES ('$username','$password','$firstname','$lastname','$email','$address','$city','$state','$zip','$phone',
	'$dob','$sex','$spous','$sdob,'$anniversary','$facebook','$twitter','$google','$linage','$parents',
	'$grandparents')");

mysql_close($con);

?>
[/php]

Try using mysql errors to tell you what it going wrong then you can get an idea.

[php]$db_server = mysql_connect($host, $username, $password);

if (!$db_server) die("unable to connect: " . mysql_error());

mysql_select_db($host)
	or die("Unable to select database: " . mysql_error());[/php]

I assume you noticed that there is no PHP code on that page. It is all after which makes it HTML.
You need to start the PHP with <?PHP…

Assuming that it is not that simple. Your connection code is good and as it should be.

But, I would take out all of the query, post info, insert info and just start simple with the connection only. Just open the query with '$result = mysql_query(“Select * from Registration”)
Then, check row count or whatever to see if it works. Then, add the others back in once the simple parts are working.

I use GoDaddy all the time and connect easily to both public and private MySQL databases there and it works great. I suspect the missing PHP…

Sponsor our Newsletter | Privacy Policy | Terms of Service