0

I got an error when i use $_Request . this is my code

$lat2=$_REQUEST['lat'];
$lng2=$_REQUEST['lng'];

$flag['code']=0;

if($r=mysql_query("insert into markers_awal values('','$lat2','$lng2') ",$con))
{
    $flag['code']=1;
    echo"hi";
}

this is my error.

Notice: Undefined index: lat in C:\xampp\htdocs\MUF_Surabaya\Rute\insert_android.php on line 10
Notice: Undefined index: lng in C:\xampp\htdocs\MUF_Surabaya\Rute\insert_android.php on line 11

hi{"code":1}

can anybody explain to me,, thnk you

potashin
  • 44,205
  • 11
  • 83
  • 107

2 Answers2

0

Bad idea better use directly $_GET or $_POST and please remember to check the values you get from the user. Now your code is open for blind sql injections.

Try this code if you don't want to use the recomended mysqli:

$lat2 = floatval($_POST['lat']);
$lng2 = floatval($_POST['lng']);

If this still not work try dumping your inputs with this two lines:

var_dump($_GET);
var_dump($_POST);
rekire
  • 47,260
  • 30
  • 167
  • 264
0

Check for values with isset() or empty()

$lat2=(isset($_REQUEST['lat']) ? $_REQUEST['lat'] : '');
$lng2=(isset($_REQUEST['lng']) ? $_REQUEST['lng'] : '');

Good to get values with what method you are using $_GET or $_POST Why :- Why should I use $_GET and $_POST instead of $_REQUEST?

Community
  • 1
  • 1
Rakesh Sharma
  • 13,680
  • 5
  • 37
  • 44