Jump to content

Help with a mailing list


bslevin

Recommended Posts

Hello,

 

I know very little about PHP, i am a graphics and HTML guy :), i had a simple mailing list script up on a clients page for a couple years, and now all of a sudden it has stopped working. When you enter your name, and email, you get "select fails" and it does not get added to the database.

 

Here is the code, any help would be great, i am lost since nothign has changed, but it just stoppped working.

 

from the config.php file

function insert_mail() {

$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];


$sql2="select * from mail where email='$email'";
$result2=mysql_query($sql2) or die("select fails");
$no=mysql_num_rows($result2);



if ($no==0) {


	$sql = "insert into mail(id,fname,lname,email) values(NULL,'$fname','$lname','$email')";
	$result = mysql_query($sql) or die("insert fails");

	echo "Email added to list: " . LISTNAME;

} else {

	echo "Email Address Already Exists in List: " . LISTNAME;

}



}

function delete_mail() {

    $email = $_POST['email'];

    if ($email == "") {
       $email = $_GET['email'];
    }

    $sql2="select * from mail where email='$email'";
    $result2=mysql_query($sql2) or die("select  fails");
    $no=mysql_num_rows($result2);

    if ($no==0) {
       echo "Your email was not found in the list: " . LISTNAME;
    } else {
       echo "Your email was unsubscribed from the list: " . LISTNAME;
    }

    $sql2="delete from mail where email='$email'";
    $result2=mysql_query($sql2) or die("unsubscribe failed, please try again");

}

?>

 

From the HTML

 

<center>

<form action='<? echo BASEHREF; ?>index.php' method=post>

<TABLE BORDER=0 ALIGN=center>
<TR>

	<TD><b>first name</b></TD>
	<TD><INPUT TYPE=text name=fname></TD>

</TR>


<TR>
	<TD><b>last name</b></TD>
	<TD><INPUT TYPE=text name=lname></TD>
</TR>

<TR>
	<TD><b>email</b></tD>
	<TD><INPUT TYPE=text name=email></td>
</tR>

<TR>
	<TD colspan=2 align=center><INPUT TYPE=submit value=join> <INPUT TYPE=reset value=reset><BR></TD>
</tR>

</TABLE>


</FORM>

</center>

 

Let me know what else you may need....

Link to comment
https://forums.phpfreaks.com/topic/229626-help-with-a-mailing-list/
Share on other sites

Try adding a line of error message to know it the problem is from the database:

 

if ($no==0) {

 

 

$sql = "insert into mail(id,fname,lname,email) values(NULL,'$fname','$lname','$email')";

//$result = mysql_query($sql) or die("insert fails");

              // replace this line with:

                $result = mysql_query($sql) or die("insert fails ".mysq_error());

              //this will tell where the error is from, if it is a database problem

echo "Email added to list: " . LISTNAME;

 

} else {

 

Where ever you have a line like

<?php
$result2=mysql_query($sql2) or die("select fails");
?>

change it to something like

<?php
$result2=mysql_query($sql2) or die("Problem with the query: $sql2 at line " . __LINE__ . "<br>" . mysql_error());
?>

 

Ken

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.