-1

this is my php page .I am sending data to $_post["name"],$_post["myHttpData"],$_post["address"]by an android application .I have tried writing these value in text file to check successful reception of data .The data is being received but a blank row (all fields blank) is being inserted when I send data .

    <?php

       $con=mysqli_connect("fdb2.biz.nf","1463950_rtr","tcp123","1463950_rtr");
    // Check connection
    if (mysqli_connect_errno())
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }
    $data=$_post["myHttpData"];

    $data1=$_post["name"];
    $data2=$_post["address"];
    $sql="INSERT INTO SMS (sender,body,time)
    VALUES
    ('$data','$data1','$data2')";
      if (!mysqli_query($con,$sql))
      {
      die('Error: ' . mysqli_error($con));
      }
    echo "1 record added";

    mysqli_close($con);
?>

I have also tried using

 $sql="INSERT INTO SMS (`sender`,`body`,`time`)
    VALUES
    ('$data','$data1','$data2')";

But it also produces same results .

Amit Swain
  • 213
  • 2
  • 4
  • 9
  • Have you tried using $_POST all capital case instead of $_post. Also, a side note - you should use prepared statements to help protect against SQL injection. – Boundless Sep 21 '13 at 15:24
  • Are you sure you want to assign the data to the fields: myHttpData->sender, name->body, address->time ? – dar7yl Sep 21 '13 at 16:57

2 Answers2

-1

Php variables are case sensitive. You need to specify $_POST, instead of $_post. Since there was nothing in $_post[...], the $data fields take empty strings.

Sasanka Panguluri
  • 3,058
  • 4
  • 32
  • 54
-1

My guess is that you used single quotes instead of double quotes. In php, single quoted strings are processed "as is", while double quoted strings will look for variables and evaluate them. See this answer

see if this works:

$sql="INSERT INTO SMS (sender,body,time)
VALUES
('".$data."','".$data1."','".$data2."')";

EDIT:oops I see you used double quotes.

try

 echo $sql;

see if your query is what you expected.

Community
  • 1
  • 1
what is sleep
  • 916
  • 4
  • 12