Jump to content

[SOLVED] php and mysql contact Script problem


ace2721

I have a problem when I check the mysql database there is always blank entrys and I mean there could be upto 1000s.  

  1. 1. I have a problem when I check the mysql database there is always blank entrys and I mean there could be upto 1000s.

    • php contact Script problem
      0
    • php contact Script problem
      0


Recommended Posts

Hi Guys got to say what a fantastic forum, posted a question yesterday in 30 minutes my problem was solved, so I thought I would ask another, as you can see below I have made a contact form which send an email to me and inputs into mysql database, I have a problem when I check the mysql database there is always blank entry's and I mean there could be up to 1000s.

 

can any one through some light on the matter as I am new to php and mysql so I am really stuck to what I should do

 

thanks again guys and have a great Christmas

 

 

<?php

 

// Connect to database

$hostname = "ip address";

$username = "username";

$password = "password";

$dbname = "database";

$usertable = "pitman";

$f_name = $_REQUEST['f_name'];

$postcode = $_REQUEST['postcode'];

$tel = $_REQUEST['tel'];

$mobile = $_REQUEST['mobile'];

$email = $_REQUEST['email'];

$course = $_REQUEST['course'];

 

mysql_connect($hostname, $username, $password) or DIE("Unable to connect to MySQL server $hostname");

 

$selected = mysql_select_db($dbname) or DIE("Could not select requested db $dbname");

 

 

$query = "INSERT INTO database (id, f_name, postcode, tel, mobile, email, course, pdate) VALUES ('', '$f_name', '$postcode', '$tel', '$mobile', '$email' , '$course', NOW())";

 

 

$result = mysql_query($query) or DIE("Could not Execute Query on table $usertable");

 

mysql_close;

 

$errmsg  = ''; // error message

$f_name  = ''; // sender's name

$postcode  = ''; // sender's name

$tel = ''; // message tel

$mobile = ''; // message tel

$email  = ''; // sender's email addres

$course = ''; // the message itself

 

if(isset($_POST['send']))

{

  $f_name  = $_POST['f_name'];

  $postcode  = $_POST['postcode'];

  $tel = $_POST['tel'];

  $mobile = $_POST['mobile'];

  $email = $_POST['email'];

  $course = $_POST['course'];

 

  if(trim($f_name) == '')

  {

      $errmsg = 'Please enter your name';

  }

  else if(trim($postcode) == '')

  {

      $errmsg = 'Please enter your postcode';

  }

  else if(trim($tel) == '')

  {

      $errmsg = 'Please enter Your Telephone Number:';

  }

  else if(trim($mobile) == '')

  {

      $errmsg = 'Please enter your mobile';

  }   

  else if(trim($email) == '')

  {

      $errmsg = 'Please enter your email address';

  }

  else if(!isEmail($email))

  {

      $errmsg = 'Your email address is not valid';

  }

  else if(trim($course) == '')

  {

      $errmsg = 'Please enter the course your interested in';

  } 

  if($errmsg == '')

  {

      if(get_magic_quotes_gpc())

      {

        $tel = stripslashes($tel);

        $message = stripslashes($message);

      } 

     

      // the email will be sent here

      $to      = "my@domain";

     

      $user_message .= "Name: $f_name \r\n";

        $user_message .= "postcode: $postcode \r\n";

        $user_message .= "tel: $tel \r\n";

        $user_message .= "mobile: $mobile \r\n";

        $user_message .= "email: $email \r\n";

        $user_message .= "course: $course \r\n";

        $headers = "- web Enquiry \r\n";

        $headers .= "Reply-To: $email";

     

      mail('[email protected]','website Enquiry',$user_message,$headers);

?>

<div align="center" class="boldenquire">Your message has been sent </div>

<?php

  }

}

 

 

if(!isset($_POST['send']) || $errmsg != '')

