1
<?php $daerah_ejen1 = "$_GET[daerah_ejen]";
$kumpulan_ejen1 ="$_GET[kumpulan_ejen]";

echo $daerah_ejen1;
echo $kumpulan_ejen1;
echo $kumpulan_ejen;

$sql= "SELECT * FROM data_ejen WHERE daerah_ejen= '$daerah_ejen1' AND kumpulan_ejen='Ketua Kampung' ORDER BY nama_ejen";
$result = mysql_query($sql) or @error_die("Query failed : $sql " . mysql_error());
?>

my url

laporan_kk_detail.php?daerah_ejen=HULU+LANGAT&kumpulan_ejen=Ketua Kampung

for output daerah_ejen variable has display, but for kumpulan_ejen/kumpulan_ejen1 is not display.

i dont know where the problem

1
  • You are echo $kumpulan_ejen; but you don't seem to have set $kumpulan_ejen anywhere. You've only set $kumpulan_ejen1 Commented Apr 2, 2014 at 7:23

5 Answers 5

3

your quotes accessing $_GET variable is invalid. try this

<?php 
  $daerah_ejen1 = $_GET["daerah_ejen"];
  $kumpulan_ejen1 =$_GET["kumpulan_ejen"];

and you should read something about security, because you can pass malicous code to your script!

edit:// you can have a look on this thread https://stackoverflow.com/questions/19539692/sanitizing-user-input-php

Sign up to request clarification or add additional context in comments.

4 Comments

the first part of your answer is wrong. you can access the way the OP used.
but than, the 'daerah_ejen' for example will be treated as an constant, and since its not defined, its cast to a string. this is quite bad practise and raise notices within your application. so its just a lucky incident, that this actually works!
can you tell me what kind notice you was talking about ?
If your error_reporting and display_error php setting is switched on, you may see notice such as this: "Notice: Use of undefined constant daerah_ejen - assumed 'daerah_ejen'.
3

you are converting get values in string using double quotes so remove and try

$daerah_ejen1 = $_GET['daerah_ejen'];
$kumpulan_ejen1 =$_GET['kumpulan_ejen'];

also use mysql_real_escape_string() for prevent sql injection.

Comments

0
  1. The quotes go around the parameter name. This is because $_GET[] is an associative array and its values are referenced using a string key

    $daerah_ejen1 = $_GET['daerah_ejen'];

    $kumpulan_ejen1 =$_GET['kumpulan_ejen'];

  2. Always sanitize your parameter values before using them in a query to protect yourself against SQL injection.

    $daerah_ejen1 = mysqli::real_escape_string($daerah_ejen1)

Comments

0

You face 2 problem on your code :

1st is :

$daerah_ejen1 = "$_GET[daerah_ejen]";
$kumpulan_ejen1 ="$_GET[kumpulan_ejen]";

replace it by this :

 $daerah_ejen1 = $_REQUEST['daerah_ejen'];
$kumpulan_ejen1 =$_REQUEST['kumpulan_ejen'];

2nd is :

$sql= "SELECT * FROM data_ejen WHERE daerah_ejen= '$daerah_ejen1' AND kumpulan_ejen='Ketua Kampung' ORDER BY nama_ejen";

replace it by this :

$sql= "SELECT * FROM data_ejen WHERE daerah_ejen= '".$daerah_ejen1. "' AND kumpulan_ejen='Ketua Kampung' ORDER BY nama_ejen";

7 Comments

can you tell me why you advice the OP to replace the $_GET to the way you have used ?
The second problem is not a problem. You can write "'$variable'" inside double quotes and get the desired result.
$_REQUEST represent $_GET and $_POST. I used $_REQUEST is easier your code which no need care about which $_GET or $_POST should use.
the question was asked before you change $_GET to $_REQUEST. And as said by W.K.S the second problem you mentioned was not a problem.Also changing to $_REQUEST will no way solve the problem
i recommend 2nd problem it more safety for your code.
|
0

If you need to put the $_GET['name'] in double quotes, wrap it in {} brackets.

e.g.

$kumpulan_ejen1 ="{$_GET['kumpulan_ejen']}";

Also, as dbh pointed out, you only have $kumpulan_ejen1, not kumpulan_ejen.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.