I am tring to have a user click the submit buttion and the status of that row/room will become closed and the user can reserve more than 1 room at a time

<html>
<head>
</head>
<body> 
     <?php
//include database configuration
include 'config_open_db.php';

//selecting records
$sql="select RoomNumber, Type, Cost, Status from Rooms";

//query the database
$rs=mysql_query($sql) or die($sql.">>".mysql_error());

//count how many records found
$num=mysql_num_rows($rs);

if($num>0){ //check if more than 0 record found

    echo "<table border='1'>";//start table

        //creating  table heading
        echo "<tr>";
            echo "<th>RoomNumber</th>";
            echo "<th>Type Of Room</th>";
            echo "<th>Cost</th>";
            echo "<th>Status</th>";
        echo "</tr>";

        //retrieve our table contents
        while($row=mysql_fetch_array($rs)){
            //extract row

            extract($row);

            //creating new table row per record
            echo "<tr>";
                echo "<td>{$RoomNumber}</td>";
                echo "<td>{$Type}</td>";
                echo "<td>{$Cost}</td>";
        echo "<td>{$Status}</td>";
                echo "<td>" . '<input type="submit" name="submit" value=" Reserve">' . "</td>";               
            echo "</tr>";

        }
    echo "</table>";//end table

}else{ //if no records found
    echo "No records found.";
}

?>
</body>
</html>

Recommended Answers

All 25 Replies

Member Avatar for diafol

Ok, so with what bit are you having trouble?

I can't see any form tags around the bunch of buttons, and none of the submit buttons have a unique id or value to grab the room_id, so I'm assuming you'll be using javascript to run a separate php script (ajax)?

You have no $_POST variable checking (check which button is being pressed) - so I'm assuming that your (form) data handling is happening in a different file?

Sorry, not trying to be unhelpful, but the main components of the functionality that you're asking about seem to be missing from your code.

so i need to add id's would that mean create a new coloum in the database? create a form file and from there what i need maianly direction

Member Avatar for diafol

so i need to add id's would that mean create a new coloum in the database?

Not necessarily, but I would. It's pretty standard to create a PRIMARY KEY - usually an INT datatype which should be set to AUTOINCREMENT.

This means that you can then search the table very quickly as it's INDEXED and you can efficiently JOIN related tables.
In addition, your html buttons need to be able to reference the room that they're linked to somehow.

Let me also explain what Join tables can do. I assume you have a little background or just staring up relational database programming. I would rather like to read the subject title "sets" in discrete mathematics because they are the same with database programming. let's say in SETS, there was set A and set B, in database there is table and table B.

Union- combination of 2 or more sets in SETS. in database is called syntax as Union, it combines 2 o more tables.
Intersection- finding the common between 2 or more sets. In database it is called syntax Join, it finds common databetwwen 2 or more sets (this should be assigned).

select * from tableA left join tableB on tableB.id=tableA.id
the type of join that is commonly used is left join. in SETS it called subset, in this manner mentioned in the example program above, it is a subset of tableB (meaning to say finding common data in tableB with tableA)

the on clause is used always as the connector to the logic to which shall the program triggers.

so do i need to make another table and yes I am extremly new this is my first project I created a primary key and been looking up buttons and $_POST variable checking (check which button is being pressed) i just need an ideal on how to put this together

Member Avatar for diafol

Whether you want to make another table depends upon your usage. Obvious tables to include could be 'bookings' and 'users', where you have something like:

bookings

booking_id (PK, autoincrement)
booking_made_datetime
room_id
start_booking (datetime)
end_booking (datetime)
user_id

users

user_id
username
pw
(etc)

But, as I mentioned, that depends on your usage (case use).

would it be better to get replace the buttons with checkboxes and how would that work or should i start from scratch

frankey bailey... we are open to lend you a helping hand, share us your logic and we will also share our comments and hints that you need to do.

we should start first from the database tables you want to have. just like the example what diafol has posted. diafol has just posted a brief preview on that.

What I am trying to do is have a web page that connects to a mysqldata base i want to have the user click a button and change that room status to closed am i good on the columuns or do i need to make new columns and a new table i like the bookings table he thought of my backgound is in cisco routers so i will be unfaimlar with terms and i have a php/mysql book to reference and if you can include links to explain things that would be geat

mr frankey bailey we don't know excatly what you want, whether it is checkbox or not. all we have to do is find a possible way to solve your questions.

share us your database tables and we will fix it.

here is my question. u mentioned, mr. bailey, that you want to use check box. well it dpends to your design.

consider this things between checkbox and dropdowns.

checkbox could be user firendly because checkbox can be used as userfriendly GUI that can be used to display that these checkboxes with this color legend can be reserved already or it is vacant. while drop downs are easier also when it comes to server computation speed.

could you lend us the design?

lets use checkboxes and erase the cost column and add
start_booking (datetime) end_booking (datetime) I included a text file of the data and columns

frankey bailey, I apologize for a late reply. I'm late to reply on you because I have corporate business conference with CISCO just a few minutes passed away.

Now... back to the topic.

I can lend a help to you with that.
Insert those details you have right now in your database. we all have to do is design everything first. that is called the front-end programming methodology. (100% pure design) back-end is (100% pure logic)

I think you can start constructing HTML for now. we'll do first (100% pure design)

on your initial post, that is back-end programming already.

draw a design of your image of your website and we will convert it to a code of html and css.

remember the foundation of the project relies on the quality but the attraction of the project relies on eye-popping design

honstely i just neeed a table that has the included colums and when a rooom is reserved the status is changed to close and the according table row changes from green to red and a text input field for the book dates

Member Avatar for diafol

You'll probably want to think this through a little bit.
The status field is an odd one - what's the purpose of red/green? Is this for current time (booked or not). Can rooms have multiple bookings (on different non-overlapping datetimes)? If so, 'status' loses meaning. Well, it loses meaning anyway if you book for a set amount of time.

IMO, the colour should be set by whether the room has been booked for that particular period

yes the status color is for current status, No the the rooms cant have multiple bookings on different non-overlapping datetimes Click Here i read this it looks like what im doing except i want to edit 3 field instead of two can i follow the same logic

i am also having problem with buttons. Can you please give an example of html form's 2 button with elseif statement. which shows how to control two buttons through php. i mean when i click "insert" button so it inserts data to DB and when i click "delete" button in html, so it delete the selected record form DB.

Regrads.

wow. I got big hole of a problem in your project mr. frankie bailey. You mentioned to have checkboxes and buttons earlier this post.

what it hinderes me right now are:

1.) what is the process of booking here? do customers have to contact the staff and change the status of their desired room(s)?

2.) how do the customers pay the hotel rooms?

3.) how do the staff check that the customer is not a fraud or not a prank poster?

You should perhaps have this done by professionals. I am talking about people who have done similar job. Unless you have time to do it on your own.

Mr akkbkht, please don't hijack other peoples threads, you are unlikely to get a reply, start your own thread if you cannot find your answer by searching.

Im trying everything to be done by web the status change booking dates i forgot to put in a submit button at the bottom and checkboxes in the pictureand staff only has to check it i shout be able to fine out how to auto delete so it doesnt have to be done manully iv done a shopping cart before so the payment part shouldn't be hard and for the fraud part honestly I don't know

in your part of the questioned "auto delete", what are the rules for having auto delete?
can you post your new interface along with the submit button and check boxes as well? so we can innovate the design.

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.