Hi!

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!:

The HTML:

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>###### Contact Form</title>
<style>



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

div.box{
margin:0 auto;
width:500px;
background:#222;
position:relative;
top:50px;
border:1px solid #262626;
}

div.box h1{ 
color:#FFF5CC;
font-size:18px;
text-transform:uppercase;
padding:5px 0 5px 5px;
border-bottom:1px solid #161712;
border-top:1px solid #161712; 
}

div.box label{
width:100%;
display: block;
background:#1C1C1C;
border-top:1px solid #262626;
border-bottom:1px solid #161712;
padding:10px 0 10px 0;
}
div.box label span{
display: block;
color:#bbb;
font-size:12px;
float:left;
width:100px;
text-align:right;
padding:5px 20px 0 0;
}

div.box .input_text{
padding:10px 10px;
width:200px;
background:#262626;
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;
width:350px;
background:#262626;
border-bottom: 1px double #171717;
border-top: 1px double #171717;
border-left:1px double #333;
border-right:1px double #333;
overflow:hidden;
height:150px;
}

div.box .button
{
margin:0 0 10px 0;
padding:4px 7px;
background:#CC0000;
border:0px;
position: relative;
top:10px;
left:382px;
width:100px;
border-bottom: 1px double #660000;
border-top: 1px double #660000;
border-left:1px double #FF0033;
border-right:1px double #FF0033;
}
</style>
</head>

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

            </label>
        </div>
    </form>
</body>
</html>

and the good ol php

<?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)
VALUES
('$_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";

mysql_close($con);

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!!

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/

Have you tried putting a relative path in form action?

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')";

or:

    $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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.