0

I have wrote a script in php for accesing from android application. It is used to add data into database but after I host it into a shared hosting it always showing 502 BAD gateway error...I don't know what happened to my code

here is my code:

<?php
require "init.php";
header('Content-type : bitmap; charset=utf-8');
$encoded_string = $_POST["encoded_string"];
$image_name = $_POST["image_name"];
$glry_encode_string = $_POST["glry_encoded_string"];
$glry_image_name = $_POST["glry_image_name"];
$cash= $_POST["cash"];
$credit = $_POST["credit"];
$description = $_POST["description"];
$date = $_POST["date"];

if(empty($_POST['encoded_string'])) {

} else {
    $camname="http://xxxxxx.com/folder/folder/Camera_images";
    $camimgpath="$camname/$image_name.jpeg";
    $folder="Camera_images/";
    $camera_path="$folder/$image_name.jpeg";
    file_put_contents($camera_path,base64_decode($encoded_string));
    echo "\n+$cash";
    echo "\n+$credit";
    echo "\n+$description";
    echo "\n+$image_name";
}

if(empty($_POST['glry_encoded_string'])) {
} else {
    $galname="http://xxxxx.com/folder/folder/Gallery_images";
    $galimgpath="$galname/$glry_image_name.jpeg";
    $folder="Gallery_images/";
    $glry_path="$folder/$glry_image_name.jpeg";
    file_put_contents($glry_path,base64_decode($glry_encode_string));
}
$sql= "insert into tbl_sales_Report    (cash,credit,description,date,camera_name,camera_path,gallery_name,gallery_path)values('$cash','$credit','$description','$date','$image_name','$camimgpath','$glry_image_name','$galimgpath');";

if(mysqli_query($con,$sql)) {
    echo "<br><h3>sending....</h3>";
} else {
    echo "Error in inserted".mysqli_errno($con);
}
?>

and here is the error log given from server side

  [16-Jan-2017 18:49:49 Etc/GMT] PHP Notice: Undefined index:     encoded_string in /home/samanxw6/public_html/hennasilks.com/jijo/informe /Add_info.php on line 5
    [16-Jan-2017 18:49:49 Etc/GMT] PHP Notice: Undefined index: image_name in /home/samanxw6/public_html/hennasilks.com/jijo/informe/Add_info.php on line 6
   [16-Jan-2017 18:49:49 Etc/GMT] PHP Notice: Undefined index: glry_encoded_string in /home/samanxw6/public_html/hennasilks.com/jijo/informe/Add_info.php on line 7
  [16-Jan-2017 18:49:49 Etc/GMT] PHP Notice: Undefined index: glry_image_name in /home/samanxw6/public_html/hennasilks.com/jijo/informe/Add_info.php on line 8
   [16-Jan-2017 18:49:49 Etc/GMT] PHP Notice: Undefined index: cash in /home/samanxw6/public_html/hennasilks.com/jijo/informe/Add_info.php on line 9
  [16-Jan-2017 18:49:49 Etc/GMT] PHP Notice: Undefined index: credit in /home/samanxw6/public_html/hennasilks.com/jijo/informe/Add_info.php on line 10
  [16-Jan-2017 18:49:49 Etc/GMT] PHP Notice: Undefined index: description in /home/samanxw6/public_html/hennasilks.com/jijo/informe/Add_info.php on line 11
  [16-Jan-2017 18:49:49 Etc/GMT] PHP Notice: Undefined index: date in /home/samanxw6/public_html/hennasilks.com/jijo/informe/Add_info.php on line 12
  [16-Jan-2017 18:49:49 Etc/GMT] PHP Notice: Undefined variable: camimgpath in /home/samanxw6/public_html/hennasilks.com/jijo/informe/Add_info.php on line 42
  [16-Jan-2017 18:49:49 Etc/GMT] PHP Notice: Undefined variable: galimgpath in /home/samanxw6/public_html/hennasilks.com/jijo/informe/Add_info.php on line 42

please help me to find a solution ...thanks in advance....

Shadow
  • 33,525
  • 10
  • 51
  • 64
fresher
  • 1
  • 5
  • Dont' save files in a database. http://stackoverflow.com/a/41235395/267540 – e4c5 Jan 17 '17 at 06:31
  • Possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – Niklesh Raut Jan 17 '17 at 06:31
  • 1
    You don't get a _"502 - Bad gateway"_-error on a _"PHP notice_". It rather sounds like your web server isn't correctly setup. – M. Eriksson Jan 17 '17 at 06:35
  • @Rishi i also try this... i check each variable using isset() but again i get the same error please help me – fresher Jan 17 '17 at 06:37
  • @MagnusEriksson yes i get this error from web server beacuase of this error but i can't solve this issue using isset()/empty() please help me – fresher Jan 17 '17 at 06:38
  • Can your android app connect to the server at all? Try with a "hello world". Does your script work when trying from some app like `Postman`? Btw, you're wide open to [SQL Injections](http://php.net/manual/en/security.database.sql-injection.php) and should really use [Prepared Statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) instead of concatenating your queries. – M. Eriksson Jan 17 '17 at 06:38
  • 1
    are you actually sending data by post request ? – Niklesh Raut Jan 17 '17 at 06:39
  • @Rishi yes i am sending request using POST – fresher Jan 17 '17 at 06:44
  • @MagnusEriksson how can i use preparedstatement instead of this script? how can i send data using this scrip – fresher Jan 17 '17 at 06:44
  • Start by reading the documentation I linked to. Look at the documentation of the tool you're trying to use to test sending the data. Basically: RTM. – M. Eriksson Jan 17 '17 at 06:47
  • @MagnusEriksson thanks for your helping and one doubt is that is this erro is because of i am not using preparedstatment? – fresher Jan 17 '17 at 06:52
  • No, that's just a security concern (a serious one, though). As I stated in my first comment, I don't think the 502-error is caused by your code at all: http://stackoverflow.com/questions/5011632/502-http-status-code – M. Eriksson Jan 17 '17 at 07:01
  • @MagnusEriksson thank you so much for your advice i'll try my best and please help me to solve this error also thanks in advance.. – fresher Jan 17 '17 at 07:03
  • If you get these error messages, then either you do not send the request via post or you use different parameter names. Period. You need to check your code on the client side. – Shadow Jan 17 '17 at 07:04
  • @Shadow you mean use parameter name and php variable name are must be different? – fresher Jan 17 '17 at 07:06
  • No. Pls read the comment again. Also dump your $_POST array to see what is in there. – Shadow Jan 17 '17 at 07:08

0 Answers0