The PHP code won't delete item from database using "$noteid". If I put a number in it's place it will, but when I try using "$noteid". It won't do it. It does everything correct up to the point where it tries to delete.
Here's how I get the "$noteid":
//javascript
function viewnote(noteid) {
window.location = "noteview.php?noteid=" + noteid;
}
//button in body
<input type="button" value="Edit" onclick="editnote('<?= $noteid ?>')" />
Here's the code on the linked to page:
<?php
$noteid = $_REQUEST['noteid'];
if (isset($_POST['delete'])){
mysql_query("DELETE FROM notes WHERE noteid='$noteid'");
header ('Location: index2.php');
}
?>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" style="margin:0px; pading:0px"><input type="submit" name="delete" value="Delete"></form>
</body>
** It's Working Now!!! ** What made it work was a hidden form field.
Here's the code:
<?php
if (isset($_POST['delete'])){
$nid = $_REQUEST['notenum'];
mysql_query("DELETE FROM notes WHERE noteid='$nid'");
header ('Location: index2.php');
}
?>
//body cody
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" style="margin:0px; pading:0px"><input type="text" name="notenum" value="<?php echo $noteid; ?>" style="display:none" /><input type="submit" name="delete" value="Delete"></form>
Thanks to everyone for your help!!! This site is my favourite site now.
vardump($_REQUEST)and see what you're working with.<?php echo $_SERVER['PHP_SELF']; ?>is a potential XSS hole, too. It should not be used.