如何在PHP中使用post方法捕获表中每个用户的特定主id?
我对编程一无所知。基本上,我正在使用PHP和MySQL处理crud操作 下面是我从数据库检索数据的代码。请注意,我使用了 用于捕获每个用户的主键(如何在PHP中使用post方法捕获表中每个用户的特定主id?,php,mysql,bootstrap-modal,crud,Php,Mysql,Bootstrap Modal,Crud,我对编程一无所知。基本上,我正在使用PHP和MySQL处理crud操作 下面是我从数据库检索数据的代码。请注意,我使用了 用于捕获每个用户的主键(id)的隐藏输入字段 <div class="table-responsive"> <table id="datatable-buttons" class="table table-striped jambo_table bulk_action"> <thead> <tr class=
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>
因此,请帮助我仅检索所选用户的数据。您必须在SELECT语句中使用WHERE子句。确保使用准备好的语句来避免SQL注入 以下是根据您的需要更改的[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>
客户名称
平底锅
商品及服务税登记类型
添加
'select*from customer\u master where customerId=$\u POST['customerId']”您正在寻找类似的东西吗?对,兄弟,我只在寻找这个。它有效吗@amitNow查看关于参数化queriesno bro它现在工作。给出未定义的错误
<?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>