I have a bit of a problem with my newsletter
here is the error I get:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/happy/public_html/newsletter/subscribe.php on line 64

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/happy/public_html/newsletter/sindex.php on line 244

Warning: extract(): First argument should be an array in /home/happy/public_html/newsletter/nindex.php on line 175

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/happy/public_html/newsletter/nindex.php on line 191

Subscribe.php

<?php

// subscribe newsletter
// subscribe.php
// database connection script here

// MySQL Connection Variables
								
$hostname='localhost';
$user='user'; 
$pass='pass';	
$dbase='user_newsletter'; 

$connection = mysql_connect("$hostname" , "$user" , "$pass") or die ("Can't connect to 

MySQL");
$db = mysql_select_db($dbase , $connection) or die ("Can't select database.");


if(!isset($mode))
{
	$mode = 'index';
}

switch ($mode)
{
	case 'index':
		// display default form
		?><p><strong>Subscribe/ UnSubscribe Mailing List</strong></p>
		
		<form action="<?php echo "$PHP_SELF?mode=process"; ?>" method="post">
			<table width="100%" border="1" cellspacing="1" cellpadding="1">
			  <tr> 
				<td>Name:*</td>
				<td><input type="text" name="name" size="20"></td>
			  </tr>
			  <tr> 
				<td>Email:*</td>
				<td><input type="text" name="email" size="20"></td>
			  </tr>
			  <tr> 
				<td>Format Preferred:*</td>
				<td><input type="radio" name="format" value="h" 

checked>HTML <input type="radio" name="format" value="t">Plain Text</td>
			  </tr>
			  <tr> 
				<td>Mode:*</td>
				<td><input type="radio" name="smode" value="subscribe"  

checked>Subscribe <input type="radio" name="smode" value="unsubscribe">UnSubscribe</td>
			  </tr>
			  <tr> 
				<td colspan="2"><input type="submit" name="Submit" 

value="Submit"></td>
			  </tr>
			</table>
		</form>
	<?php
	break;
	
	case 'process':
		// check that all fields are filled in
		if (empty($name) || empty($email))
		{
			die ("Error! Please fill in all required fields.");
		}
		// check for duplicate entry in database
		$qCheck = "select * from subscribers where name='$name' and 

email='$email' ";
		$rsCheck = mysql_query($qCheck);
		
		$countCheck = mysql_num_rows($rsCheck);
		
		// determine whether user wants to subscribe or unsubscribe
		if ($smode=='subscribe')
		{
			if ($countCheck != 0)	// if entry already exists in database, 

do not add subscriber
			{
				die ("Error. Record already exist.");
			}
			else {
				$query = "insert into subscribers VALUES 

('','$name','$email','$format')";
				$successmsg = "Thank you $name. Your email, $email has 

been recorded.";
			}
		}
		else {	// smode= unsubscribe
			if ($countCheck == 0)	// entry does not exist, cannot 

unsubscriber user
			{
				die ("No such record, cannot unsubscribe user.");
			}
			else {
				
				$query = "delete from subscribers where name='$name' and 

email='$email' ";
				$successmsg = "Thank you $name. Your email, $email has 

been unsubscribed.";
			}
		}
		
		// now execute the query
		$result = mysql_query($query);
		
		if ($result)
		{
			echo $successmsg;
			
		}
		
	break;

}
?>

sindex.php

<?php

// Subscriber Administration
// sindex.php

// MySQL Connection Variables (Enter the values)
$hostname='localhost';
$user='user';
$pass='pass';
$dbase='user_newsletter';

$connection = mysql_connect("$hostname" , "$user" , "$pass") or die ("Can't connect to MySQL");
$db = mysql_select_db($dbase , $connection) or die ("Can't select database.");

if(!isset($mode))
{
$mode = 'list';		// set the default mode to list subscribers
}

?><p><strong>Subscriber Administration</strong></p><?php

switch ($mode)
{
	case 'list':
		$q = "select * from subscriber order by sid desc limit 35 ";
		$rs = mysql_query($q);
		
		?>
		<table cellpadding="1" cellspacing="1" border="1" >
		<tr><td><strong>Name</strong></td><td>Email</td><td>Commands</td></tr>
		<?php
		
		while ($row = mysql_fetch_array($rs))
		{
			extract ($row);
			// Display records into table rows.
			echo "<tr><td><strong>$name</strong></td><td>$email</td>
			<td><a href=\"$PHP_SELF?mode=edit&sid=$sid\">Edit</a>  | 
			<a href=\"$PHP_SELF?mode=delete&sid=$sid\">Delete</a></td></tr>";
		}
		?></table><?php
			
	
	break;
	
	case 'add':
	
		// Display Adding Form.
		?><form action="sindex.php?mode=insert" method="post">
		<table cellpadding="1"  border="1">
		<tr>
		<td><strong>Name:</strong></td>
		<td><input type="text" name="name" size="30" maxlength="25"></td>
		</tr>
		<tr>
		<td><strong>Email:</strong></td>
		<td><input type="text" name="email" size="30" maxlength="200"></td>
		</tr>
		<tr>
		<td><strong>Format:</strong></td>
		<td><input type="radio" name="format" value="h" checked>HTML 
		<input type="radio" name="format" value="t">Plain Text</td></tr>
		 <tr>
		<td>Mode:*</td>
		<td><input type="radio" name="smode" value="subscribe" checked>Subscribe <input type="radio" name="smode" value="unsubscribe">UnSubscribe</td>
		</tr>
		<tr><td colspan="2"><input type="submit" name="submit"></td></tr></table>
		</form> 
		<?php
	
	break;
	
	case 'insert':
		 // check that all fields are filled in
		if (empty($name) || empty($email))
		{
		die ("Error! Please fill in all required fields.");
		}
		// check for duplicate entry in database
		$qCheck = "select * from subscribers where name='$name' and email='$email' ";
		$rsCheck = mysql_query($qCheck);
		
		$countCheck = mysql_num_rows($rsCheck);
		
		// determine whether user wants to subscribe or unsubscribe
		if ($smode=='subscribe')
		{
		if ($countCheck != 0) // if entry already exists in database, do not add subscriber
		{
		die ("Error. Record already exist.");
		}
		else {
		$query = "insert into subscribers VALUES ('','$name','$email','$format')";
		$successmsg = "Thank you $name. Your email, $email has been recorded.";
		}
		}
		else { // smode= unsubscribe
		if ($countCheck == 0) // entry does not exist, cannot unsubscriber user
		{
		die ("No such record, cannot unsubscribe user.");
		}
		else {
		
		$query = "delete from subscribers where name='$name' and email='$email' ";
		$successmsg = "Thank you $name. Your email, $email has been unsubscribed.";
		}
		}
		
		// now execute the query
		$result = mysql_query($query);
		
		if ($result)
		{
			echo $successmsg;
		}
		
	break;
	
	case 'edit':
		$q = "select * from subscribers where sid=$sid ";
		$rs = mysql_query($q);
		
		while ($row = mysql_fetch_array($rs))
		{
			extract($row);
			// Display Editing Form.
			?>
			<form action="<?php echo "sindex.php?mode=update&sid=$sid"; ?>" method="post">
			<table cellpadding="1"  border="1">
			<tr>
			<td><strong>Name:</strong></td>
			<td><input type="text" name="name" size="30" maxlength="25" value="<?php echo "$name"; ?>"></td>
			</tr>
			<tr>
			<td><strong>Email:</strong></td>
			<td><input type="text" name="email" size="30" maxlength="200" value="<?php echo "$email"; ?>"></td>
			</tr>
			<tr>
			<td><strong>Format:</strong></td>
			<td><input type="radio" name="format" value="h" 
			<?php  if ($format == "h") { echo "checked"; } ?>>HTML 
			<input type="radio" name="format" value="t" <?php  if ($format == "t") { echo "checked"; } ?>>Plain Text</td></tr>
			 <tr>
			<td>Mode:*</td>
			<td><input type="radio" name="smode" value="subscribe" checked>Subscribe <input type="radio" name="smode" value="unsubscribe">UnSubscribe</td>
			</tr>
			<tr><td colspan="2"><input type="submit" name="Update"></td></tr></table>
			</form> 
			<?php	
		}
	
	break;
	
	case 'update':
		 // check that all fields are filled in
		if (empty($name) || empty($email))
		{
		die ("Error! Please fill in all required fields.");
		}
		// check for duplicate entry in database
		$qCheck = "select * from subscribers where name='$name' and email='$email' ";
		$rsCheck = mysql_query($qCheck);
		
		$countCheck = mysql_num_rows($rsCheck);
		
		// determine whether user wants to subscribe or unsubscribe
		if ($smode=='subscribe')
		{
		if ($countCheck != 0) // if entry already exists in database, do not add subscriber
		{
		die ("Error. Record already exist.");
		}
		else {
		$query = "update subscribers set  name='$name', email='$email', format='$format' where sid='$sid' ";
		$successmsg = "Success! Subscriber record has been updated.";
		}
		}
		else { // smode= unsubscribe
		if ($countCheck == 0) // entry does not exist, cannot unsubscriber user
		{
		die ("No such record, cannot unsubscribe user.");
		}
		else {
		
		$query = "delete from subscribers where name='$name' and email='$email' ";
		$successmsg = "Success. $email has been unsubscribed.";
		}
		}
		
		// now execute the query
		$result = mysql_query($query);
		
		if ($result)
		{
			echo $successmsg;
		}
	break;
	
	case 'delete':
		$q = "delete from subscribers where sid='$sid' ";
		$rs = mysql_query($q);
		
		if ($rs)
		{
			echo "Success. Record deleted.";
		}
	break;
	
	case 'search':
		// display search box.
		?>
		<form action="sindex.php?mode=results" method="post">
		<strong>Name:</strong> <input type="text" name="name" size="30" maxlength="20"><br>
		<strong>Email:</strong> <input type="text" name="email" size="30" maxlength="200"><br>
		<input type="submit" value="Search">
		</form>
		<?php
		
	
	break;
	
	case 'results':
		if (empty($name) && empty($email))
		{
			die ("Error. There is no search criteria.");
		}
		// if user enter both name & email search
		if ($name !="" && $email !="")
		{
			$q = "select * from subscribers where name like '$name%' and email like '$email%' ";
		}
		else {
			if (empty($name))
			{
				// user entered email option
				$q = "select * from subscribers  where email like '$email$' ";
			}
			else {
				// user chose name option
				$q = "select * from subscribers where name like '$name%' ";
			}
		}
		$rs = mysql_query($q);
		$rscount = mysql_num_rows($rs);
		
		// display results
		?>
		<table cellpadding="1" cellspacing="1" border="1" >
		<tr><td><strong>Name</strong></td><td>Email</td><td>Commands</td></tr>
		<?php
		if ($rscount != 0)
		{
			while ($row = mysql_fetch_array($rs))
			{
				extract ($row);
				// Display records into table rows.
				echo "<tr><td><strong>$name</strong></td><td>$email</td>
				<td><a href=\"$PHP_SELF?mode=edit&sid=$sid\">Edit</a>  | 
				<a href=\"$PHP_SELF?mode=delete&sid=$sid\">Delete</a></td></tr>";
			}
		}
		else {
			echo "<tr><td colspan =3>No Results returned.</td></tr>";
		}
		?></table><?php
			
	break;
}
	
?>

nindex.php

<?php

// Newsletter Administration
// nindex.php

// MySQL Connection Variables (Enter the values)
$hostname='localhost';
$user='user';
$pass='pass';
$dbase='user_newsletter';

$connection = mysql_connect("$hostname" , "$user" , "$pass") or die ("Can't connect to MySQL");
$db = mysql_select_db($dbase , $connection) or die ("Can't select database.");

$mode = $_GET['mode'];		// for globals off

if(!isset($mode) || empty($mode))
{
	$mode = 'list';		// set the default mode to list subscribers
}

?><p><strong>Newsletter Administration</strong></p><?php

switch ($mode)
{
	case 'list':
		$q = "select * from newsletter order by postdate desc ";
		$rs = mysql_query($q);
		
		?>
		<table cellpadding="1" cellspacing="1" border="1" >
		<tr><td><strong>Newsletter Title</strong></td><td>Post Date</td><td>Commands</td></tr>
		<?php
		
		while ($row = mysql_fetch_array($rs))
		{
			extract ($row);
			// Display records into table rows.
			echo "<tr><td><strong>$title</strong></td><td>$postdate</td>
			<td><a href=\"$PHP_SELF?mode=edit&news_id=$news_id\">Edit</a>  | 
			<a href=\"$PHP_SELF?mode=delete&news_id=$news_id\">Delete</a></td></tr>";
		}
		?></table><?php
			
	break;
	
	case 'add':
			// Display Adding Form.
		?><form action="nindex.php?mode=insert" method="post">
		<table cellpadding="1"  border="1">
		<tr>
		<td><strong>Newsletter Title:*</strong></td>
		<td><input type="text" name="title" size="30" maxlength="250"></td>
		</tr>
		<tr>
		<td><strong>Content:*</strong><br>HTML Code okay.</td>
		<td><textarea name="content" rows="10" cols="35"></textarea></td>
		</tr>
		<tr><td colspan="2">
		Dispatch Newsletter?<input type="checkbox" name="dispatch" value="yes">
		<p><input type="submit" name="submit"></p></td></tr>
		</table>
		</form> 
		<?php
	
	break;
	
	case 'insert':
		$title = $_POST['title'];
		$content = $_POST['content'];
		$dispatch = $_POST['dispatch'];
		 // check that all fields are filled in
		if (empty($title) || empty($content))
		{
			die ("Error! Please fill in all required fields.");
		}
		
		// insert into database
		$newRecord = "insert into newsletter (news_id, title, content, postdate) 
							VALUES ('','$title','$content', now()) ";
		$rsRecord = mysql_query($newRecord);
		
		if ($rsRecord && $dispatch == 'yes') // administrator wants to send newsletter out
		{
			$lastid= mysql_insert_id();
			// redirect administrator to dispatch mode
			header("Location: nindex.php?mode=dispatch&news_id=$lastid");
		}
		else {
			echo "Success! Newsletter recorded.";
		}
	
	break;
	
	case 'delete':
		$news_id = $_GET['news_id'];
		
		$remove = "delete from newsletter where news_id='$news_id' ";
		$rs = mysql_query($remove);
				
		if ($rs)
		{
			echo "Success, newsletter deleted.";
		}
	
	
	break;
	
	case 'edit':
		$news_id = $_GET['news_id'];

		$q = "select * from newsletter where news_id=$news_id ";
		$rs = mysql_query($q);
		
		while ($row = mysql_fetch_array($rs))
		{
			extract($row);
			// Display Editing Form.
			?>
			<form action="<?php echo "nindex.php?mode=update&news_id=$news_id"; ?>" method="post">
			<table cellpadding="1"  border="1">
			<tr>
			<td><strong>Title:</strong></td>
			<td><input type="text" name="title" size="30" maxlength="250" value="<?php echo "$title"; ?>"></td>
			</tr>
			<tr>
			<td><strong>Content:*</strong><br>HTML Code okay.</td>
			<td><textarea name="content" rows="10" cols="35"><?php echo "$content"; ?></textarea></td>
			</tr>
			<tr><td colspan="2">
			Dispatch Newsletter?<input type="checkbox" name="dispatch" value="yes">
			<p><input type="submit" name="submit"></p></td></tr>
			</table>
			</form>
			<?php
		}
	
	break;
	
	case 'update':
		$title = $_POST['title'];
		$content = $_POST['content'];
		$dispatch = $_POST['dispatch'];
		 // check that all fields are filled in
		if (empty($title) || empty($content))
		{
			die ("Error! Please fill in all required fields.");
		}
		
		// Update query
		$update = "update newsletter set title='$title', content='$content' where news_id='$news_id' ";
		$rsUpdate = mysql_query($update);
		
		if ($rsUpdate && ($dispatch=='yes'))
		{
			// Administrator wants to dispatch newsletter, redirect to dispatch mode
			header("Location: nindex.php?mode=dispatch&news_id=$news_id");

		}
		else {
			echo "Success, Newsletter updated.";
		}
	
	break;
	
	case 'dispatch':
		$news_id = $_GET['news_id'];
		// dispatch newsletter to subscribers
		// Obtain newsletter details
		$select = "select  * from newsletter where news_id='$news_id' ";
		$result = mysql_query($select);
		
		$row = mysql_fetch_array($result);
		
		extract($row);
		$plaintext = str_replace("<br>","\r\n",$content);		
		$plaintext = str_replace("<p>","\r\n",$content);
		$plaintext = strip_tags($content);
			
		// obtain subscriber list
		$getList = "select * from subscribers ";
		$rsList = mysql_query($getList);
		
		$headers = "MIME-Version: 1.0\r \n";
		// edit the following 3 variables
		
		$from = "Your Name Here";	
		$fromemail = "abc@yyy.com";
		$subject = "Newsletter from ABC website";
		
		while ($subrow = mysql_fetch_array($rsList))
		{
			extract($subrow);
			if ($format == 't')
			{
				// plain text format
				$headers .= "Content-type: text/plain; charset=iso-8859-1\r \n";
				$headers .= "From: \"$from\" <$fromemail>\r \n";
   				$headers .= "Reply-To: \"$from\" <$fromemail>\r \n";
				$headers .= "X-Mailer: Just My Server";
				$message = $plaintext;

			}
			else {
				// HTML format
				$headers .= "Content-type: text/html; charset=iso-8859-1\r \n";
				$headers .= "From: \"$from\" <$fromemail>\r \n";
   				$headers .= "Reply-To: \"$from\" <$fromemail>\r \n";
				$headers .= "X-Mailer: Just My Server";
				$message = $content;
			}
			// mail it out
			mail($email,$subject,$message,$headers);
			
		}
		echo "Newsletter sent out.";		
	break;
}
?>

Can somebody tell me my errors?

I would guess it may be that you are running a query on newsletter but your database is called user_newsletter. :)

