0

I successfully configured ACRA to send my caught exceptions to my server, the problem is I can't insert the report into the database:

@AcraCore(buildConfigClass = BuildConfig.class)
@AcraHttpSender(uri = "http://www.myserver.com/crashreports/addreport.php",
        httpMethod = HttpSender.Method.POST)

public class MyApplication extends Application {
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);

        ACRA.init(this);
    }
}

I know it sends somethings because I see an empty entry in my phpMyAdmin, but I can't get the report inside the database:

<?php
$link = mysqli_connect("localhost", "root", "pass", "db");

// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}

// Escape user inputs for security
$report = mysqli_real_escape_string($link, $_REQUEST['']);

// attempt insert query execution
$sql = "INSERT INTO VoiceRemoteCrash (report) VALUES ('$report')";

if(mysqli_query($link, $sql)){
    echo "Records added successfully.";
} else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}

// close connection
mysqli_close($link);
?>

I've searched docs, but didn't find much info, and my PHP knowledge is somewhat basic.

hiddeneyes02
  • 2,562
  • 1
  • 31
  • 58

2 Answers2

1

$_REQUEST[''] will returns NULL and will throw an "undefined index" notice.

You could get your report from POST raw data using file_get_contents('php://input').

I suggest you to have a look to : How can I prevent SQL injection in PHP? and use parameterized queries.

Syscall
  • 19,327
  • 10
  • 37
  • 52
0

This line references a nonsense variable:

$report = mysqli_real_escape_string($link, $_REQUEST['']);

You want something like:

$report = mysqli_real_escape_string($link, $_REQUEST['form_variable_name']);

But you shouldn't even do that, because the real_escape_string() functions can not be relied on to prevent SQL injection. Instead, you should use prepared statements with bound parameters, via either the mysqli or PDO driver. This post has some good examples.

Alex Howansky
  • 50,515
  • 8
  • 78
  • 98