0

So essentially i'm following a youtube tutorial and playing around with android studio for the first time.

I am having problems connecting with the database and keep getting the response server error.

I've tried checking the php code on a number of website and they keep saying the code is fine.

Any suggestions?

Register Code:

    require_once "connect.php";

    if(!$con){
        echo "Connecting failed";
    }else{
        if($_SERVER['HTTP_USER_AGENT'] == "MyTestApp"){
            if($_SERVER["REQUEST_METHOD"] == "POST"){
                if(isset($_POST['name']) && isset($_POST['email']) && isset($_POST['password'])){

                    $name = $_POST['name'];
                    $email = $_POST ['email'];
                    $password = md5($_POST['password']);

                    echo $name;
                } 
                else{
                    echo "missing fields required";
                }
                else{
                    echo "Improper request method";
                }
                else{
                    echo "invalid platform";
                }
            }

?>  

Connection Code:

<?php

    require_once "constants.php";

    $con = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

    if($con){
        echo "Database connection failed";
    }else{
        echo "Connected!!!";
    }

?>

Constants code:

<?php 

    define ( 'DB_HOST', 'localhost');
    define('DB_USER', 'id1950281_patrickmcmu11an');
    define( 'DB_PASSWORD', 'jordan123');
    define('DB_NAME', 'id1950281_penumbralogin');

 ?>
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
Patrick
  • 11
  • 2
  • 1
    MD5 is considered broken for security purposes and is not sufficient for password hashing. Use [`password_hash()`](http://us3.php.net/manual/en/function.password-hash.php) and [`password_verify()`](http://us3.php.net/manual/en/function.password-verify.php) instead. – Alex Howansky Jun 14 '17 at 20:39
  • What is the error? What do the logs tell you? – ficuscr Jun 14 '17 at 20:40
  • $password = string password_hash($_POST['password']); @AlexHowansky like this? – Patrick Jun 14 '17 at 20:41
  • @ficuscr Server Error from Volley – Patrick Jun 14 '17 at 20:43
  • @Patrick that is not really helpful. Read this: https://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php If you think it is the DB connection maybe [check for error](http://php.net/manual/en/mysqli.error.php). – ficuscr Jun 14 '17 at 20:46
  • Depends on your context -- use `password_hash()` when you write the password to the database, and `password_verify()` when you're checking a login attempt against the password that was previously stored. – Alex Howansky Jun 14 '17 at 20:53

0 Answers0