简体   繁体   中英

PHP Form data not inserting into MySQL database

HTML FORM

  <form class="form" method="post" action="process.php">
    <h4 class="form-heading">Please New Enter Customer Information</h4>
    <label for="inital">Inital:</label>
     <select id="inital" name="inital" required="required">  
        <option value="mr">Mr</option>  
        <option value="ms">Ms</option>  
        <option value="mrs">Mrs</option> 
        <option value="prof">Prof</option>      
        <option value="dr">Dr</option>    
    </select>  
    <label for="firstname">First Name:</label>
    <input type="text" placeholder="First Name" name="firstname" required="required" >
    <label for="lastname">last Name:</label>
    <input type="text" placeholder="Last Name" name="lastname" required="required">
    <label for="mobile">Mobile:</label>
    <input type="tel" placeholder="Mobile" name="mobile" required="required">
    <label for="landline">Landline:</label>
    <input type="tel" placeholder="Landline" name="landline">
    <label for="email">Email:</label>
    <input type="email" placeholder="Email" name="email" required="required">
    <label for="address">Address:</label>
    <input type="text" placeholder="Address" name="address" required="required">
    <label for="postocde">Postal Code:</label>
    <input type="text" placeholder="Post Code" name="postcode">
    <label for="accessibility">Accessibility:</label>
    <input type="text" placeholder="Accessibility Needs" name="accessibility" value="">

    <button class="btn btn-large btn-primary" type="submit">Enter</button>

process.php

    <? php

require( '../connect_db.php' ) ;

$inital = $sql->real_escape_string($_POST[inital]);  
$firstname = $sql->real_escape_string($_POST[firstname]); 
$lastname = $sql->real_escape_string($_POST[lastname]); 
$mobile = $sql->real_escape_string($_POST[mobile]); 
$landline = $sql->real_escape_string($_POST[landline]);
$email = $sql->real_escape_string($_POST[email]);
$address = $sql->real_escape_string($_POST[address]);   
$postcode = $sql->real_escape_string($_POST[postcode]); 
$accessibility = $sql->real_escape_string($_POST[accessibility]); 

$query = "INSERT INTO `customer` (inital, firstname, lastname, mobile, landline, email, address, postcode, accessibility) VALUES ('$inital','$firstname', '$lastname','$mobile','$landline','$email','$address','$postcode','$accessibility')";

/* execute the query, nice and simple */
$sql->query($query) or die($query.'<br />'.$sql->error);

 ?> 

I have tried alternatives too but to no satisfaction like not including $inital =($_POST[inital]); Instead putting right into INSERT INTO section but that still does not help either.

It either prints out the whole code on screen or blank. I've looked at similar problems on here and on forums all them seem to present the issue differently and when i change it suit the so called answer it still does not work!

My other page that lists all the tables using the following connection required statment works works fine so there is no problem with connection to the database but at this moment just cannot insert content. Grr

Two problems:

change <? php to <?php <? php to <?php

and then add quotes to your post data values. $_POST[inital] to $_POST['inital']

and for your information i would do isset($_POST['value']) ? $_POST['value'] : ''; isset($_POST['value']) ? $_POST['value'] : '';

you still need to check post value before using it.

Check the <? php tag. it should be <?php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM