在php无法正常工作

时间:2017-05-25 09:46:59

标签: php isset

我有一个从这个表单中获取数据并将其插入数据库 我无法在网上找到任何解决方案 一切都在浏览器上工作,但数据没有存储到表中,if块内的echo不会打印在屏幕上。 代码可以在下面看到。

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 个答案:

答案 0 :(得分:1)

只有在提交表单时,您才能访问$_POST[]值 所以,替换它,

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

有了这个,

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

它可以正常运行,而不会将button替换为input

答案 1 :(得分:0)

如果您在同一页面提交表格,则应使用 -

$(document).ready(function() {
  $('#store_select').bind('change', function(e) {
    if ($('#store_select').val() == 'finished') {
      $("#completedStores").show();
      $("#notCompletedStores").hide();
    } else if ($('#store_select').val() == 'notFinished') {
      $("#completedStores").hide();
      $("#notCompletedStores").show();
    } else {
      $("#completedStores").hide();
      $("#notCompletedStores").hide();
    }
  }).trigger('change');

});

答案 2 :(得分:-1)

if(isset($_POST["proceed"])){}

$_POST["proceed"]根本没有设置,它需要一个值来确保它已设置。

而不是检查是否,只需打印帖子值并尝试提交表单。

在php标签内写下代码并尝试回显数据。

echo '<pre>';

print_r($_POST);

echo '----------------';

print_r($_REQUEST);