I want to display form data on another page so that when I click "More View" button and the inputed data of each user will display on another page. This is the code of the HTML form:
registerbooks.php
<!DOCTYPE Html>
<<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Register books</title>
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
</head>
<body>
<div id='main-content'>
<form action="connect.php" method="POST">
<input type="text" name="tittle" placeholder="Book Tittle"></br>
<input type="text" name="author" placeholder="Author"></br>
<input type="text" name="copies" placeholder="Copies Available"></br>
<button type="submit" name="submit">submit</button>
<button type="reset" value="Reset">Reset</button>
</form>
</div>
</body>
</html>
This is the connection.php
<?php
$servername = 'localhost';
$username = 'root';
$password = '';
$dbname = 'list';
// Create connection
$connect = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$connect) {
die("Connection failed: " . mysqli_connect_error());
}
if (isset($_POST['submit'])){
$Tittle = $_POST['tittle'];
$Author = $_POST['author'];
$Copies = $_POST['copies'];
$query = "INSERT INTO books(Tittle,Author,Copies) VALUES('$Tittle' , '$Author' , '$Copies')";
$result=mysqli_query($connect, $query);
if($result){
echo 'Available Books updated';
}
else{
echo "Failed to update";
}
}
?>
The fom is displayed in this page:
Availablebooks.php
<!DOCTYPE HTML>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Available books</title>
</head>
<body>
<?php
$servername = 'localhost';
$username = 'root';
$password = '';
$dbname = 'list';
$connect = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$connect) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM books";
$result=mysqli_query($connect, $sql);
?>
<table align="centre" border="1px" width="600px" line-height="30px" >
<tr>
<th colspan="4">Available books</th>
</tr>
<tr>
<th>ID</th>
<th>Book tittle</th>
<th>Author</th>
<th>More Details</th>
</tr>;
<?php
while ($rows = $result->fetch_assoc())
{
?>
<tr>
<td><?php echo $rows['ID']; ?> </td>
<td> <?php echo $rows['Tittle']; ?> </td>
<td> <?php echo $rows['Author']; ?> </td>
<td> <button type="submit"><a href="http://localhost:80/orders.php/?id=<?php echo $rows['ID']; ?>">More Views</a></button> </td>
</tr>
<?php
}
?>
</table>
</body>
</html>
When I click "more views" button, I want each user data to be displayed in "orders.php"
<!DOCTYPE HTML>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Available books</title>
</head>
<body>
<?php
$servername = 'localhost';
$username = 'root';
$password = '';
$dbname = 'list';
$connect = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$connect) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM books WHERE id=(Tittle,Author,Copies )";
$result=mysqli_query($connect, $sql);
?>
<table align="left" border="1px" width="600px" line-height="30px" >
<tr>
<th colspan="4">Ordered books</th>
</tr>
<tr>
<th>ID</th>
<th>Book tittle</th>
<th>Author</th>
<th>Number of copies</th>
</tr>
<?php
while ($rows = $result->fetch_assoc())
{
?>
<tr>
<td><?php echo $rows['ID']; ?> </td>
<td><?php echo $rows['id']; ?> </td>
<td> <?php echo $rows['id']; ?> </td>
<td> <?php echo $rows['id']; ?> </td>
</tr>
<?php
}
?>
</table>
</body>
</html>
But the code is not working. Please help me to resolve this issue. Thanks