简体   繁体   English

如何在HTML表格的可点击行中发送数据

[英]How to send data in a clickable row of an html table

I am doing a library project to reserve books.Here, I search for a book and get the data on the database into a table using php.Here is the code. 我正在做一个图书馆项目来保留书籍。在这里,我搜索一本书,然后使用php将数据库中的数据放入表中。

 $sql=" SELECT DISTINCT books.isbn,books.bname,books.bauthor,books.btype FROM books WHERE CONCAT(isbn, '', bname, '', bauthor, '', btype) LIKE '%" . $search . "%' "; $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { ?> <tr> <td><?php echo('<a href="bookres.php?[$bisb]='.$row['isbn'].'">'.$row['isbn'].'</a>');?></td> <td><?php echo $row['bname']?></td> <td><?php echo $row['bauthor']?></td> <td><?php echo $row['btype']?></td> </tr> <?php } } else { echo "0 results"; } 

In the table,I have made the ISBN column clickable. 在表中,我已使ISBN列可单击。

在此处输入图片说明

When I click on a books ISBN number, I need to display the clicked ISBN number on the reditected page.On the redirected page(bookres.php), I have written the following code. 当我单击书籍的ISBN号时,需要在重新定向的页面上显示单击的ISBN号。在重定向的页面(bookres.php)上,我编写了以下代码。

 <?php $servername = "localhost"; $username = "root"; $password = ""; $db = "vidunena"; if (mysqli_connect_error()) { printf("Connect failed: %s\\n", mysqli_connect_error()); exit(); } $bisb = ""; if(isset($_POST['bisb'])) { $bisb = $_POST["bisb"]; } echo $bisb; ?> 

However, when I clich on an ISBN number, it,s being redirected to the given page but the ISBN number is not echoed in it.How can I fix this? 但是,当我使用ISBN号时,它被重定向到给定的页面,但是ISBN号中没有回显。如何解决此问题?

  1. Your link is wrong, the parameter must be named exactly how you're going to use it on the target page. 您的链接错误,必须在目标页面上准确命名参数的使用方式。 So it should be echo("<a href="bookres.php?bisb="...) 所以应该是echo("<a href="bookres.php?bisb="...)

  2. You are using $_POST[] instead of $_GET[]. 您正在使用$ _POST []而不是$ _GET []。 See What is the difference between POST and GET? 请参阅POST和GET有什么区别?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM