Jump to content

Recommended Posts

<?php
@mysql_connect('localhost', 'root', 'tmc') or die(mysql_error());
@mysql_select_db('tgp') or die(mysql_error());
$datein=$_POST['check-in-date'];
$dayin=$_POST['check-in-day'];
$r_type=$_POST['r_category'];
$pac=$_POST['special'];
$checkin = "$datein-$dayin" ;
$nyt=$_POST['nyts'];
$id=$_COOKIE['ID']; 
$room= mysql_query("SELECT r_no FROM room WHERE RC_id ='$r_type'order by rand() limit 1"); 

while ($row = mysql_fetch_row($room)){

break;
}
$r= mysql_free_result($room);
echo "$r";
   
if(!mysql_query ("INSERT INTO reservation VALUES ('0','$checkin', '$nyt','$r','$pac','$id')"))
{	print '<div style=" width: 450px; background:black;filter:alpha(opacity=75); -moz-opacity:.75;opacity:.75; margin-left: 0; margin-right:0;">';
print '<b>reservation failed</b>';
print '</div>';
}


else {
 print '<div style=" width: 450px; background:black;filter:alpha(opacity=75); -moz-opacity:.75;opacity:.75; margin-left: 0; margin-right:0;">';
 print 'Your Information has been successfully added to the database.';
print '<br><br>';
$result=mysql_insert_id();
print "Your Reservation No. is <b>$result</b>";
print '</div>';
}




mysql_close();
?>

 

if i use this code its always give me number 1.. which is wrong.. and its not following my $room query...

 

my r_no column is auto_incremented.. and it doesnt matter if it is or it isnt...

coz i only want to get the data from r_no column... and put that obtained data to reservation table...

this is my room table

create table room
(
RC_id varchar(15) not null,
floorlvl int not null,
R_no int not null auto_increment,
primary key (R_no),
Foreign Key (RC_id) references r_category(RC_id)
);

and this is my reservation table

create table reservation
(
Res_id int not null auto_increment,
check_in date not null,
night_per_stay int not null,
R_no int not null,
pac_id varchar(15) not null,
Cid varchar(15) not null,
primary key (Res_id),
Foreign Key (Cid) references member(Cid),
Foreign Key (pac_id) references packages(pac_id),
Foreign Key (R_no) references room(R_no)

);

 

what i want to do is to get the r_no in the table...

 

 

 

i just noticed you ignored my last post..

 

go back and try that

 

it seam your just trying anything to make it work without the understanding

 

<html>
<head>
<link href="interface design/css.css" rel="stylesheet" type="text/css">
</head>
<body class="bg">
<?php

         

mysql_connect('localhost', 'root', 'tmc') or die(mysql_error());


mysql_select_db('tgp') or die(mysql_error());

$datein=$_POST['check-in-date'];
$dayin=$_POST['check-in-day'];
$r_type=$_POST['r_category'];
$pac=$_POST['special'];
$checkin = "$datein-$dayin" ;
$nyt=$_POST['nyts'];
$room= mysql_query("SELECT r_no FROM room WHERE r_no ='$r_type'order by rand() limit 1");         
$id=$_COOKIE['ID']; 



while ($row = mysql_fetch_row($room)){
	echo $row="['r_no']";
break;
}
$r=mysql_free_result($room);
   
if(!mysql_query ("INSERT INTO reservation VALUES ('0','$checkin', '$nyt','$r','$pac','$id')")or die(mysql_error()))
{	print '<div style=" width: 450px; background:black;filter:alpha(opacity=75); -moz-opacity:.75;opacity:.75; margin-left: 0; margin-right:0;">';
print '<b>reservation failed</b>';
print '</div>';
}


else {
 print '<div style=" width: 450px; background:black;filter:alpha(opacity=75); -moz-opacity:.75;opacity:.75; margin-left: 0; margin-right:0;">';
 print 'Your Information has been successfully added to the database.';
print '<br><br>';
$result=mysql_insert_id();
print "Your Reservation No. is <b>$result</b>";
print '</div>';

}




mysql_close();
?>
</body>
</html>

 

ok now i try dis code...

i try to echo d $r then it remove the resource id thin... it give me pure integer...

but its still give me failed reservation...

wat do u think d problem...

echo $row="['r_no']";

should be

echo $row['r_no'];

ok now i change it... now i can get it... and its randomize....

$room= mysql_query("SELECT r_no FROM room WHERE rc_id ='$r_type'order by rand() limit 1"); 
while ($row = mysql_fetch_assoc($room)){
	echo $row['r_no'];
break;
}
$r= mysql_free_result($room);

how to insert it in the reservation table

if(!mysql_query ("INSERT INTO reservation VALUES ('0','$checkin', '$nyt','$r','$pac','$id')"))

do i need to change the $r to $row...

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.