Hi, This is part hotel managment system but we want to create new feature where we can edit room type but this is not my code but it my program because I cant contact programmer so end up need to do my self, so got problem where cant update

Here is only few line of code that I just take from file because it a lot dont worry about connect to DB it in separate file

<?
include('z_header.php');
$general_tab='class="active"';

if ($_REQUEST['edit_types'] == '1') {
    $id = mysql_result(mysql_query("SELECT * FROM `ref_types` WHERE `id`=" . $row[id]), 0);
    mysql_query("UPDATE `ref_types` SET `code`= '$_REQUEST[code_edit]', `description`='$_REQUEST[description_edit]', `price`='$_REQUEST[price_edit]', `discount`='$_REQUEST[discount_edit]'WHERE `id`='".$id."'");

    $types_tab='class="active"';
    $general_tab=''; 
    $usermessage = true;
    $usermessage_text = 'Room type <b>'.$room_code.'</b> has been Edited successfully!';
}

?>

<table class="listing" cellpadding="0" cellspacing="0" width="100%">
                                        <tr>

                                            <th width="11%" height="21"><?= CODE ?></th>
                                            <th width="19%"><?= HOTEL ?></th>
                                            <th width="23%"><?= DESN ?></th>
                                            <th width="13%"><?= PRICE ?></th>
                                            <th width="13%"><?= DIS ?></th>
                                            <th width="10%"><?= EDIT ?></th>
                                            <th width="11%"><?= DELETE ?></th>

                                        </tr>
                                        <?
                                        $i = 0;

                                        $sql = "SELECT ref_types.*, hotels.hotel_name FROM `ref_types`, hotels WHERE ref_types.hotel_id=hotels.id ";

                                        if (($_REQUEST[hotel_selected] != '-1') && ($_REQUEST[hotel_selected] != '')) {
                                            $sql.='AND ref_types.hotel_id=' . $_REQUEST[hotel_selected];
                                        }

                                        $q = mysql_query($sql);
                                        while ($row = mysql_fetch_assoc($q)) {
                                            ?>
                                            <tr<?
                                        if ($i % 2 == 0) {
                                            echo(' class="even"');
                                        }
                                            ?>>
                                                <td><?= $row['code'] ?></td>
                                                <td><?= $row['hotel_name'] ?></td>
                                                <td><?= $row['description'] ?></td>
                                                <td><?= $row['price'] ?></td>
                                                <td><?= $row['discount'] ?></td>
                                                <td><a href="#" id="myButton<?= $row['id'] ?>" data-reveal-id="myNewModal" data-animation="fadeAndPop" data-animationspeed="300" data-closeonbackgroundclick="true" data-dismissmodalclass="close-reveal-modal"><img src="img/add2.png"></a></td>
                                                <td><a href="#" onclick="if (confirm('Are you sure to delete `<?= $row['description'] ?>`? This action will affect all the rooms for all hotel as well!')) {location.href='settings.php?delete_type=1&id=<?= $row[id] ?>';}  "><img src="img/icons/minus-circle.png"></a></td>
                                            </tr>

                                            <div id="myNewModal<?= $row['id'] ?>" class="reveal-modal">


                                                <?
                                                $sql_supp = "SELECT * FROM `ref_types` WHERE `id`=" . $row[id];
                                                $q_supp = mysql_query($sql_supp);
                                                $row_supp = mysql_fetch_assoc($q_supp);
                                                ?>
                                                <h2><?= $row_supp['code'] ?> :<?= $row_supp['description'] ?> </h2>
                                                <hr>
                                                <form action="settings.php" method="post" id="editform<?= $row_supp['id'] ?>" name="editform<?= $row_supp['id'] ?>">
                                                    <input type="hidden" value="1" name="general" />
                                                    <div class="column grid-16">
                                                        <p>
                                                            <label><?= CODE ?>:</label><br/>
                                                            <input class="text big" value="<?= $row['code'] ?>" type="text" name="code" tabindex="1" />
                                                        </p>
                                                    </div>
                                                    <div class="column grid-5">
                                                        <p>
                                                            <label><?= DESN ?>:</label><br/>
                                                            <input class="text big" value="<?= $row['description'] ?>" type="text" name="description" tabindex="1" />
                                                        </p>
                                                    </div>
                                                    <div class="column grid-5">
                                                        <p>
                                                            <label><?= PRICE ?>:</label><br/>
                                                            <input class="text big" value="<?= $row['price'] ?>"  type="text" name="price<?= $row_supp['id'] ?>" id="price<?= $row_supp['id'] ?>" tabindex="2" onchange="AddTotalT()"/>
                                                            <input type="hidden" value="0" name="price_hidden<?= $row_supp['id'] ?>" id="price_hidden<?= $row_supp['id'] ?>"/>
                                                        </p>
                                                    </div>
                                                    <div class="column grid-5">
                                                        <p>
                                                            <label><?= DIS ?>:</label><br/>
                                                            <input class="text big" value="<?= $row['discount'] ?>" type="text" name="discount<?= $row_supp['id'] ?>" id="discount<?= $row_supp['id'] ?>" tabindex="3" onkeyup="AddDiscountT()" />


                                                        </p>



                                                        <input type="submit" class="button small yellow" value="<?= APPLY ?>" />
                                                        </p>
                                                    </div>
                                                </form>

                                                <hr>


                                            </div>


                                            <script type="text/javascript">
                                                $(document).ready(function() {
                                                    $('#myButton<?= $row['id'] ?>').click(function(e) {

                                                        e.preventDefault();
                                                        $('#myNewModal<?= $row['id'] ?>').reveal({
                                                            animation: 'fadeAndPop',                   //fade, fadeAndPop, none
                                                            animationspeed: 300,                       //how fast animtions are
                                                            closeonbackgroundclick: true,              //if you click background will modal close?
                                                            dismissmodalclass: 'close-reveal-modal'    //the class of a button or element that will close an open modal
                                                        });

                                                        e.unlockModal();
                                                    });
                                                });
                                            </script>



                                            <?
                                            $i++;
                                        }
                                        ?>
                                    </table> `Inline Code Example Here` 

