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 » Thu Jan 04, 2007 2:50 pm
Hi all, would you mind showing me how do I wrong because I only can update one row, more I couldn't .
page1.php
Code: Select all
...........
echo "<td width = '30'><input type='hidden' name='new_id_numberRoom[]' value='$id_numberRoom'></td>" ;
echo "<td width = '90'><input type='text' name='new_number_room' size='10' align='right' value= '$number_room' size='8' style='font-family:Arial'></td>" ;
echo "<td width = '90'><input type='text' name='new_state_room' size='10' align='right' value= '$state_room' size='8' style='font-family:Arial'></div></td>";
page2.php
Code: Select all
$valId = implode(",",$_POST['new_id_numberRoom']);
$new_number_room = $_POST['new_number_room'];
$new_state_room=$_POST['new_state_room'];
if(!get_magic_quotes_gpc())
{
$new_number_room = addslashes($new_number_room);
}
$query = "UPDATE room p,type_room t SET p.number_room = '$new_number_room',
p.state_room = '$new_state_room'
WHERE p.id_numberRoom IN ($valId)";
mysql_query($query) or die(mysql_error());
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jan 04, 2007 3:00 pm
new_number_room and new_state_room are unique in the form?
hrubos
Forum Contributor
Posts: 172 Joined: Sat Oct 07, 2006 3:44 pm
Post
by hrubos » Thu Jan 04, 2007 3:04 pm
feyd wrote: new_number_room and new_state_room are unique in the form?
Really I don't understand your question, so plz, would you mind explaining me again???
Thank you
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jan 04, 2007 3:14 pm
Are the echoes posted above in a loop?
In other words: in the resulting HTML, do the fields corresponding to new_number_room and new_state_room appear more than once?
hrubos
Forum Contributor
Posts: 172 Joined: Sat Oct 07, 2006 3:44 pm
Post
by hrubos » Thu Jan 04, 2007 3:25 pm
yeah, I use checkbox to chose and so reult can be return more 2 rows.
If query only 1 result, so Ok
But more than 1, so it doesn't run exactly
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jan 04, 2007 3:34 pm
Because you have multiples of each, the naming needs to be adjusted.
For example, new_id_numberRoom[] could be removed; new_number_room could become foo[$id_numberRoom][numberRoom]; and new_state_room could become foo[$id_numberRoom][stateRoom].
You would then loop over $_POST['foo'] where the keys will be the original room number and the value will be an array of the numberRoom and stateRoom values. Each iteration over foo will require a new UPDATE query.
hrubos
Forum Contributor
Posts: 172 Joined: Sat Oct 07, 2006 3:44 pm
Post
by hrubos » Thu Jan 04, 2007 3:51 pm
So i'm sorry if I don't understand you suggest exatly. I have tried follow your advice but I have received that after updating, it would be edited , is described here
(I chose 2 checkbox)-->2/2b| free
2/3b|free
---> 2/3|free
2/4|free ---> submit -->(last step) 2/3 |free
Array|Array
I did that :
Code: Select all
echo "<td width = '30'><input type='hidden' name='new_id_numberRoom' value='$id_numberRoom'></td>" ;
echo "<td width = '90'><input type='text' name='foo[$id_numberRoom][numberRoom]' size='10' align='right' value= '$number_room' size='8' style='font-family:Arial'></td>" ;
echo "<td width = '90'><input type='text' name='foo1[$id_numberRoom][stateRoom]' size='10' align='right' value= '$state_room' size='8' style='font-family:Arial'></div></td>";
page2.php
Code: Select all
$new_id_numberRoom = $_POST['new_id_numberRoom'];
$new_number_room = $_POST['foo'];
$new_state_room=$_POST['foo1'];
if(!get_magic_quotes_gpc())
{
$new_number_room = addslashes($new_number_room);
}
$query = "UPDATE room p SET p.number_room = '$new_number_room',
p.state_room = '$new_state_room'
WHERE p.id_numberRoom = '$new_id_numberRoom'";
mysql_query($query) or die(mysql_error());
hrubos
Forum Contributor
Posts: 172 Joined: Sat Oct 07, 2006 3:44 pm
Post
by hrubos » Fri Jan 05, 2007 5:51 am
Who would mind showing me how to do for updating row of result,which are more 2 rows???
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jan 05, 2007 9:35 am
My post specifically stated to remove the hidden field, and name both input fields as "foo"
There's a reason for it.
Mordred
DevNet Resident
Posts: 1579 Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria
Post
by Mordred » Fri Jan 05, 2007 9:39 am
Also $_POST['new_id_numberRoom'] is vulnerable to a SQL injection.
Also don't use addslashes but mysql_real_escape_string
hrubos
Forum Contributor
Posts: 172 Joined: Sat Oct 07, 2006 3:44 pm
Post
by hrubos » Fri Jan 05, 2007 4:48 pm
feyd wrote: My post specifically stated to remove the hidden field, and name both input fields as "foo"
There's a reason for it.
hej, your advance looks right and I think it is right but when I tried agian, it doesn't run any thing
I did :
Code: Select all
echo "<td width = '30'><input type='text' name='foo' value='$id_numberRoom'></td>" ;
echo "<td width = '90'><input type='text' name='foo[$id_numberRoom][numberRoom]' size='10' align='right' value= '$number_room' size='8' style='font-family:Arial'></td>" ;
echo "<td width = '90'><input type='text' name='foo[$id_numberRoom][stateRoom]' size='10' align='right' value= '$state_room' size='8' style='font-family:Arial'></div></td>";
Code: Select all
$new_id_numberRoom = $_POST['foo'];
$new_number_room = $_POST['foo[$id_numberRoom][numberRoom]'];
$new_state_room=$_POST['foo[$id_numberRoom][stateRoom]'];
$query = "UPDATE room p SET p.number_room = '$new_number_room',
p.state_room = '$new_state_room'
WHERE p.id_numberRoom = '$new_id_numberRoom'";
mysql_query($query) or die(mysql_error());
Thank your advance !!!
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jan 05, 2007 5:02 pm
You don't need the first tag. I've said to remove it now three times.
hrubos
Forum Contributor
Posts: 172 Joined: Sat Oct 07, 2006 3:44 pm
Post
by hrubos » Fri Jan 05, 2007 5:37 pm
feyd wrote: You don't need the first tag. I've said to remove it now three times.
hic,
what a pity that I tried once more and It doesn't run
Code: Select all
echo "<td width = '90'><input type='text' name= 'foo[$id_numberRoom][number_room]' size='10' align='right' value= '$number_room' size='8' style='font-family:Arial'></td>" ;
echo "<td width = '90'><input type='text' name= 'foo[$id_numberRoom][state_room]' size='10' align='right' value= '$state_room' size='8' style='font-family:Arial'></div></td>";
Code: Select all
$new_number_room = $_POST['foo'];
$new_state_room=$_POST['foo'];
$query = "UPDATE room p SET p.number_room = '$new_number_room',
p.state_room = '$new_state_room'";
mysql_query($query) or die(mysql_error());
I'm sorry if I have done wrong
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jan 05, 2007 6:03 pm
Go over all the posts in this thread again, carefully and slowly.
hrubos
Forum Contributor
Posts: 172 Joined: Sat Oct 07, 2006 3:44 pm
Post
by hrubos » Sun Jan 07, 2007 1:29 am
So I have tried but actually, I can't make it run!!!