www.webdeveloper.com
Results 1 to 2 of 2

Thread: PHP form and MySQL database

Hybrid View

  1. #1
    Join Date
    Dec 2013
    Posts
    3

    PHP form and MySQL database

    Hi

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

    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>
    <div id="lnamef">
    <label for="LastName" class="textLabel">Last name</label>
    <input type="text" name="LastName" id="LastName">
    </div>
    <div id="emailf">
    <label for="Email" class="textLabel">Email </label>
    <input type="text" name="Email" id="Email">
    </div>
    <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>
    <br>
    <div id="submitf">
    <input type="submit" name="submit" id="submit" value="Submit">
    </form> </div>
    </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">

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Untitled Document</title>
    </head>

    <body>
    </body>
    </html>
    <?php
        $username
    ="root";
        
    $password="";
        
    $database="test1";
        
        
    $FirstName $_POST["FirstName"];
        
    $LastName $_POST["LastName"];
        
    $Email $_POST["Email"];
        
    $Mobile $_POST["Mobile"];
        
    $Message $_POST["Message"];

            echo 
    $FirstName;
            echo 
    $LastName;
            echo 
    $Email;
            echo 
    $Mobile;
            echo 
    $Message;

      
    $conn=mysql_connect("localhost""root""")
            or die (
    "NO connection");

        
    $db=mysql_select_db("test1",$conn)
        or die (
    "Brak polaczenia");

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

        
    $db=mysql_query($sql,$conn)
        or die (
    "Error");

    ?>
    Thanks

  2. #2
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    5
    Hi, try this
    PHP Code:
     <?php
                $username
    ="root";
                
    $password="";
                
    $database="test1";
                
    $host="localhost";
                
                
    $FirstName $_POST["FirstName"];
                
    $LastName $_POST["LastName"];
                
    $Email $_POST["Email"];
                
    $Mobile $_POST["Mobile"];
                
    $Message $_POST["Message"];


              
    $conn=mysqli_connect($host,$username,$password,$database);
                    or die (
    "NO connection");

                

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

                
    $db=mysqli_query($conn,$ql);
                
                if(
    $db)
                {
                echo 
    "Success" ;
                }
                else
                {
                echo 
    "errror";
                }
            
    ?>

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



Recent Articles