Joshua F Posted September 3, 2010 Share Posted September 3, 2010 Error Notice: Undefined index: action in C:\Users\cory\Desktop\xampp\htdocs\Starter Kit(2)\admincp\pages\news.php on line 69 Php code <?php if($_GET['action'] == 'delete') { if($_SERVER['REQUEST_METHOD'] == 'POST') { mysql_query("DELETE FROM blog WHERE ID = '". realEscape($_POST['ID']) ."';") or die(mysql_error()); echo "News Deleted"; } } ?> <?php $result1 = mysql_query("SELECT * FROM blog ORDER BY ID desc") or die (mysql_error()); while($result = mysql_fetch_assoc($result1)) { ?><center> <h1>Delete News</h1> <form action="news.php?action=delete" method="POST"> ID: <select name="id" id="id"> <option value="<?php echo $result['ID'];?>"><?php echo $result['ID'];?> - <?php echo $result['name'];?></option> </select> <input type="submit" name="submit" value="Delete News"> </form></center> <?php } ?> Any ideas? Link to comment https://forums.phpfreaks.com/topic/212407-another-error/ Share on other sites More sharing options...
Joshua F Posted September 3, 2010 Author Share Posted September 3, 2010 Oh yea, forgot to say that line 69 is if($_GET['action'] == 'delete') { Link to comment https://forums.phpfreaks.com/topic/212407-another-error/#findComment-1106682 Share on other sites More sharing options...
trq Posted September 3, 2010 Share Posted September 3, 2010 You need to wrap that code in another if that checks $_GET['action'] actually exists. if (isset($_GET['action'])) { // code } Link to comment https://forums.phpfreaks.com/topic/212407-another-error/#findComment-1106683 Share on other sites More sharing options...
Mod-Jay Posted September 3, 2010 Share Posted September 3, 2010 That didnt work, joshua asked this for me Link to comment https://forums.phpfreaks.com/topic/212407-another-error/#findComment-1106710 Share on other sites More sharing options...
trq Posted September 3, 2010 Share Posted September 3, 2010 That didnt work, joshua asked this for me Post your current code then. Link to comment https://forums.phpfreaks.com/topic/212407-another-error/#findComment-1106725 Share on other sites More sharing options...
Mod-Jay Posted September 3, 2010 Share Posted September 3, 2010 My current code: <?php if ($_GET['action'] == ('delete')) { if($_SERVER['REQUEST_METHOD'] == 'POST') { mysql_query("DELETE FROM blog WHERE ID = '". realEscape($_POST['ID']) ."';") or die(mysql_error()); echo "News Deleted"; } } ?> <?php $result1 = mysql_query("SELECT * FROM blog ORDER BY ID desc") or die (mysql_error()); while($result = mysql_fetch_assoc($result1)) { ?><center> <h1>Delete News</h1> <form action="news.php?action=delete" method="POST"> ID: <select name="id" id="id"> <option value="<?php echo $result['ID'];?>"><?php echo $result['ID'];?> - <?php echo $result['name'];?></option> </select> <input type="submit" name="submit" value="Delete News"> </form></center> <?php } ?> Error: Notice: Undefined index: action in C:\Users\cory\Desktop\xampp\htdocs\Starter Kit(2)\admincp\pages\news.php on line 69 Line 69 : if ($_GET['action'] == ('delete')) { i added the isset and it show another error.. Link to comment https://forums.phpfreaks.com/topic/212407-another-error/#findComment-1106807 Share on other sites More sharing options...
wildteen88 Posted September 3, 2010 Share Posted September 3, 2010 You need to do two things.First make sure $_GET['action'] exits using isset. Then if it does exits, check whether $_GET['action'] is set to 'delete' if(isset($_GET['action']) && $_GET['action'] == 'delete') { // do something here } Link to comment https://forums.phpfreaks.com/topic/212407-another-error/#findComment-1106810 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.