I have table named books, this table will store the data of each book . each book has 5 pages only and each page has different details which belong to the same book. the name of the book stored in a column named "jalad" and the pages stored in a column named "sanad"
I want PHP allows to me inserted a new book after totally completing the insertion of the first book which has five-page and in case I entered less than 5 pages then will stop me to insert a new book before completing the first one. Any idea, please. I used this code but it does not work perfectly. Please any help.
The code:
<?php
// connect to the database
// $serverName = "";   
//$database = "";  
$serverName = "";   
$database = "";  
$connectionInfo = array( "Database"=>$database );  
$conn = sqlsrv_connect( $serverName, $connectionInfo);  
if( $conn )  
{  
    echo "Connection established.\n";  
}  
else  
{  
    echo "Connection could not be established.\n";  
    die( print_r( sqlsrv_errors(), true));  
}
$x= $_POST['x'];
$y= $_POST['y'];
$sql = "SELECT count(x) as countnumber FROM books where x='$x' ";
    
$stmt = sqlsrv_query( $conn, $sql );
while($row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC)) {           
    $rowc= $row['countnumber'];
    echo $rowc;
    if ($rowc <=5) {
        $sql = "INSERT INTO books (x,x) 
        VALUES ('$x','$x' )";
        //  echo  $sql;
   
        if (sqlsrv_query($conn, $sql)) {
            echo "your data saved";
        }
        else {echo "error";}        
    }
    else {
        echo"You have to complete the page of the current book";
    }
}
?>
 
     
    