Connecting Tech Pros Worldwide Forums | Help | Site Map

HTML table Update row PHP/MySQL

rukkie
Guest
 
Posts: n/a
#1: Jan 24 '07
Hi,

I have a dynamic HTML page with 4 columns of data, retrieved with PHP
from a MySQL database.
At the end of every row I have an UPDATE submit button, which activates
a php update script to update the database. I now encounter the problem
that in the update script I cannot trace back for which row the UPDATE
buttom was pressed.

I first had defined the UPDATE button as : <input name="update"
value="UPDATE" type="submit">. That doesn't work ...
If I change the definition to <input name="update" value=<? echo
"UPDATE".$nt['id']; ?type="submit">, then I can get the id number in
the update script, but the display is not that good, because you see
UPDATE1, UPDATE7,UPDATE4 and so on ...
So I need something, so I can find back in the update script for which
row the update button was pressed. Each row has his unique id (which is
not shown in the table)

Anyone has a suggestion on how to solve this ?

Thanks in advance.


Rik
Guest
 
Posts: n/a
#2: Jan 24 '07

re: HTML table Update row PHP/MySQL


On Wed, 24 Jan 2007 17:56:33 +0100, rukkie <rukkie@belgacom.netwrote:
Quote:
I first had defined the UPDATE button as : <input name="update"
value="UPDATE" type="submit">. That doesn't work ...
If I change the definition to <input name="update" value=<? echo
"UPDATE".$nt['id']; ?type="submit">, then I can get the id number in
the update script, but the display is not that good, because you see
UPDATE1, UPDATE7,UPDATE4 and so on ...
So I need something, so I can find back in the update script for which
row the update button was pressed. Each row has his unique id (which is
not shown in the table)
>
Anyone has a suggestion on how to solve this ?
'<input name="update['.$id.']" value="UPDATE" type="submit">'

In the update:
$id = intval(reset(array_keys($_POST['update'])));
--
Rik Wasmus
* I'm testing several new newsreaders at the moment. Please excuse
possible errors and weird content. *
rukkie
Guest
 
Posts: n/a
#3: Jan 24 '07

re: HTML table Update row PHP/MySQL


Thanks for the reply ....

Now I get some weird warning :

Warning: array_keys(): The first argument should be an array in
xxxx.php on line 9

and line 9 is the line with : $id =
intval(reset(array_keys($_POST['update'])));

Any suggestion of what could be wrong ?


On 24 jan, 18:03, Rik <luiheidsgoe...@hotmail.comwrote:
Quote:
On Wed, 24 Jan 2007 17:56:33 +0100, rukkie <ruk...@belgacom.netwrote:
Quote:
I first had defined the UPDATE button as : <input name="update"
value="UPDATE" type="submit">. That doesn't work ...
If I change the definition to <input name="update" value=<? echo
"UPDATE".$nt['id']; ?type="submit">, then I can get the id number in
the update script, but the display is not that good, because you see
UPDATE1, UPDATE7,UPDATE4 and so on ...
So I need something, so I can find back in the update script for which
row the update button was pressed. Each row has his unique id (which is
not shown in the table)
>
Quote:
Anyone has a suggestion on how to solve this ?'<input name="update['.$id.']" value="UPDATE" type="submit">'
>
In the update:
$id = intval(reset(array_keys($_POST['update'])));
--
Rik Wasmus
* I'm testing several new newsreaders at the moment. Please excuse
possible errors and weird content. *
Geoff Berrow
Guest
 
Posts: n/a
#4: Jan 24 '07

re: HTML table Update row PHP/MySQL


Message-ID: <1169657792.959426.116980@s48g2000cws.googlegroups .comfrom
rukkie contained the following:
Quote:
>I first had defined the UPDATE button as : <input name="update"
>value="UPDATE" type="submit">. That doesn't work ...
>If I change the definition to <input name="update" value=<? echo
>"UPDATE".$nt['id']; ?type="submit">, then I can get the id number in
>the update script, but the display is not that good, because you see
>UPDATE1, UPDATE7,UPDATE4 and so on ...
>So I need something, so I can find back in the update script for which
>row the update button was pressed. Each row has his unique id (which is
>not shown in the table)
>
>Anyone has a suggestion on how to solve this ?
One way is to make each row a separate form and use a hidden field. to
pass the id. Alternatively use checkboxes to get an array of ids and do
a multiple update with a single submit button.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Rik
Guest
 
Posts: n/a
#5: Jan 24 '07

re: HTML table Update row PHP/MySQL


