Results 1 to 5 of 5

Thread: PHP form and MySQL

Hybrid View

  1. #1
    Join Date
    Dec 2013

    PHP form and MySQL


    Am getting a error when am trying connect inputs from my contact form to my database. Please have a look at following code

    HTML Code:
    <div id='frmFormMailContainer'>
    <h2>Contact Us</h2><form name="Contacts" method="post" action="Insert.php">
    <div class="formItem" id="fnamef">
    <label for="FirstName" class="testLabel">First name</label>
      <input type="text" name="FirstName" id="FirstName">
    <div id="lnamef">
    <label for="LastName" class="textLabel">Last name</label>
    <input type="text" name="LastName" id="LastName">
    <div id="emailf">
    <label for="Email" class="textLabel">Email </label>
    <input type="text" name="Email" id="Email">
    <div id="mobilef">
    <label for="Mobile" class="textLabel">Mobile</label>
    <input type="tel" name="Mobile" id="Mobile">
    <div id="Message">
    <label for="Message" class="textLabel">Message</label>
    <input type="text" name="Message" id="Message">
    <div id="submitf">
    <input type="submit" name="submit" id="submit" value="Submit">
    </form> </div>
    and PHP
    PHP Code:
    <!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>Untitled Document</title>

    $FirstName $_POST["FirstName"];
    $LastName $_POST["LastName"];
    $Email $_POST["Email"];
    $Mobile $_POST["Mobile"];
    $Message $_POST["Message"];


            or die (
    "NO connection");

        or die (
    "Brak polaczenia");

    $sql "INSERT INTO 'test1'.'contacts' ('FirstName', 'LastName', 'Email', 'Mobile', 'Message')
                VALUES ('
    $FirstName', '$LastName', '$Email', '$Mobile', '$Message');";

        or die (


  2. #2
    Join Date
    Nov 2013
    I think you may be having a problem with your connect function call and your insert statement.

    INSERT INTO contacts

    Since you are creating variables for you database info, you should use them, and also specify what database you want to connect to in the call.

    PHP Code:
    Then your insert statement should look like this. I also noticed an extra semicolon at the end of the values.

    PHP Code:
    $sql "INSERT INTO 'test1'.'contacts' ('FirstName', 'LastName', 'Email', 'Mobile', 'Message')
              VALUES ('
    $FirstName', '$LastName', '$Email', '$Mobile', '$Message')"
    Last edited by wevie; 12-03-2013 at 10:41 PM. Reason: left out a closing php tag

  3. #3
    Join Date
    Nov 2013
    My biggest issue with your code is mysql please please please look into mysqli or PDO
    ok so your code
    bad code below -> you don't need to declare the database in the query
    $sql = "INSERT INTO 'test1'.'contacts' ('FirstName', 'LastName', 'Email', 'Mobile', 'Message') 
                VALUES ('$FirstName', '$LastName', '$Email', '$Mobile', '$Message');";
    good code. notice also i have used ticks ` and not single quotes ' . singles quotes should only be used in the VALUES
    $sql = "INSERT INTO `contacts` (`FirstName`, `LastName`, `Email`, `Mobile`, `Message`) 
                VALUES ('$FirstName', '$LastName', '$Email', '$Mobile', '$Message');";
    hopefully this will get you started towards fixing your code.

  4. #4
    Join Date
    Nov 2013
    Why the ticks? I have queries written that is working without the ticks. I am most curious as to what the propose of those are. Should I start using them?

  5. #5
    Join Date
    Nov 2013
    the backticks help to avoid any reserved keyword collisions. but are not always necessary and in all honesty not best practice. But i find if i have issues using backticks can help.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center