Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question
"prints the whole code" e.g. your php code shows up instead of being executed? that's a server configuration issue... Your $_POST keys also need to be quoted: $_POST['mobile'] and the like. PHP will politely (in most cases) pretend the quotes are there, but spit out warnings. – Marc B Jan 31 at 14:49
2  
<? php This will case error. And, if you don't have short-tags enabled, will not be treated as PHP code. – Dainis Abols Jan 31 at 14:50
Show connect_db.php also. – Jonathon Reinhart Jan 31 at 14:50
in query you forget to put "set" "INSERT INTO customer SET..." – mohammad mohsenipur Jan 31 at 14:50
1  
Why do you need SET for INSERT? – Dainis Abols Jan 31 at 14:51
show 4 more commentsadd comment (requires an account with 50 reputation)

2 Answers

up vote 2 down vote accepted

Two problems:

change <? 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'] : '';

you still need to check post value before using it.

share|improve this answer
Thank you for your reply :) – KP2012 Jan 31 at 15:01
If I was there i would hug you! lol – KP2012 Jan 31 at 15:08
glad to help :) – GGio Jan 31 at 15:10
add comment (requires an account with 50 reputation)

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

share|improve this answer
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.