Bootstrap表单提交无法使用$ _POST数据

时间:2015-08-02 05:07:04

标签: php html forms twitter-bootstrap post

我的代码没有从boostrap表单输入任何数据到MySQL表中,如果我硬编码值而不是使用$ login和$ score,数据会显示在我的表格中。

这是我的表格(index.php)

<form action="insert.php" method="post">
    <div class="input-group">
        <span class="input-group-addon">NA</span>

            <input type="text" id = "login" name = "login" class="form-control" placeholder="Name" />
            <span class="input-group-addon">-</span>
            <input type="int" id = "score" name = "score" class="form-control" placeholder="Score: (0-10)"/>


            <span class="input-group-btn">
            <a class="btn btn-success" type="submit" id="submit" href = "/insert.php">Rate!</a>
       </span>

</form>

和我的php(insert.php)

<?php

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "data";

$login=$_POST['login'];
$score=$_POST['score'];


// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

print("name data: $login");
$sql = "INSERT INTO table (name, score)
VALUES ('$login', '$score')";

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";

} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

每次添加我的数据时,名称和分数都是空的。

编辑:修复,谢谢

 <button id="submit" name="submit" class="btn btn-lg btn-success">Rate</button>

2 个答案:

答案 0 :(得分:2)

您必须使用按钮进行提交,而不是使用href链接

试试这个

SELECT scf_cliente.nombre, scf_cotizacion.fecha FROM scf.scf_cliente join scf.scf_cotizacion on scf.scf_cliente.id = scf.scf_cotizacion.cliente_identificacion_id

答案 1 :(得分:1)

或者您可以使用

 <input type="submit" id="submit" name="submit" class="btn btn-lg btn-success" value ="Rate">