如何使用 PHP 中的 post 方法捕获 table 中每个用户的特定主 ID?
How to catch particular primary id of each user in table using post method in PHP?
我对编程完全陌生。基本上我正在使用 PHP 和 MySQL.
进行 crud 操作
下面是我从数据库中检索数据的代码。请注意我用过
隐藏输入字段以捕获每个用户的主键 (id
)。
<div class="table-responsive">
<table id="datatable-buttons" class="table table-striped jambo_table bulk_action">
<thead>
<tr class="headings">
<th class="column-title">Client Name</th>
<th class="column-title">PAN </th>
<th class="column-title">GST Registration Type </th>
<th class="column-title no-link last"><span class="nobr">Add</span>
</th>
</tr>
</thead>
<?php
$sql = mysqli_query($conn,'select * from customer_master');
while ($row = mysqli_fetch_array($sql))
{?>
<tbody>
<tr class="even pointer">
<td class=" "><?php echo $row['companyName'];?></td>
<td class=" "><?php echo $row['pan'];?></td>
<td class=" "><?php echo $row['gstTaxType'];?></td>
<td><input type="hidden" name="pid" value="<?php echo $row['customerId'];?>"></a> | <a type="" class="" data-toggle="modal" data-target="#edit_customer_profile"><i class="fa fa-pencil" aria-hidden="true"></i></a></td>
</tr>
</tbody>
<?php }?>
</table>
</div>
当点击 data-target="#edit_customer_profile"
第二个模式将
仅针对特定 customerId
打开数据。
为此,我在第二个模态中使用了这个查询。
<?php $sql = mysqli_query($conn,'select * from customer_master');
while ($row = mysqli_fetch_array($sql)) {?>
所以请帮我检索仅选定用户的数据。
您必须在 SELECT 语句中使用 WHERE 子句。请务必使用准备语句以避免 SQL-Injection.
此处根据您的需要更改了 [PHP-docs] (http://php.net/manual/de/mysqli.prepare.php) 中的示例:
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* create a prepared statement */
if ($stmt = $mysqli->prepare("SELECT * FROM customer_master WHERE customerId=?")) {
/* bind parameters for markers */
$stmt->bind_param("i", $_POST['customerId']);
/* execute query */
$stmt->execute();
/* bind result variables */
$stmt->bind_result($customerId);
$stmt->bind_result($companyName);
$stmt->bind_result($pan);
$stmt->bind_result($gstTaxType);
/* fetch value */
$stmt->fetch();
/* close statement */
$stmt->close();
}
/* close connection */
$mysqli->close();
?>
<div class="table-responsive">
<table id="datatable-buttons" class="table table-striped jambo_table bulk_action">
<thead>
<tr class="headings">
<th class="column-title">Client Name</th>
<th class="column-title">PAN </th>
<th class="column-title">GST Registration Type </th>
<th class="column-title no-link last"><span class="nobr">Add</span></th>
</tr>
</thead>
<tbody>
<tr class="even pointer">
<td class=" "><?php echo $companyName;?></td>
<td class=" "><?php echo $pan;?></td>
<td class=" "><?php echo $gstTaxType;?></td>
<td><input type="hidden" name="pid" value="<?php echo $customerId;?>"></a> | <a type="" class="" data-toggle="modal" data-target="#edit_customer_profile"><i class="fa fa-pencil" aria-hidden="true"></i></a></td>
</tr>
</tbody>
</table>
</div>
我对编程完全陌生。基本上我正在使用 PHP 和 MySQL.
进行 crud 操作下面是我从数据库中检索数据的代码。请注意我用过
隐藏输入字段以捕获每个用户的主键 (id
)。
<div class="table-responsive">
<table id="datatable-buttons" class="table table-striped jambo_table bulk_action">
<thead>
<tr class="headings">
<th class="column-title">Client Name</th>
<th class="column-title">PAN </th>
<th class="column-title">GST Registration Type </th>
<th class="column-title no-link last"><span class="nobr">Add</span>
</th>
</tr>
</thead>
<?php
$sql = mysqli_query($conn,'select * from customer_master');
while ($row = mysqli_fetch_array($sql))
{?>
<tbody>
<tr class="even pointer">
<td class=" "><?php echo $row['companyName'];?></td>
<td class=" "><?php echo $row['pan'];?></td>
<td class=" "><?php echo $row['gstTaxType'];?></td>
<td><input type="hidden" name="pid" value="<?php echo $row['customerId'];?>"></a> | <a type="" class="" data-toggle="modal" data-target="#edit_customer_profile"><i class="fa fa-pencil" aria-hidden="true"></i></a></td>
</tr>
</tbody>
<?php }?>
</table>
</div>
当点击 data-target="#edit_customer_profile"
第二个模式将
仅针对特定 customerId
打开数据。
为此,我在第二个模态中使用了这个查询。
<?php $sql = mysqli_query($conn,'select * from customer_master');
while ($row = mysqli_fetch_array($sql)) {?>
所以请帮我检索仅选定用户的数据。
您必须在 SELECT 语句中使用 WHERE 子句。请务必使用准备语句以避免 SQL-Injection.
此处根据您的需要更改了 [PHP-docs] (http://php.net/manual/de/mysqli.prepare.php) 中的示例:
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* create a prepared statement */
if ($stmt = $mysqli->prepare("SELECT * FROM customer_master WHERE customerId=?")) {
/* bind parameters for markers */
$stmt->bind_param("i", $_POST['customerId']);
/* execute query */
$stmt->execute();
/* bind result variables */
$stmt->bind_result($customerId);
$stmt->bind_result($companyName);
$stmt->bind_result($pan);
$stmt->bind_result($gstTaxType);
/* fetch value */
$stmt->fetch();
/* close statement */
$stmt->close();
}
/* close connection */
$mysqli->close();
?>
<div class="table-responsive">
<table id="datatable-buttons" class="table table-striped jambo_table bulk_action">
<thead>
<tr class="headings">
<th class="column-title">Client Name</th>
<th class="column-title">PAN </th>
<th class="column-title">GST Registration Type </th>
<th class="column-title no-link last"><span class="nobr">Add</span></th>
</tr>
</thead>
<tbody>
<tr class="even pointer">
<td class=" "><?php echo $companyName;?></td>
<td class=" "><?php echo $pan;?></td>
<td class=" "><?php echo $gstTaxType;?></td>
<td><input type="hidden" name="pid" value="<?php echo $customerId;?>"></a> | <a type="" class="" data-toggle="modal" data-target="#edit_customer_profile"><i class="fa fa-pencil" aria-hidden="true"></i></a></td>
</tr>
</tbody>
</table>
</div>