[SOLVED] [HELP] Undefined index

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

[SOLVED] [HELP] Undefined index

Post by bla5e »

heres my whole code... i dont know whats wrong..

Code: Select all

<?php 
error_reporting(E_ALL);  

$valid = array('email'); 

$email = empty($_GET['email']) ? 'email' : $_GET['email']; 
if(in_array($email, $valid)){ 
  mysql_connect ("localhost", "steve_maillist", "maillist") or die(mysql_error()); 
  mysql_select_db ('steve_maillist') or die(mysql_error()); 
  $sql = 'SELECT * FROM maillist ORDER BY '.$email; 
  $result = mysql_query($sql) or die(mysql_error()); 
} else { 
  echo 'Invalid email: '.$_GET['email']; 
} 

echo "<table width="100%" border="1" cellspacing="0" cellpadding="0">";
echo "<tr>";
echo "<td width="25%"><span class="style4">EMAIL</span></td>\n";
echo "</tr>";
while ($data = mysql_fetch_assoc($result)) {
echo "<tr>";
echo "<td><span class="style1">";
echo '<a href="mailto:'.$data["email"].'"> '.$data["email"].'</a>';
echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href='maillist.php?del=dl&id=" . $data["email"] . "'>*Delete*</a> ";
echo "</span></td>";
echo "</tr>";
echo mysql_error();
}
echo "</table><BR>";
?>

<?PHP
if ($_GET['del'] == 'dl') {
$connect = mysql_connect ("localhost", "steve_maillist", "maillist") or die ('I cannot connect to the database because: ' . mysql_error()); 
$db = mysql_select_db ("steve_maillist");
$num = $_GET['email'];
$query = mysql_query("DELETE FROM maillist WHERE email = '$num'");

echo "<br>All Done, No ERRORS!!<BR><BR>";
}
?>

<b><a href="#" onclick="return hidetoggle('msgs');" onmouseover="window.status=' past messages '; return true;">PAST EMAILS SENT</a></b>(click to view the drop down)<br>
<span id="msgs" class="leftborder" style="display: none;">

<?php 
error_reporting(E_ALL);  
$dbh=mysql_connect ("localhost", "steve_maillist", "maillist") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("steve_maillist", $dbh);
$sql = "SELECT * FROM messages";
echo mysql_error();
$result = mysql_query($sql, $dbh);
echo mysql_error();
echo "<table width="100%" border="1" cellpadding="0" cellspacing="0">";
echo "<tr>";
echo "<td width="8%"><span class="style4">ID</span> </td>";
echo "<td width="23%"><span class="style4">Message</span></td>";
echo "</tr>";
while ($data = mysql_fetch_assoc($result)) {
echo "<tr>";
echo "<td width="8%"><span class="style1">";
echo $data["id"];
echo "</span></td>";
echo "<td width="23%"><span class="style1">";
echo $data["msg"];
echo "</span> </td>";
echo "</tr>";
echo mysql_error();
}
echo "</table>";

?>
</span><br><BR>

<B>Send Mass Mail</b>:
<?PHP
		if (!empty($_POST['submitted']) && $_POST["submitted"] == 1){ 
		error_reporting(E_ALL); 
		
		$subject = $_POST["subject"]; 
		$body = $_POST["body"];
		$from = $_POST["from"];
		
		$dbh=mysql_connect ("localhost", "steve_maillist", "maillist") or die ('I cannot connect to the database because: ' . mysql_error()); 
		mysql_select_db ("steve_maillist"); 
		$sql = "SELECT * FROM messages";
		mysql_query("INSERT INTO `messages` (`id`, `msg`)VALUES ('', '$body')");
		$result = mysql_query($sql, $dbh) or die (mysql_error()); 
		

		$query = mysql_query("SELECT * FROM maillist");
		while ($result = mysql_fetch_array($query)) {
			mail($result['email'],$subject,$body,
			"FROM: {$from}\r\n");
		}
		echo mysql_error(); 
		echo "Mail Sent!!<Br>";
		echo "Message stored!";
} 
else 
{
			echo "<form method="POST" action="" . $_SERVER['PHP_SELF'] . "">\n";
			echo ("<table border="0" cellspacing="0" cellpadding="0">");
			echo ("<tr>");
			echo ("<td valign="top"><span class="style4">reply emai</span>l</td>");
			echo ("<td><span class="style1"><input type="text" name="from" size="33"></span></td>");
			echo ("</tr>");
			echo ("<td valign="top"><span class="style4">subject</span></td>");
			echo ("<td><span class="style1"><input type="text" name="subject" size="33" maxlength="50" /></span></td>");
			echo ("</tr>");			
			echo ("<tr>");
			echo ("<td valign="top"><span class="style4">body</span>&nbsp;</td>");
			echo ("<td><span class="style1"><textarea name="body" rows="9" cols="52"></textarea></span></td>");
			echo ("</tr>");
			echo ("<tr>");
			echo ("<td colspan="2">");
			echo ("<input type="hidden" name="submitted" value="1">");
			echo ("<input type="image" name=submitted src="imgs/submit.jpg" value="1"></center></form>");
			echo ("</td>");
			echo ("</tr>");
			echo ("</form><BR>");
} 
echo mysql_error(); 
?>
I get this error:

Code: Select all

Notice: Undefined index: del in /home/steve/public_html/onepurpose/maillist/maillist.php on line 65
line 65 =

Code: Select all

if ($_GET['del'] == 'dl') {
can someone tell me whats wrong :(
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

learn how and why to use isset() and empty()

you url doesnt contain ?del=something
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

rehfeld wrote:learn how and why to use isset() and empty()

you url doesnt contain ?del=something

Code: Select all

echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href='maillist.php?del=dl&id=" . $data["email"] . "'>*Delete*</a> ";
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

and i bet if you click on that link, you dont get an error.
but you DO get an error when your url doesnt have that.

again, learn how and why to use isset() and empty()
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

rehfeld wrote:and i bet if you click on that link, you dont get an error.
but you DO get an error when your url doesnt have that.
true, but it wont delete still wont delete it from the db
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

i think my query is messed up... someone help me out?
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

FIXED IT

Code: Select all

<?PHP 
   	   	if (isset($_GET['del'])) if ($_GET['del'] == 'dl') {
		$connect = mysql_connect ("localhost", "steve_maillist", "maillist") or die ('I cannot connect to the database because: ' . mysql_error()); 
		$db = mysql_select_db ("steve_maillist");
		if (isset($_GET['id'])) {
		$num = $_GET['id'];
		$query = mysql_query("DELETE FROM maillist WHERE email = '$num'");
		} else die('email param not set in delete function');
		echo "<br>All Done, No ERRORS!!<BR><BR>";
		} 
?>
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

better make that

Code: Select all

if (isset($_GET['del']) && ($_GET['del'] == 'dl')) {
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

thanks
Post Reply