how to update database using php,mysql

Arebhy Sridaran

hi i am developing hotel website. I have a page which is show all available and booked room in a page using php and mysql.the booked room display as red background color with Exclamation button. if i click that exclamation marked button room status should be change from booked to available. his same function should be done in available room portion. available room should be display with green background color with tick button. if click tick button available status should be change from available to booked.

here is my html code

<?php while($row = mysql_fetch_array($result)):;?>
                <div class="w3-small">
                  <?php if ($row['status'] == 'available'){ 
                        echo"<div class='w3-container w3-green w3-text-white w3-padding-small'>
                            <div class='w3-left'><i class='fa fa-users w3-tiny'></i></div>
                            <div class='w3-right'>".
                            "<h3 name='$row[0]'>".$row['roomno']."</h3>".
                            "</div>".
                          "<div class='w3-clear'></div>";
                        echo "<form action='editstatus.php' method='POST'><button class='buttonmark buttoncan' name='available'><i class='fa fa-exclamation-triangle'></i></button></form></div>";
                        }
                        elseif ($row['status']== 'booked') {
                          echo"<div class='w3-container w3-red w3-text-white w3-padding-small'>
                            <div class='w3-left'><i class='fa fa-users w3-tiny'></i></div>
                            <div class='w3-right'>".
                            "<h3 name='$row[0]'>".$row['roomno']."</h3>".
                            "</div>".
                          "<div class='w3-clear'></div>";
                        echo "<form action='editstatus.php' method='POST'><button class='buttonmark buttonok' name='booked'><i class='fa fa-check-square-o'></i></button></form></div>";
                        }
                      ?>
                        <br> <br>
                </div>
              <?php endwhile;?> 

my php code is

<?php
ob_start(); //After ob_start this output is saved in output buffer, so you can later decide what to do with it. 
include("../database/connection.php");

    $sql1="UPDATE acroom SET status='$_POST[booked]' WHERE roomno='$row[roomno]'";
    // If result matched $myusername and $mypassword, table row must be 1 row
        if(mysql_query($sql1)){
            header("Location:sample.php");
            echo "Records inserted successfully into database.";

        } else{

            echo "ERROR: Could not able to execute $sql. " . mysql_error($cn);

        }

ob_end_flush();
?>

when i run my browser it show "Records inserted successfully into database" but database not yet to change. please help me o resolve my problem.

enter image description here

Arebhy Sridaran

finally i got the answer. I edit my html page as below

<?php while($row = mysql_fetch_array($result)):;?>
                <div class="w3-small">
                  <?php if ($row['status'] == 'available'){ 
                        echo"<div class='w3-container w3-green w3-text-white w3-padding-small'>
                            <div class='w3-left'><i class='fa fa-users w3-tiny'></i></div>
                            <div class='w3-right'>".
                            "<h3>".$row['roomno']."</h3>".
                            "</div>"."<div class='w3-clear'></div>
                            <a href='editstatus.php?d=$row[roomno]' class='buttonmark buttoncan'><i class='fa fa-exclamation-triangle'></i></a>

                          </div>";
                        }
                        elseif ($row['status']== 'booked') {
                          echo"<div class='w3-container w3-red w3-text-white w3-padding-small'>
                            <div class='w3-left'><i class='fa fa-users w3-tiny'></i></div>
                            <div class='w3-right'>".
                            "<h3>".$row['roomno']."</h3>".
                            "</div>".
                          "<div class='w3-clear'></div>".
                          "<a class='buttonmark buttonok' href='editstatus.php?e=$row[roomno]'><i class='fa fa-check-square-o'></i></a></div>";
                        }
                      ?>
                        <br> <br>
                </div>
              <?php endwhile;?>

and my php page

<?php
ob_start(); //After ob_start this output is saved in output buffer, so you can later decide what to do with it. 
include("../database/connection.php");

if( isset($_GET['d']) )
{
    $roomno = $_GET['d'];
    $sql= "UPDATE acroom SET status='booked' WHERE roomno='$roomno'";
    $res= mysql_query($sql) or die("Could not update".mysql_error());
        echo "<meta http-equiv='refresh' content='0;url=sample.php'>";
}

if( isset($_GET['e']) )
{
    $roomno = $_GET['e'];
    $sql= "UPDATE acroom SET status='available' WHERE roomno='$roomno'";
    $res= mysql_query($sql) or die("Could not update".mysql_error());
        echo "<meta http-equiv='refresh' content='0;url=sample.php'>";
}
ob_end_flush();
?>

now its working fine :-)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Update database using MySQL and PHP

How to update Sql database using PHP

How to update database using PHP variables?

How to UPDATE the data in the database using php

Update MySQL database using php statement

unable to update value in mysql database using php

How to have a Button update a mysql database in php

Mysql UPDATE using PHP and AJAX, can't update database

How can I update single field of an item in database using PHP and MySQL

How to update database using pandastable

Update image in database using PHP

Update information in database using php

How to update an SQL database with form data using PHP?

How to update a database using php by uploading a CSV file?

Connection class to MySQL database using PHP, insert , update, delete

using mysql NOW() function to update row in database not working in PHP query

Users cannot update information in MySQL database using PHP form

Unable to update MYSQL database table fields using php in XAMPP

How to Update Data using PHP MYSQL in Android

How to update multiple columns in mysql using php

How to store images in mysql database using php

How to connect to a new database using PHP MySQL

How to input a date into mysql database using PHP

How to append data in a mysql database using php

How to update a table in a mysql database

How to update mysql database, with a variable?

MYSQL and PHP database update wont update database

How to update database with entire html table (PHP, MySQL)

How to update a different database table with info from my current database table, using mySQL?