dongmengan8620 2017-05-25 09:46
浏览 30
已采纳

在php中没有工作

I have a to get a data from this form and insert it into database.
I am not able to find any solution online.
Everything works on the browser but the data is not getting stored into the table and echo inside the if block is not printed on screen. The code is what can be seen below.

HTML

    <form action="" method="POST">
    <div class="container-fluid">
      <div class="container">
       <div class="row">
          </div>

  <div class="row">
    <div class="col-xs-12 col-sm-6 col-md-10 col-lg-4 col-md-offset-3" style="top:100px">
            <div class="offer offer-radius offer-primary">
                <div class="shape">
                    <div class="shape-text">
                        <span class="glyphicon glyphicon-user"></span>
                </div>
            </div>
                <div class="offer-content">
                     <h4 style="margin-left:70px;font-size:20px">Enter your details below and enroll your slot</h4>

          <div class="container col-xs-12">
              <div class="stepwizard">
                  <div class="stepwizard-row setup-panel">
                      <div class="stepwizard-step">
                          <a href="#step-1" type="button" class="btn btn-primary btn-circle">
                          <i class="glyphicon glyphicon-user" style="margin-left: -18px;top: -24px;font-size: 90%;"></i></a>
                  </div>
                      <div class="stepwizard-step">
                          <a href="#step-2" type="button" class="btn btn-default btn-circle" disabled="disabled">
                          <i class="glyphicon glyphicon-education" style="margin-left: -18px;top: -24px;font-size: 90%;"></i></a>
                  </div>
                      <div class="stepwizard-step">
                          <a href="#step-4" type="button" class="btn btn-default btn-circle" disabled="disabled">
                          <i class="glyphicon glyphicon-ok" style="margin-left: -18px;top: -24px;font-size: 90%;"></i></a>
                  </div>
              </div>
          </div>

              <div class="row setup-content" id="step-2">
                  <div class="col-xs-12">
                      <div class="col-md-10">
                          <h3>Qualification</h3>
                          <div class="col-xs-12 col-xs-offset-1" style="top:-50px">
                            <button class="btn btn-primary nextBtn btn-lg pull-right" type="button" >Next</button>
                      </div>
                          <div class="col-xs-12" style="clear:both;top:-45px">
                          <input  maxlength="20" type="text" required="required" class="form-control" placeholder="B Tech" readonly="" />
                      </div>
                            <div class="col-xs-12 form-group" style="clear:both;top:-40px">
                                    <label for="subject">
                                    Year of Pass out</label>
                                        <input  maxlength="20" type="text" required="required" class="form-control" placeholder="2016" readonly="" />
                            </div>
                                <div class="col-xs-12 form-group" style="clear:both;top:-40px">
                                        <label for="subject">
                                        Branch</label>
                                        <select id="subject" name="subject" class="form-control" required="required">
                                            <option value="na" selected="">Choose One:</option>
                                            <option value="service">Computer Science</option>
                                            <option value="suggestions">Information Technology</option>
                                            <option value="product">Electronics & Communication</option>
                                            <option value="product">Electronics & Electrical</option>
                                            <option value="product">Instrumentation</option>
                                    </select>
                                </div>
                                    <div class="col-xs-12" style="clear:both;top:-40px">
                                    <label for="subject">
                                    Percentage (%)</label>
                                    <input  maxlength="6" type="text" class="form-control" placeholder="Your Percentage" name="percentage" />
                                </div>
                      </div>
                  </div>
              </div>
          </div>

          <div class="row setup-content" id="step-1">
              <div class="col-xs-12">
                  <div class="col-md-12">
                      <div class="container">
                            <div class="row">
                                <div class="col-xs-4">
                                <button class="btn btn-primary nextBtn btn-lg pull-right" type="button" >Next</button>
                                    <h3>Personal Information</h3>
                                    <div class="col-xs-12" style="padding:15px">
                                        <div class="input-group">
                                      <span class="input-group-addon"><i class="fa fa-user fa" aria-hidden="true"></i></span>
                                      <input  maxlength="100" type="text" class="form-control" placeholder="First Name" name="F_Name" />
                                </div>
                                </div>
                                    <div class="col-xs-12" style="clear:both;padding:10px">
                                        <div class="input-group">
                                      <span class="input-group-addon"><i class="fa fa-user fa" aria-hidden="true"></i></span>
                                      <input  maxlength="100" type="text" class="form-control" placeholder="Last Name" name="L_Name"  />
                                </div>
                                </div>
                                    <div class="col-xs-12" style="clear:both;padding:10px">
                                        <div class="input-group">
                                      <span class="input-group-addon"><i class="fa fa-envelope fa" aria-hidden="true"></i></span>
                                      <input  maxlength="100" type="text" class="form-control" placeholder="Your Email" name="EmailID" />
                                </div>
                                </div>
                                    <div class="col-xs-12" style="clear:both;padding:10px">
                                        <div class="input-group">
                                      <span class="input-group-addon"><i class="fa fa-phone fa" aria-hidden="true"></i></span>
                                      <input  maxlength="14" type="text" class="form-control" placeholder="(+91) 555-555-5555" name="Phone_Number" />
                                </div>
                                </div>
                                    <div class="col-xs-12" style="clear:both;padding:10px">
                                        <div class="input-group">
                                      <span class="input-group-addon"><i class="fa fa-phone fa" aria-hidden="true"></i></span>
                                      <input  maxlength="14" type="text" class="form-control" placeholder="Reference Code" name="R_Code" />
                                </div>
                                </div>
                            </div>
                    </div>
                    </div>
                  </div>
              </div>
          </div>
      </div>
              <div class="row setup-content" id="step-4">
                  <div class="col-xs-12">
                      <div class="col-xs-12">
                          <div class="container" style="height:307px;">
                           <h4>Registered</h4>
                           <div class="col-xs-4" style="margin-left:-60px;top:60px">
                             <a href="#"><button class="btn btn-success completeBtn btn-lg pull-right" type="button" name="proceed">Proceed to payment</button></a>
                       </div>
                      </div>
                  </div>
              </div>
          </div>
      </div>
      </div>

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

</form>

PHP

    <?php
$cn= mysqli_connect('localhost','testuser','password','invoicedb');
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
echo "string";

if(isset($_POST["proceed"]))
{echo "string";

  $fname=$_POST['F_Name'];
  $lname=$_POST['L_Name'];
  $emailID=$_POST['EmailID'];
  $phone_number=$_POST['Phone_Number'];
  $reference_code=$_POST[‘R_Code’];
  $branch=$_POST[‘subject’];
  $percentage=$_POST[‘percentage’];

echo "insert into students(first_name,last_name,email,phone_number,reference_code,branch,percentage) VALUES ('$fname','$lname','$emailID','$phone_number','$reference_code','$branch','$percentage')";

mysqli_query($cn,"insert into students(first_name,last_name,email,phone_number,reference_code,branch,percentage) VALUES ('$fname','$lname','$emailID','$phone_number','$reference_code','$branch','$percentage')");
//best outside the if statement so user isn't stuck on a white blank page.
header("location:confirm.php");
exit;
}
?>
  • 写回答

3条回答 默认 最新

  • dongzhouzhang8696 2017-05-25 09:58
    关注

    You can access $_POST[] values only if your form is submitted,
    So, Replace this,

    <a href="#"><button class="btn btn-success completeBtn btn-lg pull-right" type="button" name="proceed">Proceed to payment</button></a>
    

    with This,

    <a href="#"><button class="btn btn-success completeBtn btn-lg pull-right" type="submit" name="proceed">Proceed to payment</button></a>
    

    It will work, without replacing your button with input.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)