Jump to content

Cant connect to MYSQL DB


Diggers34

Cant connect to MYSQL DB  

  1. 1. Cant connect to MYSQL DB

    • Help
      0
    • Help MOre
      0


Recommended Posts

I am trying to set up a longin for my website. When I enter my username and password and hit enter I get the following message.

 

cannot connect

 

Here is my page

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>

 

<body>

<?php

$host="127.0.0.1"; // Host name

$username="root"; // Mysql username

$password="ireland"; // Mysql password

$db_name="test"; // Database name

$tbl_name="members"; // Table name

 

// Connect to server and select databse.

mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

 

// username and password sent from signup form

$myusername=$_POST['myusername'];

$mypassword=$_POST['mypassword'];

 

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";

$result=mysql_query($sql);

 

// Mysql_num_row is counting table row

$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row

 

if($count==1){

// Register $myusername, $mypassword and redirect to file "login_success.php"

session_register("myusername");

session_register("mypassword");

header("location:login_success.php");

}

else {

echo "Wrong Username or Password";

}

?>

 

 

</body>

</html>

 

 

any ideas. My set up is I am testing on my providers site http://www.siesta.cat/login2/main_login.php. Am I missing something?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/39772-cant-connect-to-mysql-db/
Share on other sites

your error is saying it cannot conect to the database with the perameters you have given it

 

as you have already set variables with the strings required to connect to the database try this

 

<?php
mysql_connect($host, $username, $password)or die("cannot connect"); 
?>

 

EDIT: if that doesnt work check that the login details are correct too

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.