I dont know how to update table

Hello, I want to create update button for each table row. I displayed data from table succesufuly, but I dont know hot to update status of reservation session.I will post my code here.
I am new in php so sorry for stupid question…

<?php
//displayResStatus.php
require_once "db.php";
class displayResStatus extends ConnToDB {
	public function displayStatusNone() {
		$sql = "SELECT * FROM reservation WHERE SESSION_STATUS='NONE'";
		$result = $this->Connection()->query($sql);

		echo '<table border="1" cellpadding="5"> 
      		<tr>
	          <th>Name</th> 
	          <th>Lastname</th> 
	          <th>E-mail</th> 
	          <th>Phone number</th> 
	          <th>Gender</th> 
	          <th>Session</th>
	          <th>Session status</th>
	          <th>Change session status</th>   
     		</tr>';

		if ($result) {
			while ($row = mysqli_fetch_assoc($result)) {
				$name = $row["NAME"];
				$lastname = $row["LASTNAME"];
				$email = $row["EMAIL"];
				$phone = $row["PHONE"];
				$gender = $row["GENDER"];
				$session = $row["SESSION"];
				$sessionStatus = $row["SESSION_STATUS"];
				

				echo '<tr>
						<td>'.$name.'</td>
						<td>'.$lastname.'</td>
						<td>'.$email.'</td>
						<td>'.$phone.'</td>
						<td>'.$gender.'</td>
						<td>'.$session.'</td>
						<td>'.$sessionStatus.'</td>
						<td>'?>
						<form method="#" action="#">
							<select name="selectStatus">
								<option name="status" value="Confirmed session">Confirmed session</option>
								<option name="status" value="Unconfirmed session">Unconfirmed session</option>
							</select>
							<input type="submit" name="submit" value="Update status"/>
						</form>															
						




						      <?php '</td>
					  <tr>';
			}
		}
		echo '</table>';

	}
}

?>

If you edit the first post in the thread and either add bbcode [code] [/code] tags or use the preformatted text menu button </>, your code will get formatted correctly.

Updating is easy, but, we can not read your code. Here is a tutorial on how to do this: Sql-Update

UPDATE Customers
SET ContactName = ‘Alfred Schmidt’, City= ‘Frankfurt’
WHERE CustomerID = 1;

(You can read this query example!)

thanks phdr! How my code can be see normaly :slight_smile:

You show a simple display of data from a database query.
It creates a simple table showing the data.
All is good in general with that. (without testing it live.)

Now, to do an update, you would need to change the table cells to be input fields.
Then, you would need to add tags to turn the table into a form.
Next, add a submit button for “Update!”.
And, code to read the form to capture the changes.
Finally, you would need to read the changes, filter them for hackers and save them back to the database.

Is that what you are asking help for? Or, do you mean just to add the confirmation at the end?

I want to add confirmation at the end of each reservation. Using select tag like I show in my code. I want to select if reservation is confirm or not and then save update in base.

slika2 .
I want to update session status by selecting one of the options in Change session status column.

Unfortunately, the programmers who wrote this forum software weren’t very good. You must put the bbcode tags on their own lines with nothing else before/after them.

1 Like

This line:
< select name=“selectStatus” >
names your drop-down, but, it is only for one and really only for the last one. Why I bring this up?
Well, your code as-is has the same select name without an index. Therefore if you change two of them,
the code will only take one of them. You would either need to create unique names for each select clause
or add indexing to them so you can tell the ones that have been changed. ( Unless you are okay with
updating just one field at a time. )

Do you have an index field in the database? I mean an “id” field? If so, you can just use that for the
index and it will make the update query easier. Or, if you are sure the “Session” field is UNIQUE, you
can use that for the select-index. Further explanation: You have several drop-down’s (select’s) and you
have matching update buttons. You need to be able to know which button is pressed and what the
corresponding select is set to. If have unique session names and are 100% sure they do not dupe, you
can name the select something like “status_session1”, “status_session2”, etc, but you show two of
them set as session3… If you have an id and it is set to auto-increment and unique, then you can use
that instead. Then, you can dump all of the update buttons and just have one at the bottom. And, you
can update many of them all at once. You can pull out the session or id numbers and update them all
at once.

Hope this gets you thinking… Ask your next question…

Sponsor our Newsletter | Privacy Policy | Terms of Service