Can not connect to the database in php

0

Hello, I'm trying to get my administration file connected to my database. the file is as follows:

<link rel="Stylesheet" type="text/css" href="style.css" />
<link href='http://fonts.googleapis.com/css?family=Karla:400,700,700italic,400italic' rel='stylesheet' type='text/css'>
<?php
$filename = 'install.php';
if (file_exists($filename)) {
echo ("<center><font color='red'><b>/install.php still exists<br>
After installing please delete install.php</center></font></b>");
} else {
    if (isset($_POST['Login'])){
    include('SqlConnect.php');
        if (!mysql_connect($host, $username, $password)) die("Can't connect to database");
        if (!mysql_select_db($db_name)) die("Can't select database");
        $myusername=$_POST['myusername'];
        $mypassword=$_POST['mypassword'];
        $myusername = stripslashes($myusername);
        $mypassword = stripslashes($mypassword);
        $myusername = mysql_real_escape_string($myusername);
        $mypassword = mysql_real_escape_string($mypassword);
        $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
        $result=mysql_query($sql);
        $count=mysql_num_rows($result);
        if($count >= 1){
            session_start();
                    $_SESSION["myusername"] = $_POST['myusername'];
$_SESSION['loggedin'] = true;
            $_SESSION["mypassword"] = $_POST['mypassword'];
        header("location: index.php");
        } else {
            echo "<center><font color='red'><b>Wrong Username or Password</center></font></b>";
        }
    }
?>
<br>
<form method="post" action=""><td>
<table width="325" border="0" align="center" cellpadding="2" cellspacing="0" bgcolor="#212121">
<td><table width="100%" border="0" cellpadding="3" cellspacing="0" bgcolor="#404040"></td>
<tr colspan="3"><strong><center> <font color="ECECEC"> Admin Login </font></center></strong></tr>
<tr>
<td>
<font color="ECECEC">Username </font><input name="myusername" type="text" id="myusername">
<font color="ECECEC">Password </font><input name="mypassword" type="password" id="mypassword">
</td>
<center><td><input type="submit" name="Login" value="Login"></td></center>
</table></table>
</form>
<?php
}
?>

And where I connect to the sqlconnect file, I put the ip address of the site:

<?php
$host="http://198.54.116.113/"; 
$username="nulltbzc_A"; 
$password="password"; 
$db_name="nulltbzc_DS"; 
$tbl_name="members"; 
$table="Account"; 
?>

But still, it always gives me the same error again.

Can't connect to database
    
asked by Sergio Ramos 16.08.2017 в 13:17
source

1 answer

0

Where do you have the mysql_connect? I see the data in variables in the SqlConnect.php where there is no mysql_connect to make the connection, and in the page either. I only see a conditional with the denial "!" from mysql_connect.

Try putting this after the include and you will know if it connects you:

//CONEXION
    $enlace =  mysql_connect('$host', '$username', 'password');
    if (!$enlace) {
        die('No pudo conectarse: ' . mysql_error());
    }
    echo 'Conectado satisfactoriamente';
//CONEXION A LA BASE DE DATOS
mysql_select_db("$db_name",$enlace) OR DIE ("Error: No es posible establecer la conexión a la base de datos"
);

Ah at the end add the disconnection (just before finishing the php "? >" includes:

mysql_close($enlace);

You tell us to see ...

Greetings.

    
answered by 16.08.2017 / 13:47
source