繁体   English   中英

PHP表单数据未插入MySQL数据库

[英]PHP Form data not inserting into MySQL database

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>

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

 ?> 

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

它要么在屏幕上打印出整个代码,要么空白。 我在这里和论坛上看过类似的问题所有他们似乎都有不同的问题,当我改变它适合所谓的答案它仍然不起作用!

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

两个问题:

改变<? php to <?php <? php to <?php

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

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

在使用之前,您仍需要检查后期值。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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