gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 10:14:27 24 4
gpt4 key购买 nike

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

<!--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>

我总是收到警告:“ undefined index :forx”或“ undefined index :fory”这些是我用来从输入中获取 x 和 y 值的变量。请帮助我知道我哪里错了。除了错误之外,我也无法让它更新 MySQL 表中的 x 和 y 列值。

最佳答案

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

关于php - 单击按钮后如何使用 php 更新 mysql 表中的 x 和 y 列值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50323713/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com