add or die(mysql_error()); onto all of your mysql_query($q) lines and see if that doesn't tell you whats up.

That helped a bit, thank you.
But I still have errors and since I am new at php I do not know how to
correct them. (is there a such thing as a php validator?)

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/user/public_html/newsletter/sindex.php on line 92

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/user/public_html/newsletter/sindex.php on line 33

<?php

// Subscriber Administration
// sindex.php

// MySQL Connection Variables (Enter the values)
$hostname='localhost';
$user='user';
$pass='pass';
$dbase='user_newsletter';

$connection = mysql_connect("$hostname" , "$user" , "$pass") or die ("Can't connect to MySQL");
$db = mysql_select_db($dbase , $connection) or die ("Can't select database.");

if(!isset($mode))
{
$mode = 'list'; // set the default mode to list subscribers
}

?><p><strong>Subscriber Administration</strong></p><?php

switch ($mode)
{
case 'list':
$q = "select * from subscriber order by sid desc limit 35 ";
$rs = mysql_query($q);

?>
<table cellpadding="1" cellspacing="1" border="1" >
<tr><td><strong>Name</strong></td><td>Email</td><td>Commands</td></tr>
<?php

while ($row = mysql_fetch_array($rs))
{
extract ($row);
// Display records into table rows.
echo "<tr><td><strong>$name</strong></td><td>$email</td>
<td><a href=\"$PHP_SELF?mode=edit&sid=$sid\">Edit</a> | 
<a href=\"$PHP_SELF?mode=delete&sid=$sid\">Delete</a></td></tr>";
}
?></table><?php


break;

case 'add':

// Display Adding Form.
?><form action="sindex.php?mode=insert" method="post">
<table cellpadding="1" border="1">
<tr>
<td><strong>Name:</strong></td>
<td><input type="text" name="name" size="30" maxlength="25"></td>
</tr>
<tr>
<td><strong>Email:</strong></td>
<td><input type="text" name="email" size="30" maxlength="200"></td>
</tr>
<tr>
<td><strong>Format:</strong></td>
<td><input type="radio" name="format" value="h" checked>HTML 
<input type="radio" name="format" value="t">Plain Text</td></tr>
<tr>
<td>Mode:*</td>
<td><input type="radio" name="smode" value="subscribe" checked>Subscribe <input type="radio" name="smode" value="unsubscribe">UnSubscribe</td>
</tr>
<tr><td colspan="2"><input type="submit" name="submit"></td></tr></table>
</form> 
<?php

break;

case 'insert':
// check that all fields are filled in
if (empty($name) || empty($email))

{
die ("Error! Please fill in all required fields.");
}

// check if email is valid
if(!eregi('^([._a-z0-9-]+[._a-z0-9-]*)@(([a-z0-9-]+\.)*([a-z0-9-]+)(\.[a-z]{2,3})?)$', $email)) 
{

    echo 'That does not look like a valid email address.'; }


// check for duplicate entry in database
$qCheck = "select * from subscribers where name='$name' and email='$email' ";
$rsCheck = mysql_query($qCheck);

$countCheck = mysql_num_rows($rsCheck);

// determine whether user wants to subscribe or unsubscribe
if ($smode=='subscribe')
{
if ($countCheck != 0) // if entry already exists in database, do not add subscriber
{
die ("Error. Record already exist.");
}
else {
$query = "insert into subscribers VALUES ('','$name','$email','$format')";
$successmsg = "Thank you $name. Your email, $email has been recorded.";
}
}
else { // smode= unsubscribe
if ($countCheck == 0) // entry does not exist, cannot unsubscriber user
{
die ("No such record, cannot unsubscribe user.");
}
else {

$query = "delete from subscribers where name='$name' and email='$email' ";
$successmsg = "Thank you $name. Your email, $email has been unsubscribed.";
}
}

// now execute the query
$result = mysql_query($query);

if ($result)
{
echo $successmsg;
}

break;

case 'edit':
$q = "select * from subscribers where sid=$sid ";
$rs = mysql_query($q) or die(mysql_error());

while ($row = mysql_fetch_array($rs))
{
extract($row);
// Display Editing Form.
?>
<form action="<?php echo "sindex.php?mode=update&sid=$sid"; ?>" method="post">
<table cellpadding="1" border="1">
<tr>
<td><strong>Name:</strong></td>
<td><input type="text" name="name" size="30" maxlength="25" value="<?php echo "$name"; ?>"></td>
</tr>
<tr>
<td><strong>Email:</strong></td>
<td><input type="text" name="email" size="30" maxlength="200" value="<?php echo "$email"; ?>"></td>
</tr>
<tr>
<td><strong>Format:</strong></td>
<td><input type="radio" name="format" value="h" 
<?php if ($format == "h") { echo "checked"; } ?>>HTML 
<input type="radio" name="format" value="t" <?php if ($format == "t") { echo "checked"; } ?>>Plain Text</td></tr>
<tr>
<td>Mode:*</td>
<td><input type="radio" name="smode" value="subscribe" checked>Subscribe <input type="radio" name="smode" value="unsubscribe">UnSubscribe</td>
</tr>
<tr><td colspan="2"><input type="submit" name="Update"></td></tr></table>
</form> 
<?php 
}

break;

case 'update':
// check that all fields are filled in
if (empty($name) || empty($email))
{
die ("Error! Please fill in all required fields.");
}
// check for duplicate entry in database
$qCheck = "select * from subscribers where name='$name' and email='$email' ";
$rsCheck = mysql_query($qCheck);


//here
$countCheck = mysql_num_rows($rsCheck);

// determine whether user wants to subscribe or unsubscribe
if ($smode=='subscribe')
{
if ($countCheck != 0) // if entry already exists in database, do not add subscriber
{
die ("Error. Record already exist.");
}
else {
$query = "update subscribers set name='$name', email='$email', format='$format' where sid='$sid' ";
$successmsg = "Success! Subscriber record has been updated.";
}
}
else { // smode= unsubscribe
if ($countCheck == 0) // entry does not exist, cannot unsubscriber user
{
die ("No such record, cannot unsubscribe user.");
}
else {

$query = "delete from subscribers where name='$name' and email='$email' ";
$successmsg = "Success. $email has been unsubscribed.";
}
}

// now execute the query
$result = mysql_query($query);

if ($result)
{
echo $successmsg;
}
break;

case 'delete':
$q = "delete from subscribers where sid='$sid' ";
$rs = mysql_query($q) or die(mysql_error());

if ($rs)
{
echo "Success. Record deleted.";
}
break;

case 'search':
// display search box.
?>
<form action="sindex.php?mode=results" method="post">
<strong>Name:</strong> <input type="text" name="name" size="30" maxlength="20"><br>
<strong>Email:</strong> <input type="text" name="email" size="30" maxlength="200"><br>
<input type="submit" value="Search">
</form>
<?php


break;

case 'results':
if (empty($name) && empty($email))
{
die ("Error. There is no search criteria.");
}
// if user enter both name & email search
if ($name !="" && $email !="")
{
$q = "select * from subscribers where name like '$name%' and email like '$email%' ";
}
else {
if (empty($name))
{
// user entered email option
$q = "select * from subscribers where email like '$email$' ";
}
else {
// user chose name option
$q = "select * from subscribers where name like '$name%' ";
}
}
$rs = mysql_query($q) or die(mysql_error());
$rscount = mysql_num_rows($rs);

// display results
?>
<table cellpadding="1" cellspacing="1" border="1" >
<tr><td><strong>Name</strong></td><td>Email</td><td>Commands</td></tr>
<?php
if ($rscount != 0)
{
while ($row = mysql_fetch_array($rs))
{
extract ($row);
// Display records into table rows.
echo "<tr><td><strong>$name</strong></td><td>$email</td>
<td><a href=\"$PHP_SELF?mode=edit&sid=$sid\">Edit</a> | 
<a href=\"$PHP_SELF?mode=delete&sid=$sid\">Delete</a></td></tr>";
}
}
else {
echo "<tr><td colspan =3>No Results returned.</td></tr>";
}
?></table><?php

break;
}

