0

I want to edit my database with popup model, my code like this :

<button type='button' class='btn btn-block btn-info btn-xs' data-toggle='modal' a href='#myModal' data-id= ".$rows['no']." >EDIT</td>

and those edit button refers to

<div class="modal fade" id="myModal" role="dialog">
        <div class="modal-dialog">

          <!-- Modal content-->
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal">&times;</button>
              <h4 class="modal-title">STATUS</h4>
            </div>

          <form method="post" action="module/prepaid/update.php">
            <input type="hidden" value="<?php echo $rows['no']; ?>" name="no">
            <div class="modal-body">

              <i class="fa   fa-remove text-red"></i>
              <input type="radio" name="status" value="Defect" <? php echo active_radio_button("Defect", $rows['status']) ?>> Defect



              <i class="fa   fa-refresh text-blue"></i>
              <input type="radio" name="status" value="OP" <? php echo active_radio_button("On Progress", $rows['status']) ?>> On Progress


              <i class="fa  fa-check-circle text-green"></i>
              <input type="radio" name="status" value="OK" <? php echo active_radio_button("OK", $rows['status']) ?>> OK

              <div id="div1"></div>
            </div>
            <div class="modal-footer">
              <input type="buttons" class="btn btn-default" value="SAVE" data-dismiss="modal" onclick="window.location.href='module/prepaid/update.php'" /></a>
            </div>
          </div>
          </form>
        </div>
      </div>

Popup was succesfully appear but eveytime i submit my edit error appear :

Notice: Undefined index: no in C:\xampp\htdocs\ocsweb\module\prepaid\update.php on line 10

my update.php is :

    <?php
$server = "localhost"; 
$username = "root";  
$password = ""; 
$database = "ocsweb";
$konek = mysql_connect($server, $username, $password) or die ("Gagal konek ke server MySQL" .mysql_error());
$bukadb = mysql_select_db($database) or die ("Gagal membuka database $database" .mysql_error());

$no         = $_POST['no'];
$status     = $_POST['status'];

$query="UPDATE postpaid SET status = '$status' WHERE no='$no'";
mysql_query($query);

I see in here the problem is index "no" (index no or number is like id) is undifinied but I do not know where my mistakes are, please help :( Thank You..

user3679987
  • 27
  • 1
  • 7
  • Your code is vulnerable to [**SQL injection**](https://en.wikipedia.org/wiki/SQL_injection) attacks. You should use [**mysqli**](https://secure.php.net/manual/en/mysqli.prepare.php) or [**PDO**](https://secure.php.net/manual/en/pdo.prepared-statements.php) prepared statements with bound parameters as described in [**this post**](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). – Alex Howansky May 08 '17 at 15:28
  • Don't use the `mysql_*` functions. They have been deprecated since v5.5 (Jun 2013) and removed since v7.0 (Dec 2015). Instead use the [**mysqli_***](https://secure.php.net/manual/en/book.mysqli.php) or [**PDO**](https://secure.php.net/manual/en/book.pdo.php) functions with [**prepared statements**](https://secure.php.net/manual/en/pdo.prepare.php) and [**bound parameters**](https://secure.php.net/manual/en/pdostatement.bindparam.php). – Alex Howansky May 08 '17 at 15:28
  • what does source show ? are ID's correct in button and hidden input or are they missing ? – OldPadawan May 08 '17 at 15:32
  • @AlexHowansky Ohh yes thankyou very much for your input – user3679987 May 09 '17 at 12:06
  • @OldPadawan It cannot get an Id or in this case i index it as 'no' , my question is, is my code : – user3679987 May 09 '17 at 12:06
  • Or any idea for code to get an id/no database from this, i think my code : @OldPadawan It cannot get an Id or in this case i index it as 'no' , my question is, is my code : – user3679987 May 09 '17 at 12:07
  • `` this is generated by a loop from query results, right ? but then, what's in `$rows['no']` ? Is it a number ? a string ? is it properly printed ? can you show the final output / source code ? – OldPadawan May 09 '17 at 12:12

0 Answers0