2

I have a code like this
I'm using little JavaScript there
my input form code

<form method="get" action="simpankriteria.php">
    Inputkan Bobot Kriteria:<BR>
    <INPUT TYPE = "text" value="1" name = "A11" readonly>
    <input type="text" id="A12" onkeyup="bagi();" placeholder="C1/C2"/>
    <input type="text" value="" id="A13" onkeyup="bagi1();" placeholder="C1/C3"/><BR>

    <input type="text" value="" id="A21" placeholder="C2/C1" readonly/>
    <INPUT TYPE = "text" value="1" NAME = "A22" readonly>
    <input type="text" value="" id="A23" onkeyup="bagi2();" placeholder="C2/C3"/><BR>

    <input type="text" value="" id="A31" placeholder="C3/C1" readonly/>
    <input type="text" value="" id="A32" placeholder="C3/C2" readonly/>
    <INPUT TYPE = "text" value="1" NAME = "A33" readonly><BR>

    <input type="submit" value="Masukkan Bobot">
</form>

my code to input that data to database

mysql_query("INSERT INTO kriteria VALUE(0,'$_GET[A11]','$_GET[A12]','$_GET[A13]','$_GET[A21]','$_GET[A22]','$_GET[A23]','$_GET[A31]','$_GET[A32]','$_GET[A33]')") //Perintah Mysql untuk mengisi tabel Tamu

Error:

Error Displaying<br>
Notice: Undefined index: A12 in C:\xampp\htdocs\spkk\simpankriteria.php on line 15<br>
Notice: Undefined index: A13 in C:\xampp\htdocs\spkk\simpankriteria.php on line 15<br>
Notice: Undefined index: A21 in C:\xampp\htdocs\spkk\simpankriteria.php on line 15<br>
Notice: Undefined index: A23 in C:\xampp\htdocs\spkk\simpankriteria.php on line 15<br>
Notice: Undefined index: A31 in C:\xampp\htdocs\spkk\simpankriteria.php on line 15<br>
Notice: Undefined index: A32 in C:\xampp\htdocs\spkk\simpankriteria.php on line 15<br>
Cœur
  • 37,241
  • 25
  • 195
  • 267
Jazuly
  • 321
  • 1
  • 4
  • 15
  • Possible duplicate of [php $\_GET and undefined index](http://stackoverflow.com/questions/7876868/php-get-and-undefined-index) – Sahil Gulati Mar 28 '17 at 08:20
  • And please stop using mysql_query : http://php.net/manual/en/function.mysql-query.php – Elbarto Mar 28 '17 at 08:20
  • can you send the whole code so we can see which line `line 15` is – 131 Mar 28 '17 at 08:21
  • You're using `$_GET[A11]` it should be `$_GET["A11"]` `A11` is a String not a literal and since you're adding this variable reference directly in the String you'll have to use something like this: `${$_GET["A11"]}`. – Titus Mar 28 '17 at 08:21
  • no, it works without "" if all of it is enclosed in quotes – 131 Mar 28 '17 at 08:22
  • 1
    Get Variable uses name as param; It seems that you are sending id not name convert id to name to – Shrijan Tiwari Mar 28 '17 at 08:22
  • Possible duplicate of [PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – Masivuye Cokile Mar 28 '17 at 08:25
  • i add name after id https://github.com/jazuly/code/blob/master/1 my input http://imgur.com/Wtm3fcQ but when i check database A21, A31 and A32 record "0" http://i.imgur.com/QqsYu3z.jpg my whole code https://github.com/jazuly/code/blob/master/2 – Jazuly Mar 28 '17 at 09:24

2 Answers2

0

Check if the $_GET[A12]','$_GET[A13]','$_GET[A21]','$_GET[A22]','$_GET[A23]','$_GET[A31] is set

if(isset($_GET['A12']) { echo "Ok" } 
  1. Are you getting your data from id or name of Input. You javascript will show better. Because all those input have id not name
codePhree
  • 97
  • 2
  • 10
  • i add name after id https://github.com/jazuly/code/blob/master/1 my input http://imgur.com/Wtm3fcQ but when i check database A21, A31 and A32 record "0" http://i.imgur.com/QqsYu3z.jpg my whole code https://github.com/jazuly/code/blob/master/2 – Jazuly Mar 28 '17 at 09:24
0

Use var_dump($_GET); exit(); in simpankriteria.php to debug it.

When you are submitting the form, the form sends a GET request to the server, this is an array of form "name"=>"value", you can not send #id unless you use some javascript to create your own url ?A12=asa&A13=122 and submit the form.

Add name="A12" and so on to the input fields and submit. you should also check before executing the query:

if(!isset($_GET['A12']) && empty($_GET['A12'])){  exit('invalid request');  }
//execute your query here

DO NOT USE mysql_query. your code is vulnerable to mysql injection.

Give PDO a try. you will love it.

Sahith Vibudhi
  • 4,935
  • 2
  • 32
  • 34
  • i add name after id https://github.com/jazuly/code/blob/master/1 my input http://imgur.com/Wtm3fcQ but when i check database A21, A31 and A32 record "0" http://i.imgur.com/QqsYu3z.jpg my whole code https://github.com/jazuly/code/blob/master/2 – Jazuly Mar 28 '17 at 10:11
  • In beginning of your php file, do `var_dump($_GET); exit();` and see your script is receiving the data or not. – Sahith Vibudhi Mar 28 '17 at 10:31
  • array(9) { ["A11"]=> string(1) "1" ["A12"]=> string(2) "10" ["A13"]=> string(2) "20" ["A21"]=> string(5) "0.100" ["A22"]=> string(1) "1" ["A23"]=> string(2) "30" ["A31"]=> string(5) "0.050" ["A32"]=> string(5) "0.033" ["A33"]=> string(1) "1" } A21, A31 and A32 have a data but why not record to my database? – Jazuly Mar 28 '17 at 10:44
  • thanks all, after running the var dump Im understand, the problem is my data type int, therefore 0.xxx not recorded, i change to float and my data record now :D – Jazuly Mar 28 '17 at 10:51
  • If it helped. Up vote and accept it as correct answer :) – Sahith Vibudhi Mar 28 '17 at 10:52