php and mysqli help

Ok i have been work on a php and mysqli project.

this si what the page looks like know
here is my code

<html><head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
</head>
<BODY>


<?php

// DATABASE CONNECTION AND SELECTION VARIABLES - GET THESE FROM YOUR HOSTING COMPANY
$DB_HOST = "localhost"; // PROBABLY THIS IS OK
$DB_USER = "root";
$DB_PASS = "admin";
$DB_NAME = "patient_regester";



$conn = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);

// check connection
if ($conn->connect_error) {
  trigger_error('Database connection failed: '  . $conn->connect_error, E_USER_ERROR);
}

// A QUICK QUERY ON A FAKE USER TABLE
$query = "SELECT * FROM `kfhh` ORDER BY 'Room_id' ";
$result = $conn->query($query) or die($conn->error.__LINE__);


echo "<form action='get.php' method='post'>";
echo "<br><table width='50%' border='1'>";

	echo "<tr align='center'>";
		echo "<td>Room Number</td>";
   		echo "<td>Occupancy Status</td>";
    	echo "<td>Last Name</td>";
    	echo "<td>First Name</td>";
    	echo "<td>LOC</td>";
    	echo "<td>Visitors</td>";
  	echo "</tr>";




	while($row = $result->fetch_assoc()) 
			{
		$lname= stripslashes($row['Last_name']);	
		$fname= stripslashes($row['First_Name']);
		$LOC= stripslashes($row['LOC']);
		$Visitors= stripslashes($row['Visitors']);
		$Occupancy= stripslashes($row['Occupancy']);
		$Room_id= stripslashes($row['Room_id']);
		
	echo "<tr>";
    	echo "<td id='RM_".$Room_id."'>" .$Room_id ."</td>";
		
		echo "<td >" .$Occupancy ."</td>";
		echo "<input name='ln_".$Room_id."_".$Occupancy."' type='hidden' value='" .$Occupancy. "'  />";
		
		if($lname == NULL) 
			{
				echo "<td> No Name </td>";
				
				
			} else
			
			{
				echo "<td >" .$lname ."</td>";
				echo "<input name='ln_".$Room_id."_".$lname."' type='hidden' value='" .$lname. "'  />";
			}
					
		if($fname == NULL) 
			{
				echo "<td> No Name </td>";
				
			} else
			
			{
				echo "<td >" .$fname ."</td>";
				echo "<input name='ln_".$Room_id."_".$fname."' type='hidden' value='" .$fname. "'  />";
			}
			
		if($LOC == NULL) 
			{
				echo "<td> No LOS </td>";
				
			} else
			
			{
				echo "<td >" .$LOC ."</td>";
				echo "<input name='ln_".$Room_id."_".$LOC."' type='hidden' value='" .$LOC. "'  />";
			}
		
		
		if($Visitors == NULL) 
			{
				echo "<td> No Visit </td>";
				
			} else
			
			{
				echo "<td >" .$Visitors ."</td>";
				echo "<input name='ln_".$Room_id."_".$Visitors."' type='hidden' value='" .$Visitors. "'  />";
			}
			echo "<td > <input type='button' id='bt_".$Room_id."' type='submit' value='Edit'></td>";
	
	
		}
			
?>
			

</tr>

</form>
</table>
<script type="text/javascript">


$("input").click(function() {
  alert(this.id);
  
});

</script>

<?php 
mysqli_close($conn);
?>
</BODY>
</html>

Open in new window



at this time all it does is list all info from the db. as you can see i have a edit button at the end of each row. Each button has there own
id='bt_".$Room_id."'

Open in new window

then i have a jquery at the bottom that alert me of witch id the user is pressing.

was going to use the button id as a way to tell the php witch db record to update.

what i would like is when the user press the edit button. It will open a overlay box with the info from that row is input box where the user can make change and click save. The save will update the db with the new info and the main php will refresh.

I have some hidden input box's in the code i was thinking of making then not hidden and then make the edit button change to a save button. So everything stays on one page.


The
action='get.php' method='post'

Open in new window

does nothing.

How can i make this a reality ?
armasmikeAsked:
Who is Participating?
 
Ray PaseurConnect With a Mentor Commented:
You might want to start by deconstructing the problem into component parts that are small enough to write and test individually.  Then as each part is proven to work correctly you can assemble the application from the pre-tested pieces.  I can show you some parts of the design patterns.

How to use MySQLi, mapped against the familiar but deprecated MySQL extension.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html

The essential moving parts of a basic jQuery AJAX call to a server-side script.
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/A_10712-The-Hello-World-Exercise-with-jQuery-and-PHP.html

An article showing the standard design pattern for a table maintenance script.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12335-PHP-and-MySQLi-Table-Maintenance.html
0
 
armasmikeAuthor Commented:
ok the PHP and MySQLi Table Maintenance is a great read will work thought that.
0
 
Ray PaseurCommented:
Post back here with any question.  Especially if there is anything unclear in the article.

Cheers, ~Ray
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
Chris StanyonCommented:
Once you've got your head around the database side of things, the easiest option is to store the primary key from the database as a data attribute on the button. It will make the jQuery side of things much easier. Assuming your primary is $Room_id, then you would create each button like this:

<button class="edit" data-roomID="<?php echo $Room_id ?>">Edit</button>

Open in new window

The jQuery to get it would then simply be

$('.edit').click(function() {
    alert("Room ID is " + $(this).data('roomID') );
});

Open in new window

0
 
armasmikeAuthor Commented:
Why do you write it this way

// CREATING A QUERY TO LIST THE TEST DATA
$sql
=
"
SELECT
  id
, fname
, lname
FROM
  EE_maintenance
ORDER BY
  id
"
;

Open in new window


I fell it's harder to read why not this

$sql =" SELECT id, fname, lname FROM EE_maintenance ORDER BY id";

Open in new window

0
 
Ray PaseurCommented:
I have a large code base to work with and I often find that I need to make changes in the queries.  When I write queries and array notation like that, it's easier for me to make the changes without introducing syntax and parse errors.  I also have automation that does things like look for a line starting with = followed by a line starting with " so it's easy for me to find my queries because I follow that coding standard.

The statements are functionally equivalent -- PHP and SQL do not care about your white space.  I just try to do what I have found makes my code easier to read and debug.  And for me this is a tried-and-true technique.  The advantage really comes out when you get into long and complicated queries.  On a short query string like this, it probably doesn't matter.
0
 
Chris StanyonCommented:
@armasmike - it's personal preference how you write it - sometimes it's easier on one line, sometimes it's easier over several lines.

A short query like that is probably best over 1 line

A longer query might be easier to read (and debug) written over several:

SELECT col1, col2, col3, col4
FROM yourTable
WHERE col1 = 'some value'
ORDER BY 'col3' DESC


Write it however you prefer :)
0
 
armasmikeAuthor Commented:
always helpful
0
 
Ray PaseurCommented:
Thanks for using EE, and best of luck with your project, ~Ray
0
 
armasmikeAuthor Commented:
can you explain this more for me the

$id LIMIT 1 on line 34 of the RAY_EE_table_maintenance_delete.php

I don't under stand how this works ?
0
 
armasmikeAuthor Commented:
ok i give up How do you add space to something like this

$out .= '<optgroup label=You can pick one of these>';

Open in new window


It only see the You part i don't want to put _ or . as spaces
0
 
Chris StanyonCommented:
Not sure what this has to do with the original question, but the answer is 'you wrap it in quotes':

$out .= '<optgroup label="You can pick one of these">';

Open in new window

0
 
armasmikeAuthor Commented:
damn it how did i miss that thank you
0
 
Chris StanyonCommented:
:)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.