Help with a mailing list

Discussion in 'PHP' started by DmitryS, Mar 4, 2011.

  1. #1
    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");
    
    }
    
    ?>
    Code (markup):
    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>
    Code (markup):
    Let me know what else you may need....
     
    DmitryS, Mar 4, 2011 IP
  2. property

    property Peon

    Messages:
    134
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you give @mail function to script code
     
    property, Mar 5, 2011 IP
  3. Mike Griffiths

    Mike Griffiths Peon

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Your query isn't working, I'd guess it's either because your table has been changed/deleted or your database isn't connecting.

    Either way, you can find out by changing the line:
    	$result2=mysql_query($sql2) or die("select fails");
    Code (markup):
    to:
    	$result2=mysql_query($sql2) or die(mysql_error());
    Code (markup):
    This will give you an error.

    On a side note, I've noticed you're not escaping the queries. This means that I can VERY easily wipe your entire database by setting the 'email' field as some simple SQL - this is known as an SQL injection. It's entirely possible that someone has done this to your database already which is why the query is failing. This is a real problem and shouldn't be ignored, malicious people set up crawlers to trawl the internet trying SQL injections on every form they find, just for something to do it seems.
     
    Mike Griffiths, Mar 5, 2011 IP