{

?>

<div align="center" class="ermsg"><?=$errmsg;?></div>

<form  method="post" name="msgform" id="msgform">

  <table border="0" align="center" cellpadding="2" cellspacing="1" class="maincell">

    <tr>

      <td align="center" colspan="2"><span class="boldenquire">        Please fill in your details <br />

        for more information.</span></td>

    </tr>

    <tr>

      <td>Your Name</td>

      <td><input name="f_name" type="text" class="eqform" value="<?=$f_name;?>" style="width:100px" /></td>

    </tr>

    <tr>

      <td>Nearest centre</td>

      <td><label>

        <select name="postcode" size="1" class="eqform" style="width:100px" value=" <?=$postcode;?>">

          <option value="Ashford">Ashford</option>

          <option value="Bromley">Bromley</option>

          <option value="Chatham">Chatham</option>

          <option value="Dartford">Dartford</option>

          <option value="Gravesend">Gravesend</option>

          <option value="Maidstone">Maidstone</option>

          <option value="Tunbridge Wells">Tunbridge Wells</option>

        </select>

      </label></td>

    </tr>

    <tr>

      <td>Tel </td>

      <td><input name="tel" type="text" class="eqform" value="<?=$tel;?>" style="width:100px" /></td>

    </tr>

    <tr>

      <td>Mobile</td>

      <td><input name="mobile" type="text" class="eqform" value="<?=$mobile;?>" style="width:100px" /></td>

    </tr>

    <tr>

      <td>Email </td>

      <td><input name="email" type="text" class="eqform" value="<?=$email;?>" style="width:100px" /></td>

    </tr>

    <tr>

      <td>Course of interest </td>

      <td><input name="course" type="text" class="eqform" value="<?=$course;?>" style="width:100px" />      </td>

    </tr>

    <tr align="center">

      <td colspan="2"><input name="send" type="submit" value="Send Message" onclick="return checkForm();" /></td>

    </tr>

    <tr align="left">

      <td colspan="2"><br />

          <script language="JavaScript">

      var addr = '';

      var host = '';

      var email = '';

      document.write(email);

      </script></td>

    </tr>

  </table>

</form>

<?php

}

 

function isEmail($email)

{

  return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i"

        ,$email));

}

?>

sorry russel I thought the problem was solved if I show you my script can you see If i have moved it to the right place

 

what i moved is in red

 

<div id="enquire_form">

<?php

 

// Connect to database

$hostname = "";

$username = "";

$password = "";

$dbname = "";

$usertable = "";

$f_name = $_REQUEST['f_name'];

$postcode = $_REQUEST['postcode'];

$tel = $_REQUEST['tel'];

$mobile = $_REQUEST['mobile'];

$email = $_REQUEST['email'];

$course = $_REQUEST['course'];

 

mysql_connect($hostname, $username, $password) or DIE("Unable to connect to MySQL server $hostname");

 

$selected = mysql_select_db($dbname) or DIE("Could not select requested db $dbname");

 

 

$result = mysql_query($query) or DIE("Could not Execute Query on table $usertable");

 

 

 

$errmsg  = ''; // error message

$f_name  = ''; // sender's name

$postcode  = ''; // sender's name

$tel = ''; // message tel

$mobile = ''; // message tel

$email  = ''; // sender's email addres

$course = ''; // the message itself

 

if(isset($_POST['send']))

{

  $f_name  = $_POST['f_name'];

  $postcode  = $_POST['postcode'];

  $tel = $_POST['tel'];

  $mobile = $_POST['mobile'];

  $email = $_POST['email'];

  $course = $_POST['course'];

 

  if(trim($f_name) == '')

  {

      $errmsg = 'Please enter your name';

  }

  else if(trim($postcode) == '')

  {

      $errmsg = 'Please enter your postcode';

  }

  else if(trim($tel) == '')

  {

      $errmsg = 'Please enter Your Telephone Number:';

  }

  else if(trim($mobile) == '')

  {

      $errmsg = 'Please enter your mobile';

  }   

  else if(trim($email) == '')

  {

      $errmsg = 'Please enter your email address';

  }

  else if(!isEmail($email))

  {

      $errmsg = 'Your email address is not valid';

  }

  else if(trim($course) == '')

  {

      $errmsg = 'Please enter the course your interested in';

  } 

  if($errmsg == '')

  {

      if(get_magic_quotes_gpc())

      {

        $tel = stripslashes($tel);

        $message = stripslashes($message);

      } 

     

      $query = "INSERT INTO pitman (id, f_name, postcode, tel, mobile, email, course, pdate) VALUES ('', '$f_name', '$postcode', '$tel', '$mobile', '$email' , '$course', NOW())";

     

      mysql_close();

   

      // the email will be sent here

      $to      = "";

     

      $user_message .= "Name: $f_name ";

        $user_message .= "postcode: $postcode ";

        $user_message .= "tel: $tel ";

        $user_message .= "mobile: $mobile ";

        $user_message .= "email: $email ";

        $user_message .= "course: $course ";

        $headers = "-  ";

        $headers .= "Reply-To: $email";

     

      mail('',,$user_message,$headers);

?>

<div align="center" class="boldenquire">Your message has been sent </div>

<?php

  }

}

 

 

