Page 1 of 1

[SOLVED] [HELP] Undefined index

Posted: Wed Dec 15, 2004 5:46 pm
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 :(

Posted: Wed Dec 15, 2004 5:47 pm
by rehfeld
learn how and why to use isset() and empty()

you url doesnt contain ?del=something

Posted: Wed Dec 15, 2004 5:49 pm
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> ";

Posted: Wed Dec 15, 2004 6:17 pm
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()

Posted: Wed Dec 15, 2004 7:26 pm
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

Posted: Wed Dec 15, 2004 8:07 pm
by bla5e
i think my query is messed up... someone help me out?

Posted: Wed Dec 15, 2004 8:23 pm
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>";
		} 
?>

Posted: Wed Dec 15, 2004 11:38 pm
by ol4pr0
better make that

Code: Select all

if (isset($_GET['del']) && ($_GET['del'] == 'dl')) {

Posted: Thu Dec 16, 2004 6:28 am
by bla5e
thanks