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