if(!isset($_POST['send']) || $errmsg != '')

{

?>

<div align="center" class="ermsg"><?=$errmsg;?></div>

<form  method="post" name="msgform" id="msgform">

  <table border="0" align="center" cellpadding="2" cellspacing="1" class="maincell">

    <tr>

      <td align="center" colspan="2"><span class="boldenquire">        Please fill in your details <br />

        for more information.</span></td>

    </tr>

    <tr>

      <td>Your Name</td>

      <td><input name="f_name" type="text" class="eqform" value="<?=$f_name;?>" style="width:100px" /></td>

    </tr>

    <tr>

      <td>Nearest centre</td>

      <td><label>

        <select name="postcode" size="1" class="eqform" style="width:100px" value=" <?=$postcode;?>">

          <option value="Ashford">Ashford</option>

          <option value="Bromley">Bromley</option>

          <option value="Chatham">Chatham</option>

          <option value="Dartford">Dartford</option>

          <option value="Gravesend">Gravesend</option>

          <option value="Maidstone">Maidstone</option>

          <option value="Tunbridge Wells">Tunbridge Wells</option>

        </select>

      </label></td>

    </tr>

    <tr>

      <td>Tel </td>

      <td><input name="tel" type="text" class="eqform" value="<?=$tel;?>" style="width:100px" /></td>

    </tr>

    <tr>

      <td>Mobile</td>

      <td><input name="mobile" type="text" class="eqform" value="<?=$mobile;?>" style="width:100px" /></td>

    </tr>

    <tr>

      <td>Email </td>

      <td><input name="email" type="text" class="eqform" value="<?=$email;?>" style="width:100px" /></td>

    </tr>

    <tr>

      <td>Course of interest </td>

      <td><input name="course" type="text" class="eqform" value="<?=$course;?>" style="width:100px" />      </td>

    </tr>

    <tr align="center">

      <td colspan="2"><input name="send" type="submit" value="Send Message" onclick="return checkForm();" /></td>

    </tr>

    <tr align="left">

      <td colspan="2"><br />

          <script language="JavaScript">

      var addr = '';

      var host = '';

      var email = '';

      document.write(email);

      </script></td>

    </tr>

  </table>

</form>

<?php

}

 

function isEmail($email)

{

  return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]]).)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]).){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i"

        ,$email));

}

?>

</div>

also, and sorry for the double post (I want the email notification to be resent to ace) your mysql_close..

 

ahhh I'll just move it for you :)

 

<div id="enquire_form">
<?php

// Connect to database
$hostname = "";
$username = "";
$password = "";
$dbname = "";
$usertable = "";
$f_name = $_REQUEST['f_name'];
$postcode = $_REQUEST['postcode'];
$tel = $_REQUEST['tel'];
$mobile = $_REQUEST['mobile'];
$email = $_REQUEST['email'];
$course = $_REQUEST['course'];

mysql_connect($hostname, $username, $password) or DIE("Unable to connect to MySQL server $hostname");

$selected = mysql_select_db($dbname) or DIE("Could not select requested db $dbname");



$errmsg  = ''; // error message
$f_name   = ''; // sender's name
$postcode   = ''; // sender's name
$tel = ''; // message tel
$mobile = ''; // message tel
$email   = ''; // sender's email addres
$course = ''; // the message itself