?>

Warning: Cannot modify header information - headers already sent by (output started at /home/user/public_html/newsletter/nindex.php:23) in /home/user/public_html/newsletter/nindex.php on line 159

Warning: Cannot modify header information - headers already sent by (output started at /home/user/public_html/newsletter/nindex.php:23) in /home/user/public_html/newsletter/nindex.php on line 89

Warning: extract(): First argument should be an array in /home/user/public_html/newsletter/nindex.php on line 177

<?php

// Newsletter Administration
// nindex.php

// MySQL Connection Variables (Enter the values)
$hostname='localhost';
$user='user';
$pass='password';
$dbase='user_newsletter';

$connection = mysql_connect("$hostname" , "$user" , "$pass") or die ("Can't connect to MySQL");
$db = mysql_select_db($dbase , $connection) or die ("Can't select database.");

$mode = $_GET['mode'];		// for globals off

if(!isset($mode) || empty($mode))
{
	$mode = 'list';		// set the default mode to list subscribers
}

?>
<p><strong>Newsletter Administration</strong></p>
<?php

switch ($mode)
{
	case 'list':
		$q = "select * from newsletter order by postdate desc ";
		$rs = mysql_query($q) or die(mysql_error());
		
		?>
		<table cellpadding="1" cellspacing="1" border="1" >
		<tr><td><strong>Newsletter Title</strong></td><td>Post Date</td><td>Commands</td></tr>
		<?php
		
		while ($row = mysql_fetch_array($rs))
		{
			extract ($row);
			// Display records into table rows.
			echo "<tr><td><strong>$title</strong></td><td>$postdate</td>
			<td><a href=\"$PHP_SELF?mode=edit&news_id=$news_id\">Edit</a>  | 
			<a href=\"$PHP_SELF?mode=delete&news_id=$news_id\">Delete</a></td></tr>";
		}
		?></table><?php
			
	break;
	
	case 'add':
			// Display Adding Form.
		?><form action="nindex.php?mode=insert" method="post">
		<table cellpadding="1"  border="1">
		<tr>
		<td><strong>Newsletter Title:*</strong></td>
		<td><input type="text" name="title" size="30" maxlength="250"></td>
		</tr>
		<tr>
		<td><strong>Content:*</strong><br>HTML Code okay.</td>
		<td><textarea name="content" rows="10" cols="35"></textarea></td>
		</tr>
		<tr><td colspan="2">
		Dispatch Newsletter?<input type="checkbox" name="dispatch" value="yes">
		<p><input type="submit" name="submit"></p></td></tr>
		</table>
		</form> 
		<?php
	
	break;
	
	case 'insert':
		$title = $_POST['title'];
		$content = $_POST['content'];
		$dispatch = $_POST['dispatch'];
		 // check that all fields are filled in
		if (empty($title) || empty($content))
		{
			die ("Error! Please fill in all required fields.");
		}
		
		// insert into database
		$newRecord = "insert into newsletter (news_id, title, content, postdate) 
							VALUES ('','$title','$content', now()) ";
		$rsRecord = mysql_query($newRecord);
		
		if ($rsRecord && $dispatch == 'yes') // administrator wants to send newsletter out
		{
			$lastid= mysql_insert_id();
			// redirect administrator to dispatch mode
			header("Location: newsletter/nindex.php?mode=dispatch&news_id=$lastid");
		}
		else {
			echo "Success! Newsletter recorded.";
		}
	
	break;
	
	case 'delete':
		$news_id = $_GET['news_id'];
		
		$remove = "delete from newsletter where news_id='$news_id' ";
		$rs = mysql_query($remove);
				
		if ($rs)
		{
			echo "Success, newsletter deleted.";
		}
	
	
	break;
	
	case 'edit':
		$news_id = $_GET['news_id'];

		$q = "select * from newsletter where news_id=$news_id ";
		$rs = mysql_query($q) or die(mysql_error());
		
		while ($row = mysql_fetch_array($rs))
		{
			extract($row);
			// Display Editing Form.
			?>
			<form action="<?php echo "nindex.php?mode=update&news_id=$news_id"; ?>" method="post">
			<table cellpadding="1"  border="1">
			<tr>
			<td><strong>Title:</strong></td>
			<td><input type="text" name="title" size="30" maxlength="250" value="<?php echo "$title"; ?>"></td>
			</tr>
			<tr>
			<td><strong>Content:*</strong><br>HTML Code okay.</td>
			<td><textarea name="content" rows="10" cols="35"><?php echo "$content"; ?></textarea></td>
			</tr>
			<tr><td colspan="2">
			Dispatch Newsletter?<input type="checkbox" name="dispatch" value="yes">
			<p><input type="submit" name="submit"></p></td></tr>
			</table>
			</form>
			<?php
		}
	
	break;
	
	case 'update':
		$title = $_POST['title'];
		$content = $_POST['content'];
		$dispatch = $_POST['dispatch'];
		 // check that all fields are filled in
		if (empty($title) || empty($content))
		{
			die ("Error! Please fill in all required fields.");
		}
		
		// Update query
		$update = "update newsletter set title='$title', content='$content' where news_id='$news_id' ";
		$rsUpdate = mysql_query($update);
		
		if ($rsUpdate && ($dispatch=='yes'))
		{
			// Administrator wants to dispatch newsletter, redirect to dispatch mode
			header("Location: nindex.php?mode=dispatch&news_id=$news_id");

		}
		else {
			echo "Success, Newsletter updated.";
		}
	
	break;
	
	case 'dispatch':
		$news_id = $_GET['news_id'];
		// dispatch newsletter to subscribers
		// Obtain newsletter details
		$select = "select  * from newsletter where news_id='$news_id' ";
		$result = mysql_query($select);
		
		$row = mysql_fetch_array($result);
		
		extract($row);
		$plaintext = str_replace("<br>","\r\n",$content);		
		$plaintext = str_replace("<p>","\r\n",$content);
		$plaintext = strip_tags($content);
			
		// obtain subscriber list
		$getList = "select * from subscribers ";
		$rsList = mysql_query($getList);
		
		$headers = "MIME-Version: 1.0\r \n";
		// edit the following 3 variables
		
		$from = "Your Name Here";	
		$fromemail = "abc@yyy.com";
		$subject = "Newsletter from ABC website";
		
		while ($subrow = mysql_fetch_array($rsList))
		{
			extract($subrow);
			if ($format == 't')
			{
				// plain text format
				$headers .= "Content-type: text/plain; charset=iso-8859-1\r \n";
				$headers .= "From: \"$from\" <$fromemail>\r \n";
   				$headers .= "Reply-To: \"$from\" <$fromemail>\r \n";
				$headers .= "X-Mailer: Just My Server";
				$message = $plaintext;

			}
			else {
				// HTML format
				$headers .= "Content-type: text/html; charset=iso-8859-1\r \n";
				$headers .= "From: \"$from\" <$fromemail>\r \n";
   				$headers .= "Reply-To: \"$from\" <$fromemail>\r \n";
				$headers .= "X-Mailer: Just My Server";
				$message = $content;
			}
			// mail it out
			mail($email,$subject,$message,$headers);
			
		}
		echo "Newsletter sent out.";		
	break;
}
?>

