bslevin Posted March 5, 2011 Share Posted March 5, 2011 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 More sharing options...
sayjoy Posted March 5, 2011 Share Posted March 5, 2011 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 { Link to comment https://forums.phpfreaks.com/topic/229626-help-with-a-mailing-list/#findComment-1183111 Share on other sites More sharing options...
bslevin Posted March 5, 2011 Author Share Posted March 5, 2011 I did that and i still get the same result.. it says "Select Fails" Link to comment https://forums.phpfreaks.com/topic/229626-help-with-a-mailing-list/#findComment-1183120 Share on other sites More sharing options...
kenrbnsn Posted March 5, 2011 Share Posted March 5, 2011 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 Link to comment https://forums.phpfreaks.com/topic/229626-help-with-a-mailing-list/#findComment-1183145 Share on other sites More sharing options...
bslevin Posted March 5, 2011 Author Share Posted March 5, 2011 Ok i did that and here is what i got... Problem with the query: select * from mail where email='[email protected]' at line 61 No database selected Link to comment https://forums.phpfreaks.com/topic/229626-help-with-a-mailing-list/#findComment-1183214 Share on other sites More sharing options...
bslevin Posted March 5, 2011 Author Share Posted March 5, 2011 OK it is working now!! Thanks for all your help! After seeing that message i found out that the datbase had been deleted and reinstalled but the username had never been reattached to it. Thanks again! Link to comment https://forums.phpfreaks.com/topic/229626-help-with-a-mailing-list/#findComment-1183216 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.