簡體   English   中英

將表單中的數據插入數據庫PHP MYSQL

[英]Inserting data from form into database PHP MYSQL

我正在嘗試將數據從表單發送到我的數據庫中,但是我似乎沒有用。 表格字段正確。 我可以看到什么地方出了問題嗎?

形成:

<form class="myForm" role="form" action= "idea.php" method ="POST">
    <h1 style="margin-top:50px; margin-bottom:30px; text-align:center; color:#0f4155;">Idea Form</h1>

    <p1>Name:</p1>
    <input type="text" class="form-control" name="name" placeholder="Name">

    <p1>Originator:</p1>
    <input type="text" class="form-control" name="originator" placeholder="Originator">

    <p1>Alternative Contact</p1>
     <input type="text" class="form-control" name="altcontact" placeholder="Alternative Contact">

    <p1>Problem to Solve</p1>
     <input type="text" class="form-control" name="problem" placeholder="Problem to Solve">

    <p1>Description</p1>
    <textarea class="form-control" rows="3" name="description" placeholder="Description"></textarea>

    <p1>PO</p1>
    <input type="text" class="form-control" name="po" placeholder="PO">

    <p1>Archetypical Client</p1>
    <input type="text" class="form-control" name="archclient" placeholder="Arcetypical Client">

    <p1>Urgency</p1>
    <input type="text" class="form-control" name="urgency" placeholder="Urgency" style="margin-bottom: 20px">

    <p1>Technology/Platform</p1>
    <input type="text" class="form-control" name="technology" placeholder="Technology/Platform">

    <p1>Number of Sprints</p1>
    <input type="number" class="form-control" name="sprints" placeholder="Number of Sprints">

    <p1>Progress</p1>
    <input type="text" class="form-control" name="progress" placeholder="Progress">

    <input class="submit" name="submit" type="submit" value="Submit">

</form>  

PHP:

if ($_SERVER["REQUEST_METHOD"] == "POST") { //if new idea is being added

    $id = '';
    $name = $_POST['name'];
    $originator = $_POST['originator'];
    $altcontact = $_POST['altcontact'];
    $problem = $_POST['problem']; 
    $description = $_POST['description']; 
    $po = $_POST['po'];
    $archclient = $_POST['archclient']; 
    $urgency = $_POST['urgency']; 
    $technology = $_POST['technology']; 
    $sprints = $_POST['sprints']; 
    $progress = $_POST['progress']; 
    $status = "submitted"; 


    $strsq0 = "INSERT INTO idea (`id`,`name`, `originator`, `alternative_contact`, `problem`, `description`, `po`, `arch_client`, `urgency`, `technology`, `sprints`, `progress`, `status`) VALUES ('" . $name . "," . $name . "," . $originator . "," . $altcontact . "," . $problem . ", " . $description . ", " . $po . "," . $archclient . ", " . $urgency . ", " . $technology . ", " . $sprints . ", " . $progress . ", " . $status . "');"; //query to insert new idea
    if ($mysqli->query($strsq0)) {
        echo "Insert success!";
    } else {
        echo "Cannot insert into the data table; check whether the table is created, or the database is active. "  . mysqli_error();
    }
}

如果idauto increment則將其從values()的add NULL查詢中刪除,並且對引號的管理不正確

$strsq0 = "INSERT INTO idea (`name`, `originator`, `alternative_contact`, `problem`, `description`, `po`, `arch_client`, `urgency`, `technology`, `sprints`, `progress`, `status`) VALUES ('$name','$originator','$altcontact ','$problem', '$description', '$po','$archclient', '$urgency', '$technology', '$sprints','$progress', '$status')"; //query to insert new idea

進行更多調試

echo "INSERT INTO idea (`name`, `originator`, `alternative_contact`, `problem`, `description`, `po`, `arch_client`, `urgency`, `technology`, `sprints`, `progress`, `status`) VALUES ('$name','$originator','$altcontact ','$problem', '$description', '$po','$archclient', '$urgency', '$technology', '$sprints','$progress', '$status')";
exit;
$strsq0 = "INSERT INTO idea (`name`, `originator`, `alternative_contact`, `problem`, `description`, `po`, `arch_client`, `urgency`, `technology`, `sprints`, `progress`, `status`) VALUES ('$name','$originator','$altcontact ','$problem', '$description', '$po','$archclient', '$urgency', '$technology', '$sprints','$progress', '$status')"; //query to insert new idea

然后復制此打印查詢並在phpMyadmin運行,運行打印查詢后檢查是否有任何錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM