Jump to content

updating table....


aian04

Recommended Posts

this is my code for retrieving all d data in the database

<?php
$host="localhost"; 
$username="root"; 
$password="tmc";
$db_name="tgp"; 
$tbl_name="reservation"; 
$id=$_COOKIE['ID'];

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name join packages on reservation.pac_id = packages.pac_id where Cid ='$id'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

?>
<html>
<head><link href="interface design/css.css" rel="stylesheet" type="text/css">
<script language="javascript">

function hover(FRM,BTN)
{
   window.document.forms[FRM].elements[bTN].style.color = "#6666AA";
   window.document.forms[FRM].elements[bTN].style.backgroundColor = "#EEEEF4";
   window.document.forms[FRM].elements[bTN].style.borderColor = "#9999DD";
}

function out(FRM,BTN)
{
   window.document.forms[FRM].elements[bTN].style.color = "#888888";
   window.document.forms[FRM].elements[bTN].style.backgroundColor = "#EEEEEE";
   window.document.forms[FRM].elements[bTN].style.borderColor = "#BBBBBB";
}

</script>
</head>
<body align="center">
<form action="http://localhost:6080/aian/update.php" method="post" name="form">
<table class="ret"  width="400" border="0" cellpadding="10" cellspacing="3" background="interface design/logo/member.jpg">
<tr>
<td colspan="6" align="center"><strong>Reservatio History</strong> </td>
</tr>
<tr>
<td align="center">Reservation ID</td>
<td align="center"><strong>Check in Date</strong></td>
<td align="center"><strong>No. of nights</strong></td>
<td align="center"><strong>Room Number</strong></td>
<td align="center"><strong>Specials And Packages</strong></td>
<td align="center"><strong>Customer ID</strong></td>
</tr>
<?php


while($rows=mysql_fetch_assoc($result)){

?>
<tr>
<td><? echo $rows['Res_id'];?>			</td>
<td><input type="submit" class="groovybutton2" name="checkin" value="<? echo $rows['check_in'];?>"></td>
<td><input type="submit" class="groovybutton2" name="nyt" value="<? echo $rows['night_per_stay'];?>"></td>
<td><input type="submit" class="groovybutton2" name="r_no" value="<? echo $rows['R_no'];?>"></td>
<td><input type="submit" class="groovybutton2" name="pac" value="<? echo $rows['pac_name'];?>"></td>
<td><? echo $rows['Cid']; ?></td>
</tr>
<?php
}
@mysql_free_result($pac);
?>
</table>
</body>
</html>
<?

@mysql_close();?>

 

and this is my the code when u click a specific datafield.. i havent finish this... stil workin on it...

<html>
<head><link href="interface design/css.css" rel="stylesheet" type="text/css">
</head>
<body class="ret">
<?php
@mysql_connect ("localhost", "root", "tmc") or die (mysql_error());
@mysql_select_db("tgp")or die(mysql_error());

$checkin=$_POST['checkin'];
$nyt=$_POST['nyt'];
$r=$_POST['r_no'];
$pac=$_POST['pac'];

if(isset($checkin)){

	?><form action="update1.php" method="post"><table align="center" class="ret" background="interface design/logo/member.jpg">
	<tr><td>Change Date </td><td><input type='text' name='date'></td><td></td><td>yyyy-mm-dd</td></tr>
	<tr></tr><tr><td><input class="groovybutton2" type='submit' name='date1' value='update'></td></tr>
	</table></form>
<?}

if(isset($nyt)){?>

<form action="update1.php" method="post"><table align="center" class="ret" background="interface design/logo/member.jpg">
	<tr><td>No. of Nights per stay </td><td><input type='text' name='nite'></td></tr>
	<tr></tr><tr><td><input class="groovybutton2" type='submit' name='nite1' value='update'></td></tr>
	</table></form>

<?}

if(isset($r)){
echo $r;
}

if(isset($pac)){
echo $pac;
}	

?>
</body>
</html>

and this is my code to process the form above

<html>
<head><link href="interface design/css.css" rel="stylesheet" type="text/css">
</head>
<body class="ret">
<?php
@mysql_connect ("localhost", "root", "tmc") or die (mysql_error());
@mysql_select_db("tgp")or die(mysql_error());
$date=$_POST['date'];
$id=$_COOKIE['ID'];
$nit=$_POST['nite'];
$dateq=mysql_query("UPDATE reservation SET check_in='$date' where Cid='$id'");
$nite=mysql_query("UPDATE reservation SET night_per_stay='$nit' where Cid='$id'");

if(!isset($_POST['date1']))	{?>

	<form action="update1.php" method="post"><table align="center" class="ret" background="interface design/logo/member.jpg">
	<tr><td>Change Date </td><td><input type='text' name='date'></td><td></td><td>yyyy-mm-dd</td></tr>";
	<tr></tr><tr><td><input type='submit' name='date' value='update'></td></tr>";
	</table></form>	
	<?}
	else {
	if($dateq){?>
			<script>window.location ="history.php"</script>

	<?} #when updated succesfully
	else
		{?><div style=" width: 450px; background:black;filter:alpha(opacity=75); -moz-opacity:.75;opacity:.75; margin-left: 0; margin-right:0;"><?

	 	echo 'Updating information is failed';

		}?></div><?
	}

if(!isset($_POST['nite1'])){?>

<form action="update1.php" method="post"><table align="center" class="ret" background="interface design/logo/member.jpg">
	<tr><td>No. of Nights per stay </td><td><input type='text' name='nite'></td></tr>
	<tr></tr><tr><td><input class="groovybutton2" type='submit' name='nite1' value='update'></td></tr>
	</table></form>
	<?}
else {
	if($nite){?>
	<script>window.location ="history.php"</script>
	<?} #when updated succesfully
	else
	?><div style=" width: 450px; background:black;filter:alpha(opacity=75); -moz-opacity:.75;opacity:.75; margin-left: 0; margin-right:0;"><?

	 echo 'Updating information is failed';

		?></div><?
}

now my problem is.. when i update the check in date... it will affect the other field like no of nights...

how to avoid that situation..

experts pls help me...

 

Link to comment
Share on other sites

bro i mean...

im doing table update which will update only one selected field...

not 2 or all the field...

u get wat i meant...

for e.g in the table i have checkin date, nyts per stay, room no..

so if i want to change the checkin date.. i just click it then my update1.php will process the updating...

 

Link to comment
Share on other sites

yeah...

im having a problem if i update this field it will update all data in the column..

and it will affect the another column in the row selected....

is this correct
while($rows=mysql_fetch_assoc($result)){

?>
<tr>
<td><? echo $rows['Res_id'];?>			</td>
<td><input type="submit" class="groovybutton2" name="checkin" value="<? echo $rows['check_in'];?>"></td>
<td><input type="submit" class="groovybutton2" name="nyt" value="<? echo $rows['night_per_stay'];?>"></td>
<td><input type="submit" class="groovybutton2" name="r_no" value="<? echo $rows['R_no'];?>"></td>
<td><input type="submit" class="groovybutton2" name="pac" value="<? echo $rows['pac_name'];?>"></td>
<td><? echo $rows['Cid']; ?></td>
</tr>
<?php
}

i put a form button so it will be clickable for updating...

now once again.. i click the field that i want to update... then i update it... it will affect all the field in a column... and it wil affect also the field in the selected row....

how to avoid that...

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.