PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
hrubos
Forum Contributor
Posts: 172 Joined: Sat Oct 07, 2006 3:44 pm
Post
by hrubos » Wed Nov 29, 2006 2:44 pm
Who can show me why I can't insert number of room into database when user choose room???I only can insert id_reversation well into database.
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="content-type" content="text/html; charset=windows-1250">
<meta name="generator" content="PSPad editor, http://www.pspad.com">
<html>
<head><title>Rezevace</title></head>
<body>
<form method = "POST" action = "data.php">
<?php
require_once ("D:\htdocs\BP\db_connectFun.php");
db_connect();
$query="SELECT DISTINCT p.id_numberRoom,p.number_room,p.building,p.floor,p.state_room,
p.id_typeRoom, t.number_beg,t.price
FROM pokoj p,type_room t
WHERE p.id_typeRoom = t.id_typeRoom";
$query_numRoom = "SELECT DISTINCT p.number_room FROM pokoj p";
$result_numRoom = mysql_query($query_numRoom);
$result=mysql_query($query)or die(mysql_error());
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num ) {
$id_numberRoom=mysql_result($result,$i,"id_numberRoom");
$number_room=mysql_result($result,$i,"number_room");
$building=mysql_result($result,$i,"building");
$floor=mysql_result($result,$i,"floor");
$number_beg=mysql_result($result,$i,"number_beg");
$price=mysql_result($result,$i,"price");
?>
<tr>
<?php
$n=0;
echo "<td>$id_numberRoom</td>" ;
echo "<td>$number_room</td>" ;
echo "<td>$floor</td>";
echo "<td>$building</td>";
echo "<td>$number_beg</td>";
echo "<td>$price</td>";
if($number_beg==2) {
for($s=1;$s <=2;$s++ )
echo "<td> <input type= 'radio' value = '$n' name= 'id_reservation'></td>";
}
if($number_beg == 3){
for($s=1;$s<=3;$s++ )
echo "<td> <input type= 'radio' value = '$n' name= 'id_reservation'></td>";
}
echo "<td> <input type= 'radio' value = '$n' name= 'id_reservation'></td>";
//echo "<td> <input type= 'radio' value = '$number_room' name= 'number'></td>";
$i++ ;
db_connect();
if($number_room==$i){
$query_room = "insert into reser_1 " . "(number_room) values"
. "('$number_room')";
mysql_query($query_room) or die(mysql_error());
}
}
?>
<tr>
<td>
<input type="submit" value="Submit" name="submit">
</td>
</tr>
</tr>
</form>
</body>
</html>
//data.php
<?php
$id_reservation = $_POST['id_reservation'];
//$number = $_POST['number'];
if(!get_magic_quotes_gpc())
{
$id_reservation = addslashes($id_reservation);
}
@ $db = mysql_connect("localhost", "root","ha1985") or die("Error");
mysql_select_db("kolej",$db) or die("Can't choose database");
$query = "insert into reser_1 " . "(id_reservation) values"
. "('$id_reservation')";
mysql_query($query) or die(mysql_error());
?>
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Wed Nov 29, 2006 2:49 pm
could you please explain your question a little more. are you receiving an error? Do you just not know how to format your sql query to perform an insert of more than one column?
Code: Select all
insert into `mytable` (`col1`,`col2`) values ('some val','some other val')
or
Code: Select all
insert into `mytable` set `col1` = 'some val', `col2` = 'some other val'
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Nov 29, 2006 2:50 pm
You only have id_reservation in your insert query. You need more fields specified to have more data.
hrubos
Forum Contributor
Posts: 172 Joined: Sat Oct 07, 2006 3:44 pm
Post
by hrubos » Wed Nov 29, 2006 3:10 pm
I haven't receive any error but when inserting to database, I haven't received number of room exactly.
That code : select --> output how many room and number of room in a table. Then user can chooe room by cliking radiobutton. ---> insert : id_resrevation into database(exactly) but number of room can't be inserted into databse follow id_resrevation(insert into table in which there are id_resrevaton and number_room)
hrubos
Forum Contributor
Posts: 172 Joined: Sat Oct 07, 2006 3:44 pm
Post
by hrubos » Wed Nov 29, 2006 3:12 pm
Burrito wrote: could you please explain your question a little more. are you receiving an error? Do you just not know how to format your sql query to perform an insert of more than one column?
Code: Select all
insert into `mytable` (`col1`,`col2`) values ('some val','some other val')
or
Code: Select all
insert into `mytable` set `col1` = 'some val', `col2` = 'some other val'
follow you, but I don't know how change this type :
Code: Select all
echo "<td> <input type= 'radio' value = '$n' name = 'id_reservation'></td>";
because if i useinsert into `mytable` set `col1` = 'some val', `col2` = 'some other val'
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Wed Nov 29, 2006 4:03 pm
I still don't understand your question. are you having a hard time getting the value of the variable you are choosing to insert?
hrubos
Forum Contributor
Posts: 172 Joined: Sat Oct 07, 2006 3:44 pm
Post
by hrubos » Wed Nov 29, 2006 4:18 pm
Burrito wrote: I still don't understand your question. are you having a hard time getting the value of the variable you are choosing to insert?
U can think that you want to reserver a room and u choose a number of room by cliking in radiobutton
Code: Select all
echo "<td> <input type= 'radio' value = '$n' name = 'id_reservation'></td>";
i++;
if($number_room=$i){
$query_room = "insert into reser_1 " . "(number_room) values"
. "('$number_room')";
mysql_query($query_room) or die(mysql_error());
}
Now what does system do???
Ofcourse after cliking radiobutton, number of room will be inserted into database --- > this is my problem. I couldn't insert number of room into database exactly.(number of room have been outputted by query SQL)
Plz help me, i have tried some ways but still not run
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Wed Nov 29, 2006 4:43 pm
you're not going to be able to do that on the same page. You have to select the room number then submit the page and post its value to the subsequent page where you'll perform your insert.
hrubos
Forum Contributor
Posts: 172 Joined: Sat Oct 07, 2006 3:44 pm
Post
by hrubos » Wed Nov 29, 2006 4:47 pm
I have changed a little but i have received error "Notice: Undefined index: number in D:\htdocs\BP\Room\outputRoom.php on line 23"
Code: Select all
<?php
require_once ("D:\htdocs\BP\db_connectFun.php");
$number = $_POST['number'];
db_connect();
$query="SELECT DISTINCT p.id_numberRoom,p.number_room,p.building,p.floor,p.state_room,
p.id_typeRoom, t.number_beg,t.price
FROM pokoj p,type_room t
WHERE p.id_typeRoom = t.id_typeRoom";
$query_numRoom = "SELECT DISTINCT p.number_room FROM pokoj p";
$result_numRoom = mysql_query($query_numRoom);
$result=mysql_query($query)or die(mysql_error());
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num ) {
$id_numberRoom=mysql_result($result,$i,"id_numberRoom");
$number_room=mysql_result($result,$i,"number_room");
$building=mysql_result($result,$i,"building");
$floor=mysql_result($result,$i,"floor");
$number_beg=mysql_result($result,$i,"number_beg");
$price=mysql_result($result,$i,"price");
?>
<tr>
<?php
$n=0;
echo "<td>$id_numberRoom</td>" ;
echo "<td>$number_room</td>" ;
echo "<td>$floor</td>";
echo "<td>$building</td>";
echo "<td>$number_beg</td>";
echo "<td>$price</td>";
/**
if($number_beg==2) {
for($s=1;$s <=2;$s++ )
echo "<td> <input type= 'radio' value = '$n' name= 'id_reservation'></td>";
}
if($number_beg == 3){
for($s=1;$s<=3;$s++ )
echo "<td> <input type= 'radio' value = '$n' name= 'id_reservation'></td>";
}
*/
echo "<td> <input type= 'radio' value = '$number_room' name = 'number'></td>";
$i++;
//echo "<td> <input type= 'radio' value = '$number_room' name= 'number'></td>";
//$i++ ;
db_connect();
if($number_room==$number)
{$query_room = "insert into reser_1 " . "(number_room) values"
. "('$number_room')";
mysql_query($query_room) or die(mysql_error());
}
<tr>
<td>
<input type="submit" value="Submit" name="submit">
</td>
</tr>
</tr>
</form>
</body>
</html>
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Wed Nov 29, 2006 5:32 pm
are you posting to that page?
if not, $number will never get set.