Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.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更新mysql表中的x和y列值?_Php_Html_Mysql - Fatal编程技术网

点击按钮后如何使用php更新mysql表中的x和y列值?

点击按钮后如何使用php更新mysql表中的x和y列值?,php,html,mysql,Php,Html,Mysql,关于我之前的类似内容的查询, 我已经更新了它的代码。但是,我的问题是,我不知道如何从x和y输入中获取值,并在用户单击“更新”按钮后使用它更新x和y列。 请参阅以下问题: 选择建筑; > $getx=isset($_POST['forx'])?$_POST['forx']:''; $gety=isset($_POST['fory'])?$_POST['fory']:'' 请用正确的格式添加完整的代码。我想您的表单里面没有添加x和Y的输入框。谢谢!它帮助解决了这个错误。但是,我仍然无法在单击按钮后

关于我之前的类似内容的查询, 我已经更新了它的代码。但是,我的问题是,我不知道如何从x和y输入中获取值,并在用户单击“更新”按钮后使用它更新x和y列。 请参阅以下问题:


选择建筑;
>
$getx=isset($_POST['forx'])?$_POST['forx']:'';

$gety=isset($_POST['fory'])?$_POST['fory']:''

请用正确的格式添加完整的代码。我想您的表单里面没有添加x和Y的输入框。谢谢!它帮助解决了这个错误。但是,我仍然无法在单击按钮后更新列值;和var_dump($_POST);出口您可以检查输出数据。然后确保更新SQL。由于var_dump以数组形式显示数据,如何获取更新SQL表列所需的数据?请重试var_dump($_get);只有因为您的错误列表中存在$\u GET['forx']
<!--QUERY FOR BUILDING DROPDOWN-->  
    <section class="row placeholders">    
      <?php
        //for error reporting
        error_reporting(E_ALL);
        ini_set('display_errors', 1);

        $con = new mysqli("localhost", "root", "","user_databases");
        //query buildings table for the dropdown
        $bquery = mysqli_query($con, "SELECT building_ID, building_name FROM buildings");

        //declare variable to store selected building option
        $selectedbldg = null;

        // if the form for building dropdown list was submitted
        if (!empty($_POST['bldg'])) 
        {
          // store selected building_ID
          $selectedbldg = $_POST['bldg'];
                     
          //query image from filepath column of buildings table based on selected building_ID (show as building_name in dropdown)
          $img = mysqli_query($con, "
           SELECT map_image_filepath
           FROM   buildings
           WHERE  building_ID = {$selectedbldg}
          "); 
        } 
      ?>
    </section>
  
  <!--building dropdown list-->  
  <form name="bldg_form" method="post" action="">
    <select name="bldg" class="dropdown" style="margin-left: 30px; margin-top: 35px;">
      <option value="">Choose Building</option>;
        <?php while ($row = mysqli_fetch_assoc($bquery)) : ?>
          <option value="<?= $row['building_ID'] ?>" <?= $row['building_ID'] == $selectedbldg ? 'selected="selected"' : '' ?>>
          <?= $row['building_name'] ?>
      </option>
        <?php endwhile ?>
    </select>
      <input type="submit" name="view1" class="btn btn-primary btn-xs" />

    <!--display image after queried from db buildings table-->  
    <section class="row placeholders">
      <div class="map-header col-md-3" style="margin-left: 30px; margin-top: 50px; ">
        <!--call $img query to display image-->
        <?php if (isset($img) && mysqli_num_rows($img)) : ?>
          <?php while($row = mysqli_fetch_assoc($img))
          {
            //the variable for the map_image_filepath stored in database
            $filepath = $row['map_image_filepath'];
         
            //stores x and y coordinates when image is clicked
              $foo_x = isset ($_POST['foo_x']) ? $_POST['foo_x'] : '';
              $foo_y = isset ($_POST['foo_y']) ? $_POST['foo_y'] : '';

            //checks if file path queried exists
            if(file_exists($filepath))
            {
              //displays the image
              echo "<form action='' method=post>
                      <input type='image' src='{$filepath}'
                      name='foo' style='cursor:crosshair; border-right: #000000 2px outset;  border-bottom: #000000 2px outset; border-left: #000000 2px outset; border-top: #000000 2px outset;' height='300px' width='400px'>
                     </form>";

              echo "<form-group mx-sm-3 mb-2>";
                //for x 
                echo"<div class='form-group form-inline' style='margin-top: 35px;'>";
                echo"  <label class='form-inlineinput' for='inlineinput1'> X </label>";
                //x textbox
                echo"<input class='form-control form-control-sm' type='text' id='inlineinput' value='$foo_x' name='forx' size='10px'>";
                echo"</div>";

                 //for y 
                echo"<div class='form-group form-inline'>";
                echo"  <label class='form-inlineinput' for='inlineinput1'> Y </label>";
                //y textbox
                echo"<input class='form-control form-control-sm' type='text' id='inlineinput' value='$foo_y' name='fory' size='10px'>";
                echo"</div>";
              echo "</form>";
            }
            
            else
            {
              //default image to display if no image is found
              echo "<img src='../img/no map.jpg' height='300' width='400'>";
            }
          }
        ?>

        <!--QUERY FOR LOCATION DROPDOWN-->  
        <section class="row placeholders">    
          <?php
            //for error reporting
            error_reporting(E_ALL);
            ini_set('display_errors', 1);

            //query location table for the dropdown
            $lquery = mysqli_query($con, "
            SELECT location_ID, location_name, location.building_ID
            FROM location
            WHERE location.building_ID = {$selectedbldg}
            ");

            //declare variable to store selected location option
            $selectedloctn = null;

            //store the value of the input field for $foo_x
            $getx = $_GET['forx'];
            $gety = $_GET['fory'];

            // if the form for location dropdown list was submitted
            if (!empty($_POST['loctn'])) 
            {
              // store selected location_ID
              $selectedloctn = $_POST['loctn'];
                         
              //update x and y value in location table
              $updt = mysqli_query($con,"
              UPDATE location SET x='$getx', y='$gety'
              WHERE location_ID = {$selectedloctn}
              ");            
            } 
          ?>
        </section>