Adding php values ​​from a php ISBN script to a text box entry

i have been trying to fix this problem for hours and i could not try to fix it, ive been searching high and low for help on putting these php values ​​from our barcode scanner script but it refused to display the text box. Is there anything i can do to make the php values ​​appear in the text box? Here is the code:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Add Book Records</title>
    <link rel="stylesheet" type="text/css" href="CSSF.css">
    <link rel="stylesheet" type="text/css" href="bootstrapcssbootstrap.min.css">
                    <script type="text/javascript" src="bootstrapjsbootstrap.bundle.js"></script>
    <script type="php">
    <?php 
        function searchisbn(){
            if(!empty($_POST['isbn'])){
                if(strlen($_POST['isbn']) == 10 or strlen($_POST['isbn']) == 13){       
                $isbn_url="https://www.googleapis.com/books/v1/volumes?q=isbn:" . $_POST['isbn'];
                $isbn_json = file_get_contents($isbn_url);  
                $isbn_array = json_decode($isbn_json, true);
    
                //echo '<pre>'; print_r($isbn_array); echo '</pre>';
                    if($isbn_array['totalItems']!=0){
                        $isbn = $_POST['isbn'];
                        $title = $isbn_array['items'][0]['volumeInfo']['title'];
                        $author = $isbn_array['items'][0]['volumeInfo']['authors'][0];
                        $category = $isbn_array['items'][0]['volumeInfo']['categories'][0];
                        $publisher = $isbn_array['items'][0]['volumeInfo']['publisher']; 
                        $published = $isbn_array['items'][0]['volumeInfo']['publishedDate'];
                        if(array_key_exists("pageCount", $isbn_array['items'][0]['volumeInfo'])){   
                            $pages = $isbn_array['items'][0]['volumeInfo']['pageCount'];
                        }
                        else{
                            $pages = "not found";
                        }
                        if(array_key_exists("description", $isbn_array['items'][0]['volumeInfo'])){ 
                            $description = $isbn_array['items'][0]['volumeInfo']['description'];
                        }
                        else{
                            $description = "not found";
                        }
                        echo "<h1>".$title."</h1>";
                        echo "<h1>".$author."</h1>";
                        echo "<h1>".$category."</h1>";
                        echo "<h1>".$publisher."</h1>";
                        echo "<h1>".$published."</h1>";
                        echo "<h1>".$pages."</h1>";
                        echo "<p>".$description."</p>";
                    }
                    else{
                        echo "<h1>Book not found within the API</h1>";
                    }
                }
                else{
                    echo '<script>alert("Enter ISBN 10 or 13")</script>';
                }
            }   
            else{
                echo '<script>alert("ISBN cannot be blank")</script>';
            }
        }
        
        function addbook(){
            if(isset($_POST['create'])){
                $bname=$_POST['bname'];
                $author=$_POST['author'];
                $genre=$_POST['genre'];
                $isbn=$_POST['isbn'];
                $status="Available";
                include 'sqlconnection.php';
                if($bname=='' or $author=='' or $genre=='' or $isbn==''){
                    echo '<script>alert("Field Cannot be Empty!")</script>';
                    return false;
                }
                else{
                    $sqlstring="insert INTO bookdb1(`Bookname`, `Author`, `Genre`, `ISBN`, `Status`) VALUES ('$bname','$author','$genre','$isbn','$status')";
                    mysqli_query($sqlcon, $sqlstring);
                    mysqli_close($sqlcon);
                    echo '<script>alert("Book successfully added!")</script>';
                    echo ("<script LANGUAGE='JavaScript'>window.location.href="https://stackoverflow.com/questions/72041022/viewbook.php";</script>");
                }   
            }
        }
    ?>
    </script>
</head>

<?php
    $title="";
    $author="";
    $category="";
    $publisher="";
    $published="";
    $pages="";
    $description="";
?>
<?php
    if(isset($_POST['isbnbutton']))
    {
        searchisbn();

    }
?>
<body>
<?php include('include/homeheader.php'); ?>
<div class="container-fluid">
    <div class="row content">
        <div class="col-sm-2 col-md-2 col-lg-2"></div>

        <div class="col-sm-8 col-md-8 col-lg-8">
            <br><h4>Add Books</h4>
            <hr><br>
            <form name="Add" method='POST'>
            <table border="1" width="30%" align="center" id="tabletest">
                    <td colspan="2" class="singlheader"><center><b><h3>ADD BOOK RECORD</h3></b></center></td>
                <tr>
                    <td>ISBN</td>
                    <td><input type="text" name="isbn"><input type="submit" name="isbnbutton" value="Search"><br><br></td>
                
                <tr>
                    <td width="40%"><br>BOOK NAME<br><br></td>
                    <td width="40%"><br><input type="text" name="bname" value="<?php echo htmlentities($title); ?>"><br><br></td>
                <tr>
                    <td>AUTHOR<br><br></td>
                    <td><input type="text" name="author" value="<?php echo htmlentities($title); ?>"><br><br></td>
                <tr>
                    <td>GENRE<br><br></td>
                    <td><input type="text" name="genre" value="<?php echo htmlentities($category); ?>"><br><br></td>
                <tr>
                    <td>Publisher</td>
                    <td><input type="text" name="publsher" value="<?php echo htmlentities($publisher); ?>"><br><br></td>
                <tr>
                    <td>Published Date</td>
                    <td><input type="text" name="published" value="<?php echo htmlentities($published); ?>">"><br><br></td>
                <tr>
                    <td>Page Count</td>
                    <td><input type="text" name="pages" value="<?php echo htmlentities($pages); ?>"><br><br></td>
                <tr>
                    <td>Description</td>
                    <td><textarea name="description" rows="5" value="<?php echo htmlentities($description); ?>""></textarea></td>
                
                <tr>
                    <td class="singlheaderleft"></td>
                    <td class="singlheaderright"><input type="submit" name="create" value="Create"></td>
            </table>
            <br>
        </div>

        <div class="col-sm-2 col-md-2 col-lg-2"></div>
    </div>
</div>
<?php 
    include('include/footer.php');
    echo addbook();
?>

</body>
</html>

Leave a Comment