【发布时间】:2018-04-24 12:24:50
【问题描述】:
当我使用<a href 在任何记录上单击编辑按钮时,我想从 url 获取数据并允许编辑该记录,使用 $_GET 如何将值传递给我的 SQL 查询以检索记录?
我们将不胜感激。
<?php
include("../include/connect.php");
$gid = (empty($_GET['cu_id']));
if (isset($_POST['cu_id'])) {
$id = $_POST['cu_id'];
}
if (isset($_POST['cu_name'])) {
$customer = $_POST['cu_name'];
}
if (isset($_POST['email'])) {
$email = $_POST['email'];
}
if (isset($_POST['phone'])){
$phone =($_POST['phone']);
}
if (isset($_POST['password'])) {
$pass =$_POST['password'];
}
if (isset($_POST['coun_id'])) {
$counter =$_POST['coun_id'];
}
if (isset($_POST['card_id'])){
$card_id =$_POST['card_id'];
}
$q=mysqli_query($conn,"SELECT * FROM customer WHERE cu_id ='".$gid."'")or
die (mysqli_error());
$r = mysqli_fetch_assoc ($q);
if (isset($_REQUEST['edit']) AND $_REQUEST['edit'] == 'customer') {
echo "
<form action= '' method ='post' class'input_type'>
<input type='text' name='cu_name' value='".$r['cu_name']."'/><br/>
<input type='text' name='email' value='".$r['email']."'/><br/>
<input type='text' name='phone' value='".$r['phone']."'/><br/>
<input type='text' name='password' value='".$r['password']."'/><br/>
<input type='text' name='coun_id' value='".$r['coun_id']."'/><br/>
<input type='text' name='card_id' value='".$r['card_id']."'/><br/>
<input type='submit' value='save edit' id='sends'/><br/>
<input type='hidden' name='cu_id' value='".$gid."'/><br/>
<input type='hidden' name='edit' value='customer'/><br/>
</form>";
}
/* query */
$query=mysqli_query($conn,"SELECT * FROM customer order by cu_id desc")or
die (mysqli_error());
echo "<center>";
echo"<table width='40%' border='1'cellpadding='5' id='ttb' >
<tr>
<th>cu id </th>
<th>cu name</th>
<th>email </th>
<th>phone </th>
<th> coun id</th>
<th> card id</th>
<th> update</th>
<th>delete</th>
</tr>";
while($row = mysqli_fetch_assoc($query)){
echo "
<tr>
<td>".$row['cu_id']."</td>
<td>".$row['cu_name']."</td>
<td>".$row['email']." </td>
<td>".$row['phone']." </td>
<td> ".$row['coun_id']."</td>
<td> ".$row['card_id']."</td>
<td>
<a href='cucontrol.php?edit&id=".$row['cu_id']."'>edit</a></td>
</td>
<td><a href='cucontrol.php?delete=user&id=".$row['cu_id']."'>delete</a></td>
</tr>";
}
echo "</table>";
echo "</center>";
echo "</div>";
mysqli_close($conn);
?>
【问题讨论】:
-
互联网上有谣言说缩进代码使其可读。你听说过那个谣言吗?
-
如果您要请一群专业人士将他们的宝贵时间花在您遇到的问题上,那么不要只是转储您不可读的代码并将相同的文本复制粘贴 5 次。请正确格式化您的代码并阅读How to Ask。之后,我们也许可以帮助您。
-
我投了反对票,并投票结束,因为您的问题似乎根本没有任何努力。您的问题文本重复了 3 次,但即便如此我也不知道您的问题是什么。请访问帮助中心并阅读how to ask,以及如何创建minimal, complete, and verifiable example。