I have a contact form that won't...do anything!! I'm kinda new at this, although I've been succseful on MS SQL for YEARS...Can some one shed light on this? Thanx in advance!:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>###### Contact Form</title>

*{ margin:0; padding:0;}
body{ font:100% normal Arial, Helvetica, sans-serif; background:#161712;}
form,input,select,textarea{margin:0; padding:0; color:#fff;}

margin:0 auto;
border:1px solid #262626;

div.box h1{ 
padding:5px 0 5px 5px;
border-bottom:1px solid #161712;
border-top:1px solid #161712; 

div.box label{
display: block;
border-top:1px solid #262626;
border-bottom:1px solid #161712;
padding:10px 0 10px 0;
div.box label span{
display: block;
padding:5px 20px 0 0;

div.box .input_text{
padding:10px 10px;
border-bottom: 1px double #171717;
border-top: 1px double #171717;
border-left:1px double #333;
border-right:1px double #333;

div.box .message{
padding:7px 7px;
border-bottom: 1px double #171717;
border-top: 1px double #171717;
border-left:1px double #333;
border-right:1px double #333;

div.box .button
margin:0 0 10px 0;
padding:4px 7px;
position: relative;
border-bottom: 1px double #660000;
border-top: 1px double #660000;
border-left:1px double #FF0033;
border-right:1px double #FF0033;

     <form action="http://www.######.com/cgi-bin/insert.php" method="post">
          <div class="box">
            <h1>Denver Mortgage Loan Contact Form</h1>
               <span>First name *</span>
               <input type="text" class="input_text" name="name_first" id="name_first"/>
               <span>Middle Initial *</span>
               <input type="text" class="input_text" name="name_mi" id="name_mi"/>
               <span>Last name *</span>
               <input type="text" class="input_text" name="name_last" id="name_last"/>
               <span>Social Security Number *</span>
               <input type="text" class="input_text" name="SSN" id="SSN"/>
                <span>Street Number *</span>
                <input type="text" class="input_text" name="AddressStreet" id="AddressStreet"/>
                <span>City *</span>
                <input type="text" class="input_text" name="Address_City" id="Address_City"/>
                <span>Apt/Suite No. *</span>
                <input type="text" class="input_text" name="Apt_ste" id="Apt_ste"/>
                <span>Phone Number *</span>
                <input type="text" class="input_text" name="phone" id="phone"/>
                <span>Cell Phone Number *</span>
                <input type="text" class="input_text" name="cphone" id="cphone"/>
                <span>Email Address *</span>
                <input type="text" class="input_text" name="email" id="email"/>
                <span>Do You Own Or Rent (Please put Own or Rent) *</span>
                <input type="text" class="input_text" name="own_rent" id="own_rent"/>
                <span>Comments *</span>
                <textarea class="message" name="comments" id="comments"></textarea>
                 <input type="submit" class="button" value="Submit Form" />


and the good ol php

$con = mysql_connect("#######","########","########");
if (!$con)
  die('Could not connect: ' . mysql_error());

mysql_select_db("my_db", $con);

$sql="INSERT INTO $####### (name_first, name_mi, name_last, AddressStreet, Address_City, PostalCode, Apt_Ste, phone, cphone, own_rent)
('$_POST[name_first]','$_POST[ name_mi]','$_POST[name_last]','$_POST[AddressStreet]','$_POST[Address_City]','$_POST[PostalCode]','$_POST[Apt_Ste]','$_POST[phone]','$_POST[cphone]','$_POST[own_rent]')";

if (!mysql_query($sql,$con))
  die('Error: ' . mysql_error());
echo "1 record added";


So, here 'tis, and no worky worky.  Of course, I am sure I got something erroneous, but for the life of...the script... I am clueless.  Please help!!

Recommended Answers

Do you see any errors? Just "not working" is kind of vague. Please describe what happens.

Jump to Post

Have you tried putting a relative path in form action?

Jump to Post

All 8 Replies

Do you see any errors? Just "not working" is kind of vague. Please describe what happens.

Nothing...no erros, no out put, just a blank page and no update to the database...mySql 5.5, php 5.4 Great site at http://www.phptherightway.com/

I would highly recommend sanitising the data before input, using an if test to check $_POST exists before any DB operations, taking the post vars and assigning to new variables. I don't think '$_POST[key]' is going to parse correctly either:

$name = mysql_real_escape_string(trim($_POST['name']));
$address = mysql_real_escape_string(trim($_POST['address']));
$sql = "INSERT INTO mytable (name, address) VALUES ('$name', '$address')";


    $sql = "INSERT INTO mytable (name, address) VALUES ('".$_POST['name'])."', '".$_POST['address']."')";

Also, check the folder that contains the files for an error-log as nothing is going to the screen.

Thank You for the replies!! I've done the contact form myself in dev, there are *'s, but no requirement checks as of yet, I want the thing to work first! I can message the URL

pritaeas I edited the form as such ../cgi-bin/insert.php and got:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@denvermortgageloan.skintense.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Server log showed nothing, I'll try script on another hosting account I have!

Still Clueless, Mike

Is your PHP really at the bottom of the page? If so, move it to the top before any html etc and add in an if statement to check if the form has been posted (i.e. if (isset($_POST)) { ...... Do your DB stuff here ..... }

Does your table name come from a variable as I notice you have written it as $####### in your query? If so then where is that variable being definined and if not then it should just be the table name.

Have you tried printing out your posted data to make sure it is being sent? If not then use print_r($_POST) to check what data (if any) is being posted.

Hi Simply pixie, as I pointed out, the php is in insert.php, on ../cgi-bin/index.php It may have sumpin to do with the $[, I'm working on it as time permits! Thanks for Comin' By!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.