-3

this img contain my updation.php code

this img contain my updation.php code

when i insert data into textbox and then click submit but at that time

javascript alertbox sys "your data has been updated successfully" and than browser display errorss messeges

error messeges

<?php
    $con = mysqli_connect('127.0.0.1','root','','');
    mysqli_select_db($con,'brm_db');

    $q = "SELECT * FROM book";

    $result = mysqli_query($con,$q);

    $num = mysqli_num_rows($result);

    mysqli_close($con);
?>


<!DOCTYPE html>
<html>
    <head>
        <title> Update Record </title>
        <link rel="stylesheet" href="./css/viewstyle.css" />
    </head>
    <body>
        <h1 align="center"> Book Record Management</h1>
    <center>
        <form action="updation.php" method="post">
        <table id="view_table">
            <tr>
                <th>Book Id</th>
                <th>Title</th>
                <th>Price</th>
                <th>Author</th>
            </tr>

            <?php
                for($i=1;$i<=$num;$i++)
                {
                    $row = mysqli_fetch_array($result);
            ?>
            <tr>
                <td> <?php echo $row['bookid'];?>
                    <input type="hidden" name="bookid <?php echo $i ;?>" value="<?php echo $row['bookid'];?>" /> </td>

                <td><input type="text" name="title <?php echo $i ;?> "value="<?php echo $row['title'];?>" /></td>
                <td><input type="text" name="price <?php echo $i ;?> "value="<?php echo $row['price'];?>" /></td>
                <td><input type="text" name="author <?php echo $i ;?> "value="<?php echo $row['author'];?>" /></td>
            </tr>
            <?php
                }
            ?>
            </table>
            <input type="submit" value="Update" style="background-color:lightgreen;width:100px;" />
            </form>
        </center>
    </body>

</html> 
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345

1 Answers1

0

Declare array assigned to those before entering into the for loop like the following

$bookid = array();

$title = array();

$price = array();

$author = array();

//for loop goes here

Instead of this type I would like to suggest you to have a single array as follows and then store in it

$books = array();

for($i = 0; $i <= $records; $i++){
    $books[$i]['bookid'] = $_POST[$index1];
    $books[$i]['title'] = $_POST[$index1];
    $books[$i]['price'] = $_POST[$index1];
    $books[$i]['author'] = $_POST[$index1];
}

Now loop the above $books array as follows, which will be very convenient to achieve

foreach($books as $book){

}
yivi
  • 42,438
  • 18
  • 116
  • 138
Channaveer Hakari
  • 2,769
  • 3
  • 34
  • 45