每当我使用隐藏字段来检索数据时,它都会抛出错误,我也想让标题区域响应

时间:2018-05-24 11:34:39

标签: php html5 twitter-bootstrap-3

当我尝试使用PHP脚本从phpmyadmin数据库中检索数据时,我使用了一个隐藏的文件并传递了#34; user_id"但后来我得到一个关于未定义变量的错误。代码如下。

而且我也希望在尝试大量解决方案之后使标题响应但没有运气。我已经尝试了使用这么多网站的所有可能的解决方案,但我无法使其发挥作用。

代码如下。



<?php 
  session_start();
  include 'lib/dao.php';
  include 'lib/model.php';
  $d = new dao();
  $m = new model();
  extract($_POST);

  if(!isset($_SESSION['user_id']))
  {
    header("location:login.php");
  }
    $q=$d->select("user","user_id='$user_id'");
    $data=mysqli_fetch_array($q);
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Your Tracker</title>
  <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
  <link rel="stylesheet" type="text/css" href="css/font_awesome/css/font-awesome.min.css"/>
  <link rel="stylesheet" type="text/css" href="css/style.css"/>
  <link rel="stylesheet" type="text/css" href="css/style1.css"/>
</head>
<body>
  <div id="home" class="container">
  <?php echo $data['$user_name']; ?>
    <div class="row">
      <div class="logo col-sm-6">
        <img src="img/firefox.png" height="30px" width="30px" class="text-left">
      </div>
      <div class="main-menu col-sm-6 text-right">
        <nav>
          <ul>
            <li><a href="logout.php">Log Out</a></li>
            <li><a href="#contact">Contact Us</a></li>
            <li><a href="#account">Account</a></li>
            <li><a href="#home">Home</a></li>
          </ul>
        </nav>
      </div>
    </div>
  </div>
  <div style="background-color: #fff;" class="section-titlee text-center col-xs-12">
    <h1>Personal <span>Details</span></h1><br>
    <div>
    <div class="text-left">
      <h4 style="margin-left: 40px;">Add Your Personal Details</h4><br>
      <form action="#" method="post" enctype="multipart/form-data">
        <div class="form-group required">
          <label class="col-sm-4 control-label" for="name">Name</label>
          <div class="col-sm-6">
            <input type="hidden" name="user_id" value="<?php echo $data['user_id']; ?>">
            <input type="text" name="user_name" value="<?php echo $data['user_name']; ?>" placeholder="Name" id="user_name" class="form-control">
          </div>
          <div class="col-sm-2"></div>
        </div>
        <div class="form-group required">
          <label class="col-sm-4 control-label" for="gender">Gender</label>
          <div class="col-sm-6">
            <div class="row">
              <div class="col-sm-4">
                Male<input type="radio"  name="radio" value="male" id="male">
              </div>
              <div class="col-sm-4">
                Female<input type="radio"  name="radio" value="female" id="female">
              </div>
              <div class="col-sm-4">  
                Other<input type="radio" name="radio" value="other" id="other">
              </div>
            </div>
          </div>
          <div class="col-sm-2"></div>
        </div>
        <div class="form-group required">
          <label class="col-sm-4 control-label" for="email">E-Mail</label>
          <div class="col-sm-6">
            <input type="email" name="email" value="<?php echo $data['user_email']; ?>" placeholder="E-Mail" id="input-email" class="form-control">
          </div>
          <div class="col-sm-2"></div>
        </div>
        <div class="form-group required">
          <label class="col-sm-4 control-label" for="mobile">Mobile</label>
          <div class="col-sm-6">
            <input type="text" name="mobile" value="<?php echo $data['user_email']; ?>" placeholder="Mobile" id="mobile" class="form-control">
          </div>
          <div class="col-sm-2"></div>
        </div>
        <div class="text-center col-sm-12" style="margin-top: 10px;">
          <input type="submit" class="btn-link" style="border-radius: 9px;border-color: blue;" name="update" id="update" value="Update">
        </div>
      </form>
    </div>
    <div class="col-sm-12">
      <hr>
      
    </div>
    </div>
  </div>
<div id="contact" class="footer section-titlee white text-center col-xs-12">
  <h1 style="margin-left: 40px;margin-top: -25px;">Contact <span>Us</span></h1>
  <div>
    <div class="row">
      <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1 col-xs-12">
        <div class="row">
          <div class="single-contact-info text-center col-sm-4 col-xs-12 mb-40">
            <i class="fa fa-phone"></i>
            <p>+91 7802969879</p>
          </div>
          <div class="single-contact-info text-center col-sm-4 col-xs-12 mb-40">
            <i class="fa fa-google-wallet"></i>
            <p>anami662@gmail.com</p>
          </div>
          <div class="single-contact-info text-center col-sm-4 col-xs-12 mb-40">
            <i class="fa fa-map"></i>
            <p>Ahemdabad,Gujarat.</p>
          </div>
        </div>
        <div class="row mt-30">
          <div class="contact-form">
            <div>
              <div id="msg"></div><br><br>
              <form action="mail.php" method="post" enctype="multipart/form-data">
               <div class="col-sm-6 col-xs-12">
                  <input type="text" id="name" name="name" placeholder="Name" >
                  <input type="email" id="email" name="email" placeholder="Email">
                  <input type="text" id="subject" name="subject" placeholder="Subject" >
                </div>
                <div class="col-sm-6 col-xs-12">
                  <textarea name="message" id="message" placeholder="Message"></textarea>
                  <input type="submit" id="submit" value="Submit">
                </div>
              </form>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- <script type="text/javascript">
  function mailsend()
  {
    jQuery.ajax({
      url:"mail.php",
      data:{name: $('input#name').val(),email:$('input#email').val(),subject:$('input#subject').val(),message:$('textarea#message').val()},
      type:"POST",
      success:function(data){
                $("#msg").html(data);}
    });
  }
</script> -->
<script type="text/javascript" href="css/jquery.min.js"></script>
<script type="text/javascript" href="css/bootstrap.min.js"></script>
</body>
</html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

答案很简单,只需使用下面给出的代码并且所有错误消失。

<input type="hidden" name="user_id" value="<?php echo $_SESSION['user_id']; ?>">
<?php 
extract($_POST);
$user_id=$_SESSION['user_id'];
$q=$d->select("user","user_id='$user_id'");
$data=mysqli_fetch_array($q); ?>