The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> no luck inserting data into database
post Nov 9 2015, 10:44 AM
Post #1

Advanced Member

Group: Members
Posts: 165
Joined: 12-November 13
Member No.: 19,963

Hi, it has been a while since I have worked with PHP & MYSQL. Can someone help me understand why information from a form isn't being inserted in the database. The connection is fine.


ini_set('display_errors', 1);

if ($_POST)
    $error = array();

    if (empty($_POST['fname']))
        $error['fname'] = "<span class='error'>Please enter your first name.</span>";
    if (empty($_POST['lname']))
        $error['lname'] = "<span class='error'>Please enter your last name.</span>";

    if (!count($error))

        {        //Do something
        die("Do Something here");
    if(isset($_POST['submit'])) {
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$orgName = $_POST['orgName'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zipcode = $_POST['zipcode'];
$phone = $_POST['phone'];
$fax = $_POST['fax'];
$email = $_POST['email'];
$confirmEmail = $_POST['confirmEmail'];
$projectOptions = $_POST['projectOptions'];
$projectOverview = $_POST['projectOverview'];
$year = $_POST['year'];
$services=array('social media', 'web content management', 'marketing material creation', 'SEO', 'video editing' , 'web design');
$sql="INSERT INTO clients & #40;fname,lname,orgName,address,city,state,zipcode,phone,fax,email,confirmEmail,
        VALUES  ('$_POST[fname]','$_POST[lname]','$_POST[orgName]','$_POST[address]','$_POST[city]','$_POST[state]','$_POST[zipcode]','$_POST[phone]','$_POST[fax]','$_POST[email]','$_POST[confirmEmail]','$_POST[projectOptions]','$_POST[projectOverview]','$_POST[year]' )";
<!doctype html>
      <meta charset="utf-8">
      <style type="text/css">
        #contactForm label, #contactForm input {
      <title>Untitled Document</title>
        <div id="contactForm">  
         <form action ="contactUs.php" method="post">
           <label for "fname"> First Name:</label>
                  <input id = "fname" type="text" name="fname" size="15" value ="<?php echo !empty($_POST['fname']) ? $_POST['fname'] : '';?>" >    <?php echo !empty($error['fname']) ? $error['fname'] : '';?>
            <label for "lname">Last Name:</label>
                   <input type="text" name="lname" size="20"><?php echo !empty($error['lname']) ? $error['lname'] : '';?>
            <label for="orgName">Organization's Name:</label>
            <input type="text" name="orgName" maxlength="50">
            </label><br />
            <label> <!--new row -->  
                <label for "address">Street Address: </label>
                  <input id = "address" type="text" name="address" size="15" maxlength="50">
                <label id="city">City: </label>
                  <input id = "city" type="text" name="city" size="10" maxlength="25">
                <label  for "state"> State:    </label>
                  <select id  = "state" name = "state"  value="">
                     <option value ="Please choose a state">
                        Please choose a state
                     <?php states($state); ?>
                 <label for "zipcode">Zipcode:</label>
                  <input id = "zipcode" type="number" name="zipcode" size="5" maxlength="5">
             </label><br />
             <label> <!--new row -->
              <label for "phone">  Phone Number:(including area code)  <br /> </label>
                  <input type="text" name="phone" size="10" maxlength="10">  
            <label for="fax">Fax Number: (including area code)
                  <input type="text" name="fax" size="10" maxlength="10">
            </label><br />
            <label> <!--new row-->
                <label for="email">Email: </label>
                  <input type="text" id = "email" name="email" />
                <label for="confirmEmail"> Confirm Email:</label>
                  <input type="text" id = "confirmEmail" name="ConfirmEmail" />
</label><br />
            <label> <!--new row -->
            <label for "projectChoices"> What would you like help with?  <br /></label>
             <table id="projectOptions">
                     <tr span=2>
                        <td><input type="checkbox" name="SocialMedia">Social Media </td>
                        <td><input type="checkbox" name="WebContentManagement">Web Content Management     </td>
                        <td><input type="checkbox" name="MarketingMaterials">Marketing Material Creation  </td>
                        <td><input type="checkbox" name="SEO">SEO (Search Engine Optimization)     </td>
                        <td><input type="checkbox" name="VideoEditing"> Video Editing  </td>
                        <td><input type="checkbox" name="WebDesign">Web Design      </td>
            <label for="projectOverview"> Overview about the project:</label><textarea rows="5" cols="10"></textarea>  <br />
If you are not a robot, what year is it? <input type="text" name="year" size="4" maxlength="4"><br />
<input type="submit" name="submit" value="Contact Me!">
<input type="reset">
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Reply to this topicStart new topic
post Nov 13 2015, 04:22 AM
Post #2

Programming Fanatic

Group: Members
Posts: 5,146
Joined: 23-August 06
From: Europe
Member No.: 9

Good point, but there should not be a space between the & and the # should there?

True, w/o the space, it's Unicode for (. (Though the forum tends to render the character instead of the code if no space is added.)
But I don't see why using Unicode for that in the first place.

This post has been edited by Frederiek: Nov 13 2015, 04:24 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:


- Lo-Fi Version Time is now: 17th October 2019 - 11:38 PM