In sindex where it says:
$rs = "select from subscriber blah blah"
$rsCheck=mysql_query($rsQcheck);
make it say
$rsCheck=mysql_query($rsQcheck) or die (mysql_error());
and same for any mysql_query($whatever).
Its looking like your querys are returning any results. That can be because the dbs don't exist, or the syntax is bunged up or maybe permissions. Because I can't see your database structure I can't tell which. the mysql_error will tell you what the problem is.

on nindex put the same mysql_error on the insert block too. I don't use extract but once the other errors are cleaned up it should work. If not I'll rewrite that block for you to not use extract.


Its also possible you need to do the insert part of this script once to get some records in there.

Don't worry about the header errors, once the script runs clean they will probably go away.

>......<
I think this script does not like me...

I do not know any alternative ways instead of the extract function because I am not so good with php.
But thank you for the help so far...

Warning: Cannot modify header information - headers already sent by (output started at /home/user/public_html/newsletter/nindex.php:23) in /home/user/public_html/newsletter/nindex.php on line 159

nindex.php

<?php

// Newsletter Administration
// nindex.php

// MySQL Connection Variables (Enter the values)
$hostname='localhost';
$user='user';
$pass='pass';
$dbase='user_newsletter';

$connection = mysql_connect("$hostname" , "$user" , "$pass") or die ("Can't connect to MySQL");
$db = mysql_select_db($dbase , $connection) or die ("Can't select database.");

