Jump to content

Another Error


Joshua F

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.