|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
help with mysql update
i can't get mysql to update multiple records. Can someone help out ?
I run a while ($row=mysql_fetch_array($mysql_result)) to get the form i need to do the update. That works fine but when i try to create an array to write the updated information back to the database it doesn't work. this is what i have so far foreach($id as $key=>$value) { for ($i=0; $i<$value; $i++) { echo "$sql<BR>n"; $sql = "UPDATE customers SET b_hbday = '{$b_hbday[$key]}' WHERE id = '$value' "; but when i update i get this message UPDATE customers SET b_hbday = 'Y' WHERE id = '3' UPDATE customers SET b_hbday = 'Y' WHERE id = '3' UPDATE customers SET b_hbday = 'Y' WHERE id = '3' UPDATE customers SET b_hbday = '' WHERE id = '4' UPDATE customers SET b_hbday = '' WHERE id = '4' UPDATE customers SET b_hbday = '' WHERE id = '4' UPDATE customers SET b_hbday = '' WHERE id = '4' UPDATE customers SET b_hbday = '' WHERE id = '5' UPDATE customers SET b_hbday = '' WHERE id = '5' UPDATE customers SET b_hbday = '' WHERE id = '5' UPDATE customers SET b_hbday = '' WHERE id = '5' |
|
#2
|
|||||
|
|||||
|
RE: help with mysql update
It would be easier for you to get rid of those hidden fields and put the id in the value of the checkbox. Check out this code:
php Code:
|
|
#3
|
|||
|
|||
|
RE: help with mysql update
no errors but it is not wirting anything to the database. here is the html output for the records
<TD>name1</TD> <TDspouse1</TD> <TD>lastname1</TD> <TD>number1</TD> <TD><input type="checkbox" name="b_hbday[]" value="3"></TD> </TR> <TR ALIGN="CENTER"> <TD></TD> <TD>name2</TD> <TD>apouse2</TD> <TDlastname2</TD> <TD>number2</TD> <TD><input type="checkbox" name="b_hbday[]" value="4"></TD> </TR> <TR ALIGN="CENTER"> <TD></TD> <TD>name3</TD> <TD>spouse3</TD> <TD>lastname3</TD> <TD>number3</TD> <TD><input type="checkbox" name="b_hbday[]" value="5"></TD> |
|
#4
|
|||
|
|||
|
RE: help with mysql update
Did you add you mysql_connect and mysql_select_db lines to the top of that script?
|
|
#5
|
|||
|
|||
|
RE: help with mysql update
yes, i have a page test.php on this page i get all the customers from the database. This is from a mysql query. the second page is do_arrm.php. this is where the update is suppose to happen. now when i use $PHP_SELF i got rid of do_arrm.php it seems to work but when i go to the database there is no entry for the checkbox
|
|
#6
|
|||
|
|||
|
RE: help with mysql update
Paste the entire script here that you are using.
|
|
#7
|
|||
|
|||
|
RE: help with mysql update
[snip]
|
|
#8
|
|||
|
|||
|
RE: help with mysql update
OK, use this script and then past back what the echo "$sql<BR>n"; lines show you...
[snip] |
|
#9
|
|||
|
|||
|
RE: help with mysql update
Parse error: parse error in on line 32
it is the } right before else if(isset($_POST['submit'])) { foreach($b_hbday as $value) $sql = "UPDATE customers SET b_hbday = 'Y' WHERE id = '$value'"; echo "$sql<BR>n"; mysql_query($sql,$connection) or die("Couldn't execute query."); } } else { when i remove this it lets me view the page when i hit submit the echo "$sql<BR>n"; returns nothing if you want to see the page go to http://int.myresponsetracker.com/test/ |
|
#10
|
|||
|
|||
|
RE: help with mysql update
Sorry about that...try this:
[snip] |
|
#11
|
|||
|
|||
|
RE: help with mysql update
got it but there is still no values writing to the database
|
|
#12
|
|||
|
|||
|
RE: help with mysql update
I just added data to a datbase and tested out the script here locally. It works great. When I went to your test page, I noticed other things being outputted (some horizontal rules,etc) that were not in the script you placed here...try the script that I posted as is without adding anything else...
|
|
#13
|
|||
|
|||
|
RE: help with mysql update
oh i was using arrm.inc for the code and made a template for header nav and footer inside a phtml file i created a index.php file copied the code there and got the same results
http://int.myresponsetracker.com/test/index.php |
|
#14
|
|||
|
|||
|
RE: help with mysql update
Hmm....the only thing I can think of is that the version of PHP you are on is prior to 4.1.0...change:
if(isset($_POST['B1'])) { to: if(isset($HTTP_POST_VARS['B1'])) { |
|
#15
|
|||
|