Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将变量从窗体传递到另一页时未定义索引_Php - Fatal编程技术网

Php 将变量从窗体传递到另一页时未定义索引

Php 将变量从窗体传递到另一页时未定义索引,php,Php,我试图将一个值从一个页面传递到另一个页面,但我一辈子都无法理解为什么我总是收到未定义的索引错误消息 这是第一页的PHP代码: <?php include 'database_connection.php'; $id = $_GET['id']; $sql="select engineer.id, engineer.team_id, engineer.first_name, engineer.active, engineer.last_name, engi

我试图将一个值从一个页面传递到另一个页面,但我一辈子都无法理解为什么我总是收到未定义的索引错误消息

这是第一页的PHP代码:

    <?php
    include 'database_connection.php';

    $id = $_GET['id'];

    $sql="select engineer.id, engineer.team_id, engineer.first_name, engineer.active, engineer.last_name, engineer.role, engineer.region, engineer.phone, to_date, team.team_name, team.manager_name, team.description, team.type, engineer.email from engineer inner join team on engineer.team_id=team.id where active=0 and engineer.team_id > 0 and engineer.id = '".$id."'";

    $results = mysqli_query($connection, $sql);

    while($row = mysqli_fetch_array($results)) {
        $id=$row['id'];
        $first_name=$row['first_name'];
        $last_name=$row['last_name'];
        $role=$row['role'];
        $email=$row['email'];
        $phone=$row['phone'];
        $region=$row['region'];
        $type=$row['type'];
    ?>

    <form class="form-horizontal col-sm-12" role="form" method="post" action="../admin/update.php">

    <fieldset disabled>
        <div class="form-group">
          <label for="sso" class="col-sm-2 control-label">SSO ID</label>
          <div class="col-sm-10">
            <input type="text" id="id" name="id" class="form-control" value="<?php echo $id; ?>">
          </div>
        </div>
    </fieldset>

        <div class="form-group">
          <label for="name" class="col-sm-2 control-label">Name</label>
          <div class="col-sm-10">
            <input type="text" class="form-control" id="name" name="first_name" placeholder="First Name" value="<?php echo $first_name; ?>">
          </div>
        </div>

        <div class="form-group">
          <label for="lastname" class="col-sm-2 control-label">Surname</label>
          <div class="col-sm-10">
            <input type="text" class="form-control" id="name" name="last_name" placeholder="Last Name" value="<?php echo $last_name; ?>">
          </div>
        </div>  

    <div class="form-group">
      <label for="team" class="col-sm-2 control-label">Team</label>
      <div class="col-sm-10">   
        <select style="width:auto;" class="btn btn-default dropdown-toggle form-control" type="button" name="team_name" value="" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
         <?php
            //connect  to the database
            include 'database_connection.php';

            //query the database
            $sql_team = "SELECT DISTINCT id, team_name FROM team";

            //uses $sql_team variable to make a specific query
            $query = mysqli_query($connection, $sql_team);
        ?>

        <option value="<?php echo $team_name; ?>"><?php echo $team_name; ?></option>

        <?php
            //initilises a while loop to retrieve all the rows
            while ($row = mysqli_fetch_array($query) )
            { 
               //echos all the distinct catDesc rows into a list
               echo "<option value='" . $row['id'] . "' >".htmlspecialchars($row["team_name"])."</option>";
            }
        ?>
        </select>
      </div>
    </div>  

    <div class="form-group">
        <label for="role" class="col-sm-2 control-label">Role</label>
        <div class="col-sm-10">
            <input type="role" class="form-control" id="role" name="role" placeholder="Role" value="<?php echo $role; ?>">
        </div>
    </div>  

    <div class="form-group">
        <label for="email" class="col-sm-2 control-label">Email</label>
        <div class="col-sm-10">
            <input type="email" class="form-control" id="email" name="email" placeholder="example@domain.com" value="<?php echo $email; ?>">
        </div>
    </div>

    <div class="form-group">
        <label for="phone" class="col-sm-2 control-label">Phone Number</label>
        <div class="col-sm-10">
            <input type="phone" class="form-control" id="phone" name="phone" placeholder="Business number" value="<?php echo $phone; ?>">
        </div>
    </div>

    <div class="form-group">
        <label for="region" class="col-sm-2 control-label">Region</label>
        <div class="col-sm-10">
            <input type="region" class="form-control" id="region" name="region" placeholder="Region e.g. South" value="<?php echo $region; ?>">
        </div>
    </div>  

    <div class="form-group">
        <div class="col-sm-10 col-sm-offset-2">
            <input type="submit" value="Save" class="btn btn-primary">
        </div>
    </div>

    <div class="form-group">
        <div class="col-sm-10 col-sm-offset-2">
            <! Will be used to display an alert to the user>
        </div>
    </div>
</form>
    <?php
        //closes and stops the loop 
        }
    ?> 

单点登录ID

若要将变量作为get方法传递,可以在表单的action属性中传递它 例如:action=“xyz.php?id=” 在第3行,您已经分配了一个$\u GET[]变量,您无法在那里分配,因为这些值只有在提交表单后才会设置,所以如果您想删除错误,请按如下方式编写脚本
if(isset($GET['id']){

$id=$\u GET['id'];

}

使用

在你的表格中,读作

$\u POST['id']


在第二页中

通常,未定义索引错误会提到未定义的索引。1.您不能同时获取和发布,它们是两种不同的HTTP方法。您对URL发出获取请求或发布请求。2.使用准备好的语句,而不是
mysqli\u real\u escape\u string
3.您应该首先检查weather字段由
isset()
设置或不设置,并且具有值,因此很难找出错误所在。关于未定义的索引,存在大量问题
<?php
include 'database_connection.php';

    $id = mysqli_real_escape_string($connection, $_GET['id']);
    $first_name = mysqli_real_escape_string($connection, $_POST['first_name']);
    $last_name = mysqli_real_escape_string($connection, $_POST['last_name']);
    $team_name = mysqli_real_escape_string($connection, $_POST['team_name']);   
    $role = mysqli_real_escape_string($connection, $_POST['role']);
    $email = mysqli_real_escape_string($connection, $_POST['email']);
    $phone = mysqli_real_escape_string($connection, $_POST['phone']);
    $region = mysqli_real_escape_string($connection, $_POST['region']);

    if ($role == ''){
        $role = NULL;
    }

    if ($email == ''){
        $email = NULL;
    }

    if ($phone == ''){
        $phone = NULL;
    }

    if ($region == ''){
        $region = NULL;
    }   


    $sql = "UPDATE people SET id='$id', first_name='$first_name', last_name='$last_name', team_id='$team_name', role='$role', email='$email', phone=$phone', region='$region' where id='$id')";

?>