无法将数据插入数据库 000webhost

格雷格迈尔斯

我已连接到 000webhost 数据库,并且它都在运行并且可以正常工作,但是无法插入数据,它给了我未插入的信息!(我写的回声)我真的不知道为什么我不能上传到数据库我连接到它但不会将数据发送到数据库我隐藏了所有登录信息其他一切正常!

<?php
    $con=mysqli_connect("localhost", "************", "*********", "*************");

    if (!$con) {
        echo "Not Connected!";
    } else {
        echo "Connection Succeful.";
    }

    if (!mysqli_select_db($con, 'id5456491_emails')) 
    {
        echo 'Database not selected!!';
    }

    $Name = $_POST['username'];
    $Email = $_POST['email'];

    $sql_store = "INSERT INTO emails1 (ID,Name,Email) VALUES (NULL,'$Name','$Email')";
    $sql = mysqli_query($con, $sql_store);

    if (!mysqli_query($con,$sql_store)) {
        echo 'Not Inserted!';
    } else {
        echo "INSERTED!ss";
    }
    //header("refresh:2; url=referal.php");
 ?>
<!DOCTYPE html>
<html>
<head>

    <link href="https://fonts.googleapis.com/css?family=Do+Hyeon" rel="stylesheet">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>B.F.B Hvac</title>
    <style type="text/css">

    #logo {
        width: 50%;
        margin: auto;
        border:5px solid black;
        border-radius: 50%
    }

    #content {
        text-align: center;    
    }

    ul {
        list-style-type: none;
        margin: 0;
        padding: 0;
        overflow: hidden;
        background-color: rgb(61, 60, 59);
    }

    li {
        float: left;
    }

    li a {
        display: block;
        color: white;
        text-align: center;
        padding: 14px 16px;
        text-decoration: none;
        font-family: 'Do Hyeon', sans-serif;        
    }

    li a:hover {
        background-color: #111;
    }

    #about {
        background-color:rgb(61, 60, 59);
        font-family: 'Do Hyeon', sans-serif;
        color:white;
    }

    #cool {
        font-family: 'Do Hyeon', sans-serif;
        color: blue;
        font-size: 30px;
    }

    #heat {
        font-family: 'Do Hyeon', sans-serif;
        color: red;
        font-size: 30px; 
    }
    #p1 {
        font-family: 'Do Hyeon', sans-serif;
        color: black;
        font-size: 30px; 
    }


    #login-form {
        background-color: black;
        width: 100%;
    }

    .ll {
        background-color: grey;
        height: 20px;
    }

    ::placeholder {
        color:black;
    }

    .ll:hover {
        border-color: grey;
        height: 25px;
        color: white;
        ::placeholder {
            color:white;
        }
    }

    #btn {
        background-color: grey;
    }

    #btn:hover {
        border-color: black;
        color:white;
    }
</style>
</head>
<body>

    <div id="head">
        <ul>

            <li><a href="index.php">Home</a></li>
            <li><a href="quote.php">Quote</a></li>
            <li><a href="gallery.html">Gallery</a></li>
            <li><a href="referal.php">Referal</a></li>
            <li><a href="https://www.goodmanmfg.com/product-registration">Register</a></li>
            <li><a href="specials.html">Specials</a></li>
        </ul>
    </div>

    <div id="content">

        <a href="https://www.facebook.com/BFB-Heat-Air-703964289638814/">
            <img src="BFBlog.jpg" id="logo">
        </a>

        <h1 id="about">Referal</h1>

        <form action="dbh.php" method="POST">

            <input type="text" name="username" placeholder="Your email">
            <br><br>
            <input type="text" name="email" placeholder="Referal email">
            <br><br>
            <input type="submit" value="Submit">

        </form>

        <br>
        <br>
        <br>
        <br>
    </div>

    <div id="foot"></div>

    <script type="text/javascript"></script>

</body>
</html>
顺元T恤

从你下面的代码来看,你好像做了INSERT两次同样的事情

$sql_store = "INSERT INTO emails1 (ID,Name,Email) VALUES (NULL,'$Name','$Email')";

// the first INSERT
$sql = mysqli_query($con, $sql_store);

// the second same INSERT again!!
if (!mysqli_query($con,$sql_store)) {
    echo 'Not Inserted!';
} else {
    echo "INSERTED!ss";
}

你有什么UNIQUE constraint在桌子上,例如:姓名,电子邮件?如果是,我怀疑第一个INSERT成功,但第二个因UNIQUE constraint违规而失败您可以像这样更改代码并重试:

$sql_store = "INSERT INTO emails1 (ID,Name,Email) VALUES (NULL,'$Name','$Email')";
// only 1 INSERT
$success = mysqli_query($con, $sql_store);

// check for INSERT return status
if (!success) {
    echo 'Not Inserted!';
} else {
    echo "INSERTED!";
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章