Recommended Answers

All 3 Replies

I feel your pain

Is room types a limited option? ie. Theres 7 room types and you don't want people to be able to make up as many as they want?

You would need to update the sql query near the top also the $id mysql select looks like it won't work, $row[id] is probably undefined so won't be working? the id should come from a $_GET or $_POST variable coming from another page

and then add an array with the possible room types:

$id = mysql_result(mysql_query("SELECT * FROM `ref_types` WHERE `id`=" . $row[id]), 0);
mysql_query("UPDATE `ref_types` SET `code`= '$_REQUEST[code_edit]', `description`='$_REQUEST[description_edit]', `price`='$_REQUEST[price_edit]', `discount`='$_REQUEST[discount_edit]'WHERE `id`='".$id."'");

turns into:

<?php 
    $roomTypes = array('double'=>'Double Room','single'=>'Single Room','kingsize'=>'King size Room');
    if(!in_array($_REQUEST[room_type], $roomTypes)){
        $_REQUEST[room_type] = 'error';
    }
    $id = $_GET['id'];
    mysql_query("UPDATE `ref_types` SET `code`= '$_REQUEST[code_edit]', `description`='$_REQUEST[description_edit]', `price`='$_REQUEST[price_edit]', `discount`='$_REQUEST[discount_edit]', `room_type` = '$_REQUEST[room_type]' WHERE `id`='".$id."'");
?>

Then further on down in the form add this:

<div class="column grid-5">
    <p>
        <label><?= ROOMTYPE ?>:</label><br/>
        <select class="text big" name="room_type" tabindex="2">
            <?php 
            foreach($roomTypes as $k=>$v){
                if($row['room_type'] == $v){
                    echo "<option value='{$k}' SELECTED>{$v}</option>\r\n";
                }else{
                    echo "<option value='{$k}'>{$v}</option>\r\n";    
                }
            }
            ?>
        </select>
    </p>
</div>

Make sure the $_REQUEST[room_type] matches up with the select boxes name name="room_type"

and i've assumed your database fieldname for room type is "room_type" you can change that in the sql query and also where it says $row['room_type']

Thakn for reply I do like this but it only update the first row so I dont know why here code

I put this on top of file in php tag

if ($_REQUEST['edit_types'] == '1') {
    $room_code = mysql_result(mysql_query("SELECT `code` FROM `ref_types` WHERE `id`=".$_REQUEST['id']), 0);
    mysql_query("UPDATE `ref_types` SET `code`= '$_REQUEST[code_edit]', `description`='$_REQUEST[description_edit]', `price`='$_REQUEST[price_edit]', `discount`='$_REQUEST[discount_edit]' WHERE  `id`=".$_REQUEST[id]);

    $types_tab='class="active"';
    $general_tab=''; 
    $usermessage = true;
    $usermessage_text = 'Room type <b>'.$room_code.'</b> has been Edited successfully!';
}

and put this somewhere in body

 <?
                                $sql_edit = "SELECT * FROM `ref_types` WHERE `id`=" . $row['id'];
                                $q_edit = mysql_query($sql_edit);
                                $row_edit = mysql_fetch_assoc($q_edit);

                                ?>


                              <h2><?= EDIT ?> E: <?= $row_edit['id']?> R: <?= $row['id']?></h2>

                                <form action="settings.php" method="POST"  id="myForm<?= $row['id'] ?>" name="myForm<?= $row['id'] ?>">
                                <input type="hidden" value="1" name="edit_types" />
                                <input type="hidden" value="<?= $row['id']?>"  name="id"  />

                                <div class="column grid-8">

                                        <p>
                                            <label><?= CODE ?></label><br/>
                                            <input class="text big" type="text" value="<?= $row_edit['code'] ?>" name="code_edit" tabindex="3" />
                                        </p>
                                        <p>
                                            <label><?= DESN ?></label><br/>
                                            <input class="text big" type="text" value="<?= $row_edit['description'] ?>" name="description_edit" tabindex="5" />
                                        </p>
                                        <p>
                                            <label><?= PRICE ?></label><br/>
                                            <input class="text big" type="text" value="<?= $row_edit['price'] ?>" name="price_edit" tabindex="7" />
                                        </p>
                                        <p>
                                            <label><?= DIS ?></label><br/>
                                            <input class="text big" type="text" value="<?= $row_edit['discount'] ?>" name="discount_edit" tabindex="7" />
                                        </p>

                                        <p>
                                            <input type="submit" class="button small yellow" value="<?= APPLY ?>" />
                                        </p>


                                    </div>

                                </form>  

But it only update the first row for the rest of room type it cant update

$room_code = mysql_result(mysql_query("SELECT `code` FROM `ref_types` WHERE `id`=".$_REQUEST['id']), 0);

This query pulls more than 1 row?

Hopefully someone else can carry on cause i gotta run now

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.