if(isset($_POST['send']))
{
   $f_name   = $_POST['f_name'];
   $postcode   = $_POST['postcode'];
   $tel = $_POST['tel'];
   $mobile = $_POST['mobile'];
   $email = $_POST['email'];
   $course = $_POST['course'];
   
   if(trim($f_name) == '')
   {
      $errmsg = 'Please enter your name';
   }
   else if(trim($postcode) == '')
   {
      $errmsg = 'Please enter your postcode';
   }
   else if(trim($tel) == '')
   {
      $errmsg = 'Please enter Your Telephone Number:';
   }
   else if(trim($mobile) == '')
   {
      $errmsg = 'Please enter your mobile';
   }    
   else if(trim($email) == '')
   {
      $errmsg = 'Please enter your email address';
   }
   else if(!isEmail($email))
   {
      $errmsg = 'Your email address is not valid';
   }
   else if(trim($course) == '')
   {
      $errmsg = 'Please enter the course your interested in';
   }   
   if($errmsg == '')
   {
      if(get_magic_quotes_gpc())
      {
         $tel = stripslashes($tel);
         $message = stripslashes($message);
      }   
      
      $query = "INSERT INTO pitman (id, f_name, postcode, tel, mobile, email, course, pdate) VALUES ('', '$f_name', '$postcode', '$tel', '$mobile', '$email' , '$course', NOW())";
      
      $result = mysql_query($query) or DIE("Could not Execute Query on table $usertable");     
      // the email will be sent here
      $to      = "";
      
      $user_message .= "Name: $f_name "; 
        $user_message .= "postcode: $postcode ";
        $user_message .= "tel: $tel "; 
        $user_message .= "mobile: $mobile "; 
        $user_message .= "email: $email "; 
        $user_message .= "course: $course ";
        $headers = "-  "; 
        $headers .= "Reply-To: $email"; 
      
      mail('',,$user_message,$headers);
?>
<div align="center" class="boldenquire">Your message has been sent </div>
<?php
   }
}
mysql_close();

if(!isset($_POST['send']) || $errmsg != '')
{
?>
<div align="center" class="ermsg"><?=$errmsg;?></div>
<form  method="post" name="msgform" id="msgform">
  <table border="0" align="center" cellpadding="2" cellspacing="1" class="maincell">
    <tr>
      <td align="center" colspan="2"><span class="boldenquire">        Please fill in your details <br />
        for more information.</span></td>
    </tr>
    <tr>
      <td>Your Name</td>
      <td><input name="f_name" type="text" class="eqform" value="<?=$f_name;?>" style="width:100px" /></td>
    </tr>
    <tr>
      <td>Nearest centre</td>
      <td><label>
        <select name="postcode" size="1" class="eqform" style="width:100px" value=" <?=$postcode;?>">
          <option value="Ashford">Ashford</option>
          <option value="Bromley">Bromley</option>
          <option value="Chatham">Chatham</option>
          <option value="Dartford">Dartford</option>
          <option value="Gravesend">Gravesend</option>
          <option value="Maidstone">Maidstone</option>
          <option value="Tunbridge Wells">Tunbridge Wells</option>
        </select>
      </label></td>
    </tr>
    <tr>
      <td>Tel </td>
      <td><input name="tel" type="text" class="eqform" value="<?=$tel;?>" style="width:100px" /></td>
    </tr>
    <tr>
      <td>Mobile</td>
      <td><input name="mobile" type="text" class="eqform" value="<?=$mobile;?>" style="width:100px" /></td>
    </tr>
    <tr>
      <td>Email </td>
      <td><input name="email" type="text" class="eqform" value="<?=$email;?>" style="width:100px" /></td>
    </tr>
    <tr>
      <td>Course of interest </td>
      <td><input name="course" type="text" class="eqform" value="<?=$course;?>" style="width:100px" />      </td>
    </tr>
    <tr align="center">
      <td colspan="2"><input name="send" type="submit" value="Send Message" onclick="return checkForm();" /></td>
    </tr>
    <tr align="left">
      <td colspan="2"><br />
          <script language="JavaScript">
      var addr = '';
      var host = '';
      var email = '';
      document.write(email);
      </script></td>
    </tr>
  </table>
</form>
<?php
}

function isEmail($email)
{
   return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]]).)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]).){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i"
         ,$email));
}
?>
</div>

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.