toofan
Technomancer
<?php
if($_POST['submit'] == 'submit')
{
if(!$_POST['email'] || $_POST['email'] == "" || strlen ($_POST['email']) >30)
{
$message = "<p> Problem. Did you enter an email address?</p>";
}
else
{
//open connection to database
mysql_connect("localhost", "root", "abc123") or die ("Failur to communication to database");
mysql_select_db("test") or die ("problem connecting to db. " .mysql_error());
//Insert email address
$as_email = addslashes($_POST['email']);
$tr_email = trim($as_email);
$query = "insert into mailinglist (ID, Email, Source)
values (null, '$tr_email', 'www.example.com/newletter_signup.html')";
$result = mysql_query($query);
if(mysql_affected_rows() == 1)
{
echo "<p> Your information has been recorded.</p>";
$noform_var = 1;
}
else
{
error_log(mysql_error());
$message = "<p>Something went wrong with your signup attempt.</p>";
}
}
//show the form in every case except successful submission
if (!$noform_var) {
$thisfile = $_SERVER['PHP_SELF'];
$message .= <<< EOMSG
<P>Enter your email address and we will send you our weekly newsletter.</P>
<FORM METHOD="post" ACTION="$thisfile">
<INPUT TYPE="text" SIZE=25 NAME="email">
<BR><BR>
<INPUT TYPE="submit" NAME="submit" VALUE="submit">
</FORM>
EOMSG;
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>email newsletter</title>
<style type="text/css">
<!--
body, p {
color:#000099;
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:12pt
}
H1 {
color:#990000;
font-family:Arial, Helvetica, sans-serif;
font-size:14pt
}
-->
</style>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="10">
<tr>
<td width="17%" bgcolor="#f0f8ff"> </td>
<td width="83%" align="center" valign="top" bgcolor="#fffff0"><h1>News Letter SignUp Form</h1>
<?php echo $message; ?>
</td>
</tr>
</table>
</body>
</html>
Friends Help me to debug this code. I don't know whats wrong with this code. Acc to me their is some problem with the code marked with blue.
Thanks friends.