$mode = $_GET['mode'];		// for globals off

if(!isset($mode) || empty($mode))
{
	$mode = 'list';		// set the default mode to list subscribers
}

?>
<p><strong>Newsletter Administration</strong></p>
<?php

switch ($mode)
{
	case 'list':
		$q = "select * from newsletter order by postdate desc ";
		$rs = mysql_query($q) or die(mysql_error());
		
		?>
		<table cellpadding="1" cellspacing="1" border="1" >
		<tr><td><strong>Newsletter Title</strong></td><td>Post Date</td><td>Commands</td></tr>
		<?php
		
		while ($row = mysql_fetch_array($rs))
		{
			extract ($row);
			// Display records into table rows.
			echo "<tr><td><strong>$title</strong></td><td>$postdate</td>
			<td><a href=\"$PHP_SELF?mode=edit&news_id=$news_id\">Edit</a>  | 
			<a href=\"$PHP_SELF?mode=delete&news_id=$news_id\">Delete</a></td></tr>";
		}
		?></table><?php
			
	break;
	
	case 'add':
			// Display Adding Form.
		?><form action="nindex.php?mode=insert" method="post">
		<table cellpadding="1"  border="1">
		<tr>
		<td><strong>Newsletter Title:*</strong></td>
		<td><input type="text" name="title" size="30" maxlength="250"></td>
		</tr>
		<tr>
		<td><strong>Content:*</strong><br>HTML Code okay.</td>
		<td><textarea name="content" rows="10" cols="35"></textarea></td>
		</tr>
		<tr><td colspan="2">
		Dispatch Newsletter?<input type="checkbox" name="dispatch" value="yes">
		<p><input type="submit" name="submit"></p></td></tr>
		</table>
		</form> 
		<?php
	
	break;
	
	case 'insert':
		$title = $_POST['title'];
		$content = $_POST['content'];
		$dispatch = $_POST['dispatch'];
		 // check that all fields are filled in
		if (empty($title) || empty($content))
		{
			die ("Error! Please fill in all required fields.");
		}
		
		// insert into database
		$newRecord = "insert into newsletter (news_id, title, content, postdate) 
							VALUES ('','$title','$content', now()) ";
		$rsRecord = mysql_query($newRecord) or die (mysql_error());
		
		if ($rsRecord && $dispatch == 'yes') // administrator wants to send newsletter out
		{
			$lastid= mysql_insert_id();
			// redirect administrator to dispatch mode
			header("Location: newsletter/nindex.php?mode=dispatch&news_id=$lastid");
		}
		else {
			echo "Success! Newsletter recorded.";
		}
	
	break;
	
	case 'delete':
		$news_id = $_GET['news_id'];
		
		$remove = "delete from newsletter where news_id='$news_id' ";
		$rs = mysql_query($remove) or die (mysql_error());
				
		if ($rs)
		{
			echo "Success, newsletter deleted.";
		}
	
	
	break;
	
	case 'edit':
		$news_id = $_GET['news_id'];

		$q = "select * from newsletter where news_id=$news_id ";
		$rs = mysql_query($q) or die(mysql_error());
		
		while ($row = mysql_fetch_array($rs))
		{
			extract($row);
			// Display Editing Form.
			?>
			<form action="<?php echo "nindex.php?mode=update&news_id=$news_id"; ?>" method="post">
			<table cellpadding="1"  border="1">
			<tr>
			<td><strong>Title:</strong></td>
			<td><input type="text" name="title" size="30" maxlength="250" value="<?php echo "$title"; ?>"></td>
			</tr>
			<tr>
			<td><strong>Content:*</strong><br>HTML Code okay.</td>
			<td><textarea name="content" rows="10" cols="35"><?php echo "$content"; ?></textarea></td>
			</tr>
			<tr><td colspan="2">
			Dispatch Newsletter?<input type="checkbox" name="dispatch" value="yes">
			<p><input type="submit" name="submit"></p></td></tr>
			</table>
			</form>
			<?php
		}
	
	break;
	
	case 'update':
		$title = $_POST['title'];
		$content = $_POST['content'];
		$dispatch = $_POST['dispatch'];
		 // check that all fields are filled in
		if (empty($title) || empty($content))
		{
			die ("Error! Please fill in all required fields.");
		}
		
		// Update query
		$update = "update newsletter set title='$title', content='$content' where news_id='$news_id' ";
		$rsUpdate = mysql_query($update) or die (mysql_error());
		
		if ($rsUpdate && ($dispatch=='yes'))
		{
			// Administrator wants to dispatch newsletter, redirect to dispatch mode
			header("Location: newsletter/nindex.php?mode=dispatch&news_id=$news_id");

		}
		else {
			echo "Success, Newsletter updated.";
		}
	
	break;
	
	case 'dispatch':
		$news_id = $_GET['news_id'];
		// dispatch newsletter to subscribers
		// Obtain newsletter details
		$select = "select  * from newsletter where news_id='$news_id' ";
		$result = mysql_query($select) or die (mysql_error());
		
		$row = mysql_fetch_array($result);
		
		extract($row);
		$plaintext = str_replace("<br>","\r\n",$content);		
		$plaintext = str_replace("<p>","\r\n",$content);
		$plaintext = strip_tags($content);
			
		// obtain subscriber list
		$getList = "select * from subscriber ";
		$rsList = mysql_query($getList);
		
		$headers = "MIME-Version: 1.0\r \n";
		// edit the following 3 variables
		
		$from = "Your Name Here";	
		$fromemail = "abc@yyy.com";
		$subject = "Newsletter from ABC website";
		
		while ($subrow = mysql_fetch_array($rsList))
		{
			extract($subrow);
			if ($format == 't')
			{
				// plain text format
				$headers .= "Content-type: text/plain; charset=iso-8859-1\r \n";
				$headers .= "From: \"$from\" <$fromemail>\r \n";
   				$headers .= "Reply-To: \"$from\" <$fromemail>\r \n";
				$headers .= "X-Mailer: Just My Server";
				$message = $plaintext;

			}
			else {
				// HTML format
				$headers .= "Content-type: text/html; charset=iso-8859-1\r \n";
				$headers .= "From: \"$from\" <$fromemail>\r \n";
   				$headers .= "Reply-To: \"$from\" <$fromemail>\r \n";
				$headers .= "X-Mailer: Just My Server";
				$message = $content;
			}
			// mail it out
			mail($email,$subject,$message,$headers);
			
		}
		echo "Newsletter sent out.";		
	break;
}
?>

Warning: extract(): First argument should be an array in /home/user/public_html/newsletter/nindex.php on line 177

Warning: Cannot modify header information - headers already sent by (output started at /home/user/public_html/newsletter/nindex.php:23) in /home/user/public_html/newsletter/nindex.php on line 89

I am still getting those errors... What did I do wrong?

This article has been dead for over six months. Start a new discussion instead.