1

HTML 表格

  <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>

进程.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);

 ?> 

我也尝试过替代方案,但不满意,比如不包括,$inital =($_POST[inital]);而是直接放入 INSERT INTO 部分,但这仍然无济于事。

它要么在屏幕上打印出整个代码,要么在空白处打印出来。我在这里和论坛上查看了类似的问题,所有这些问题似乎都以不同的方式呈现问题,当我改变它以适应所谓的答案时,它仍然不起作用!

我使用以下连接所需语句列出所有表的其他页面工作正常,因此与数据库的连接没有问题,但此时无法插入内容。格子

4

2 回答 2

2

两个问题:

改变<? php to <?php

然后在您的帖子数据值中添加引号。$_POST[inital] to $_POST['inital']

为了你的信息,我会做isset($_POST['value']) ? $_POST['value'] : '';

您仍然需要在使用前检查后值。

于 2013-01-31T14:51:23.637 回答
1

检查<?php 标签。它应该是<?php

于 2013-01-31T14:50:47.733 回答