On Wed, 24 Jan 2007 18:23:36 +0100, rukkie <rukkie@belgacom.netwrote:
Quote:
Thanks for the reply ....
Thank me by not topposting.
Quote:
On 24 jan, 18:03, Rik <luiheidsgoe...@hotmail.comwrote:
Quote:
>On Wed, 24 Jan 2007 17:56:33 +0100, rukkie <ruk...@belgacom.netwrote:
Quote:
I first had defined the UPDATE button as : <input name="update"
value="UPDATE" type="submit">. That doesn't work ...
If I change the definition to <input name="update" value=<? echo
"UPDATE".$nt['id']; ?type="submit">, then I can get the id number in
the update script, but the display is not that good, because you see
UPDATE1, UPDATE7,UPDATE4 and so on ...
So I need something, so I can find back in the update script for which
row the update button was pressed. Each row has his unique id (which
>is
Quote:
not shown in the table)
>>
Quote:
Anyone has a suggestion on how to solve this ?'<input
>name="update['.$id.']" value="UPDATE" type="submit">'
>>
>In the update:
>$id = intval(reset(array_keys($_POST['update'])));
>
Now I get some weird warning :
>
Warning: array_keys(): The first argument should be an array in
xxxx.php on line 9
Did you alter the name of the input like I told you?
The HTML-source should look like: '<input name="update[123]"
value="UPDATE">';
After posting, var_dump $_POST to see what it contains.

--
Rik Wasmus
* I'm testing several new newsreaders at the moment. Please excuse
possible errors and weird content. *
rukkie
Guest
 
Posts: n/a
#6: Jan 24 '07

re: HTML table Update row PHP/MySQL


Hi,

thanks a lot.

At the end I've got it working with this part of code : <?echo "<input
name=\"update[".$nt['id']."]\""; ?>
Some quotes and/or double quotes makes the difference

Thanks !!

On 24 jan, 18:49, Rik <luiheidsgoe...@hotmail.comwrote:
Quote:
On Wed, 24 Jan 2007 18:23:36 +0100, rukkie <ruk...@belgacom.netwrote:
Quote:
Thanks for the reply ....Thank me by not topposting.
>
>
>
Quote:
On 24 jan, 18:03, Rik <luiheidsgoe...@hotmail.comwrote:
Quote:
On Wed, 24 Jan 2007 17:56:33 +0100, rukkie <ruk...@belgacom.netwrote:
I first had defined the UPDATE button as : <input name="update"
value="UPDATE" type="submit">. That doesn't work ...
If I change the definition to <input name="update" value=<? echo
"UPDATE".$nt['id']; ?type="submit">, then I can get the id number in
the update script, but the display is not that good, because you see
UPDATE1, UPDATE7,UPDATE4 and so on ...
So I need something, so I can find back in the update script for which
row the update button was pressed. Each row has his unique id (which
is
not shown in the table)
>
Quote:
Quote:
Anyone has a suggestion on how to solve this ?'<input
name="update['.$id.']" value="UPDATE" type="submit">'
>
Quote:
Quote:
In the update:
$id = intval(reset(array_keys($_POST['update'])));
>
Quote:
Now I get some weird warning :
>
Quote:
Warning: array_keys(): The first argument should be an array in
xxxx.php on line 9Did you alter the name of the input like I told you?
The HTML-source should look like: '<input name="update[123]"
value="UPDATE">';
After posting, var_dump $_POST to see what it contains.
>
--
Rik Wasmus
* I'm testing several new newsreaders at the moment. Please excuse
possible errors and weird content. *
Rik
Guest
 
Posts: n/a
#7: Jan 24 '07

re: HTML table Update row PHP/MySQL


On Wed, 24 Jan 2007 20:04:32 +0100, rukkie <rukkie@belgacom.netwrote:
Quote:
thanks a lot.
You'd really thank me by starting to bottompost instead of toppost.
Quote:
Quote:
Quote:
>'<input name="update['.$id.']" value="UPDATE" type="submit">'
>>
>In the update:
>$id = intval(reset(array_keys($_POST['update'])));
>>
Quote:
Now I get some weird warning :
>>
Quote:
Warning: array_keys(): The first argument should be an array in
xxxx.php on line 9Did you alter the name of the input like I told you?
>The HTML-source should look like: '<input name="update[123]"
>value="UPDATE">';
>After posting, var_dump $_POST to see what it contains.
>>
At the end I've got it working with this part of code : <?echo "<input
name=\"update[".$nt['id']."]\""; ?>
Some quotes and/or double quotes makes the difference
That's why I said:
'<input name="update['.$id.']" value="UPDATE" type="submit">'
Seems a lot more readable then:
"<input name=\"update[".$nt['id']."]\"" value=\"UPDATE\"
type=\"submit\">";
--
Rik Wasmus
* I'm testing several new newsreaders at the moment. Please excuse
possible errors and weird content. *
Closed Thread