php - 提交按钮在isset中不起作用

时间:2017-09-11 07:35:46

标签: php html mysql

我正在尝试在我的html中添加一个表单,它将获得12个输入框并将其保存到mysql。但由于提交按钮,它的回声失败了。因为如果对于isset提交按钮,else就是转发消息。 我的HTML代码

<body class="templatemo-bg-image-2">
<div class="container">
    <div class="col-md-12">         
        <form class="form-horizontal templatemo-contact-form-1" role="form" action="input.php" method="post">
            <div class="form-group">
                <div class="col-md-12">
                    <h1 class="margin-bottom-15">Marketing Samurai 2017</h1>
                    <h2 class="margin-bottom-15">Registration form</h2>
                    <p>This contact form is provided by <a href="#">templatemo</a> that can be used for your websites. Credit goes to <a rel="nofollow" href="http://unsplash.com">Unsplash</a> for the background image.</p>
                </div>

            <hr>
            <h4 class="margin-bottom-15">Team Info</h4>
            <hr>
            </div>              
            <div class="form-group">
              <div class="col-md-12">                   
                <label for="name" class="control-label">University Name</label>
                <div class="templatemo-input-icon-container">
                    <i class="fa fa-university"></i>
                    <input name="uname" type="text" class="form-control" id="name" placeholder="">
                </div>                                                          
              </div>              
            </div>
            <div class="form-group">
              <div class="col-md-12">                   
                <label for="name" class="control-label">Team</label>
                <div class="templatemo-input-icon-container">
                    <i class="fa fa-users"></i>
                    <input name="tname" type="text" class="form-control" id="name" placeholder="">
                </div>                                                          
              </div>              
            </div>
            <div class="form-group">
              <div class="col-md-12">                   
                <label for="name" class="control-label">Trix Id</label>
                <div class="templatemo-input-icon-container">
                    <i class="fa fa-money"></i>
                    <input name="tcode" type="text" class="form-control" id="name" placeholder="Bkash transection Code">
                </div>                                                          
              </div>              
            </div>
            <h4 class="margin-bottom-15">Leader Info</h4>
            <hr>
            <div class="form-group">
              <div class="col-md-12">                   
                <label for="name" class="control-label">Name</label>
                <div class="templatemo-input-icon-container">
                    <i class="fa fa-user"></i>
                    <input name="lname" type="text" class="form-control" id="name" placeholder="">
                </div>                                                          
              </div>              
            </div>
            <div class="form-group">
              <div class="col-md-12">                   
                <label for="name" class="control-label">Email</label>
                <div class="templatemo-input-icon-container">
                    <i class="fa fa-envelope-o"></i>
                    <input name="lmail" type="text" class="form-control" id="name" placeholder="">
                </div>                                                          
              </div>              
            </div>
            <div class="form-group">
              <div class="col-md-12">                   
                <label for="name" class="control-label">Contact</label>
                <div class="templatemo-input-icon-container">
                    <i class="fa fa-phone"></i>
                    <input name="lcont" type="text" class="form-control" id="name" placeholder="">
                </div>                                                          
              </div>              
            </div>
            <h4 class="margin-bottom-15">1st Member Info</h4>
            <hr>
            <div class="form-group">
              <div class="col-md-12">                   
                <label for="name" class="control-label">Name</label>
                <div class="templatemo-input-icon-container">
                    <i class="fa fa-user"></i>
                    <input name="m1name" type="text" class="form-control" id="name" placeholder="">
                </div>                                                          
              </div>              
            </div>
            <div class="form-group">
              <div class="col-md-12">                   
                <label for="name" class="control-label">Email</label>
                <div class="templatemo-input-icon-container">
                    <i class="fa fa-envelope-o"></i>
                    <input name="m1mail" type="text" class="form-control" id="name" placeholder="">
                </div>                                                          
              </div>              
            </div>
            <div class="form-group">
              <div class="col-md-12">                   
                <label for="name" class="control-label">Contact</label>
                <div class="templatemo-input-icon-container">
                    <i class="fa fa-phone"></i>
                    <input name="m1cont" type="text" class="form-control" id="name" placeholder="">
                </div>                                                          
              </div>              
            </div>
            <h4 class="margin-bottom-15">2nd Member Info</h4>
            <hr>
            <div class="form-group">
              <div class="col-md-12">                   
                <label for="name" class="control-label">Name</label>
                <div class="templatemo-input-icon-container">
                    <i class="fa fa-user"></i>
                    <input name="m2name" type="text" class="form-control" id="name" placeholder="">
                </div>                                                          
              </div>              
            </div>
            <div class="form-group">
              <div class="col-md-12">                   
                <label for="name" class="control-label">Email</label>
                <div class="templatemo-input-icon-container">
                    <i class="fa fa-envelope-o"></i>
                    <input name="m2mail" type="text" class="form-control" id="name" placeholder="">
                </div>                                                          
              </div>              
            </div>
            <div class="form-group">
              <div class="col-md-12">                   
                <label for="name" class="control-label">Contact</label>
                <div class="templatemo-input-icon-container">
                    <i class="fa fa-phone"></i>
                    <input name="m2cont" type="text" class="form-control" id="name" placeholder="">
                </div>                                                          
              </div>              
            </div>
            <div class="form-group">
              <div class="col-md-12">
                <button type="submit" value="Submit" name="submit" class="btn btn-success pull-right">></button>
              </div>
            </div>              
          </form>             
    </div>
</div>

php的代码

<?php
$con = mysqli_connect('localhost','root','');
if(!$con){

echo 'Not Connected To Server';
}
    if (!mysqli_select_db ($con,'test')) {

    echo 'Database Not Selected';
    }
    if (isset($_POST['submit'])){


    $uni = $_POST['uname'];
    $team = $_POST['tname'];
    $trix = $_POST['tcode'];
    $leader = $_POST['lname'];
    $lemail = $_POST['lmail'];
    $leadercon = $_POST['lcont'];
    $mname = $_POST['m1name'];
    $memail = $_POST['m1mail'];
    $mcon = $_POST['m1cont'];
    $mname3 = $_POST['m2name'];
    $memail3 = $_POST['m2mail'];
    $mcon3 = $_POST['m2cont'];



    $sql = "INSERT INTO 'memberdetails' (uninam, team, trixid, mem, mail, cont, mem1, mail1, con1, mem2, mail2, con2) VALUES ('$uni', '$team', '$trix', '$leader', '$lemail', '$leadercon', '$mname', '$memail', '$mcon', '$mname3', '$memail3', '$mcon3' )";




        if (!mysqli_query($con,$sql))
        {
        echo 'Not Inserted';
    }

        else
    {

    echo 'Inserted Successfully';
}

header("refresh:2; url=index.html");

}   else {
echo "failed";
}

我还没有做任何验证。我正在尝试使用msqli和数据库,表连接然后为什么错误来了?我刚刚提交了提交按钮以插入文档。我该怎么做才能防止失败的消息。提前致谢。 :)

2 个答案:

答案 0 :(得分:0)

提交必须是<input>的名称,否则无法使用$_POST['submit']

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

答案 1 :(得分:0)

尝试从表单按钮名称中删除“提交”文本,并替换为其他文本

<button type="submit" value="Submit" name="form_sumit" class="btn btn-success pull-right">></button>