简体   繁体   中英

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.

 $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.

在此处输入图片说明

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.

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

  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="...)

  2. You are using $_POST[] instead of $_GET[]. See What is the difference between POST and GET?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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