1

I have realized the database on a hosting website and not on the mac using MySQL. I use the database to SignUp/Login in an IOS app. The database is using a PHP code for connecting.

This is the PHP code:

<?php

header('Content-type: application/json');
if($_POST) {
    $Nome   = $_POST['nome'];
    $Cognome   = $_POST['cognome'];
    $Email   = $_POST['email'];
    $DOB   = $_POST['dob'];
    $password   = $_POST['password'];
    $c_password = $_POST['c_password'];

    if($_POST['email']) {
        if ( $password == $c_password ) {

            $db_name     = '****************';
            $db_user     = '****************';
            $db_password = '*********************';
            $server_url  = 'localhost';

            $mysqli = new mysqli('localhost', $db_user, $db_name, $db_password);


            if (mysqli_connect_errno()) {
                error_log("Connect failed: " . mysqli_connect_error());
                echo '{"success":0,"error_message":"' . mysqli_connect_error() . '"}';
            } else {
                $stmt = $mysqli->prepare("INSERT INTO Users (nome, cognome, email, dob, password, c_password) VALUES (?, ?, ?, ?, ?, ?)");
                $password = md5($password);
                $stmt->bind_param('ssssss', $nome, $cognome, $email, $dob, $password, $c_password);


                $stmt->execute();

                if ($stmt->error) {error_log("Error: " . $stmt->error); }

                $success = $stmt->affected_rows;


                $stmt->close();


                $mysqli->close();
                error_log("Success: $success");

                if ($success > 0) {
                    error_log("User '$email' created.");
                    echo '{"success":1}';
                } else {
                    echo '{"success":0,"error_message":"Email Exist."}';
                }
            }
        } else {
            echo '{"success":0,"error_message":"Passwords does not match."}';
        }
    } else {
        echo '{"success":0,"error_message":"Invalid Email."}';
    }
}else {
    echo '{"success":0,"error_message":"Invalid Data."}';
}
?>

This is the error that I see when I try my database:

(HY000/2002): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /srv/disk8/2129310/www/haer2jkqlgjql.co.nf/signUp.php on line 20

This error tells me that there are errors or there is an error in line 20, but I don't understand the reason.

th3g3ntl3man
  • 1,926
  • 5
  • 29
  • 50
  • 1
    http://stackoverflow.com/a/15039113/1817690 – Rohan Kumar Jul 19 '16 at 11:57
  • ***You really shouldn't use [MD5 password hashes](http://security.stackexchange.com/questions/19906/is-md5-considered-insecure)*** and you really should use PHP's [built-in functions](http://jayblanchard.net/proper_password_hashing_with_PHP.html) to handle password security. Make sure you [don't escape passwords](http://stackoverflow.com/q/36628418/1011527) or use any other cleansing mechanism on them before hashing. Doing so *changes* the password and causes unnecessary additional coding. – Jay Blanchard Jul 19 '16 at 12:54

1 Answers1

3

Its syntax mistake

$mysqli = new mysqli('localhost', $db_user, $db_name, $db_password);

Right syntax is

$mysqli = new mysqli('localhost',$db_user,$db_password, $db_name);
Devsi Odedra
  • 5,244
  • 1
  • 23
  • 37