undefined index error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • leesyaa
    New Member
    • Jan 2014
    • 20

    undefined index error

    This is going to sound really stupid, but I cannot figure out why I am getting this error.

    Code:
    Undefined index: bil in C:\wamp\www\FORM\deleteadmin.php on line 4
    
    Undefined index: adminID in C:\wamp\www\FORM\deleteadmin.php on line 5

    line 4 and 5 looks like this,

    Code:
    $bil = $_POST['bil'];
    $adminID = $_POST['adminID'];
    the full code are new.php which links to the deleteadmin.php that contains the error.

    new.php
    Code:
    echo "<form name='update $bil' method=post action=newuser.php>" ?>
    	<tr>
    		<td><center><?php echo $bil; ?></center></td>
    		<td><?php echo $row['name']; ?></td>
    		<td><?php echo $row['tel']; ?></td>
    		<td><?php echo $row['email']; ?></td>
    		<td><?php echo $row['username']; ?></td>
    		<td><?php echo $row['password']; ?></td>
    		<td><a href = "deleteadmin.php"><img src="img/deleteicon.png" align="center"></a></td>
    		<input type=hidden value={$row['adminID']} name=adminID>
    	    <input type=hidden value=$bil name=bil>
    	</tr>
    <?php 
    	echo "</form>";
    }
    ?>

    deleteadmin.php
    Code:
    <?php
    include ('config.php');
    
    $bil = $_POST['bil'];
    $adminID = $_POST['adminID'];
    
    $result = mysql_query("DELETE FROM `admin` WHERE `adminID`= '$adminID'") or die (mysql_error());
    
    if($result)
    {
    ?>
    <script language="javascript">
    alert("User No : <?php echo "$bil"; ?> DELETED");
    location.href="new.php";
    </script>
    
    <?php
    }
    else
    {
    ?>
    
    <script language="javascript">
    alert("User No : <?php echo "$bil"; ?> NOT DELETED");
    location.href="new.php";
    </script>
    <?php
    }
    ?>
    What do I need to do to fix them?
    I don't understand why this is happening, and I'd love to know how to make it go away.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    the problem is that you have a link and not a submit button. you can simply combine button and image like:

    Code:
    <button type="submit">
        <img src="…">
    </button>

    Comment

    • leesyaa
      New Member
      • Jan 2014
      • 20

      #3
      I figured this do the trick!

      Code:
      <td><a href = "deleteadmin.php?adminID=<?php echo $row['adminID']; ?>&bil=<?php echo $bil; ?>"><img src="img/deleteicon.png" align="center"></a></td>

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        well, if you‘re fine with using GET instead of POST … (and the fact that GET requests get cached)

        Comment

        • leesyaa
          New Member
          • Jan 2014
          • 20

          #5
          less secure? hmm maybe this :D

          Code:
          $sql = "DELETE FROM admin WHERE md5(adminID)= '".md5($adminID)."'";

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            that doesn‘t change the fact that both values are plainly visible on transmission. when they are on your server, they have reached the "secure" spot.

            Comment

            Working...