2

I'm getting these warnings from web host which contains my database. I'm trying to get an Android app developed in Android Studio to send data from a Register user activity to a database. I think I'm having a PHP Script error.

Below is my PHP code for registering user:

<?php
$con = mysqli_connect("localhost", "user", "pass", "db");

if (isset($_POST["name"], $_POST["email"], $_POST["username"], $_POST["password"])) 
{
$name =     $_POST["name"];
$email =    $_POST["email"];
$username = $_POST["username"];
$password = $_POST["password"];
}

$statement = mysqli_prepare($con, "INSERT INTO user (name, username, email, password) VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($statement, "siss", $name, $username, $email, $password);
mysqli_stmt_execute($statement);

$response = array();
$response["success"] = true;  

echo json_encode($response);
?>
Dharman
  • 30,962
  • 25
  • 85
  • 135
Reaper
  • 35
  • 5
  • `echo mysqli_error($con);` to see the specific SQL error. Try pasting your table schema too. – ishegg Sep 08 '17 at 02:50
  • @AlivetoDie I will now :) – Reaper Sep 08 '17 at 02:59
  • @AlivetoDie okay I understand. And I corrected it now and the errors have gone, just seeing if my android code works accordingly now :D, the web request is showing no errors or warnings now thanks to you. – Reaper Sep 08 '17 at 03:20
  • @AlivetoDie however the andorid part is still not working.. :( – Reaper Sep 08 '17 at 03:25
  • Change message part like this:- `if(mysqli_stmt_execute($statement)){ $response["success"] = true; }else{ $response["success"] = false; } echo json_encode($response);` (i changed according to uour original-one) and check your now – Alive to die - Anant Sep 08 '17 at 04:02
  • @AlivetoDie I will check that out later – Reaper Sep 08 '17 at 04:04

1 Answers1

0

You have check for errors:-

<?php
    //comment these two lines when code started working fine
    error_reporting(E_ALL);
    ini_set('display_errors',1);

    $con = mysqli_connect("localhost", "id2833909_split421", "pass123", "id2833909_splitw");

    /* check connection */
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }

    if (isset($_POST["name"], $_POST["email"], $_POST["username"], $_POST["password"])) {
        $name =     $_POST["name"];
        $email =    $_POST["email"];
        $username = $_POST["username"];
        $password = $_POST["password"];
        $statement = mysqli_prepare($con, "INSERT INTO `user` (`name`, `username`, `email`, `password`) VALUES (?, ?, ?, ?)");
        mysqli_stmt_bind_param($statement, "ssss", $name, $username, $email, $password); // i need to be s
        $response = array();
        if(mysqli_stmt_execute($statement)){
            $response["message"] = "success";  
        }else{
            $response["message"] = "error";  
        }
        echo json_encode($response);
    }
?>
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98