PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old October 10th, 2002, 10:42 AM
tmurphy tmurphy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Apopka Fl. USA
Posts: 56 tmurphy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to tmurphy
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'

Reply With Quote
  #2  
Old October 10th, 2002, 11:04 AM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
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:
Original - php Code
  1. <?
  2. if(isset($_POST['submit'])) {
  3.     foreach($b_hbday as $value) {
  4.         $sql = "UPDATE customers SET b_hbday = 'Y' WHERE id = '$value'";
  5.         echo "$sql<BR>n";
  6.         $result = @mysql_query($sql,$connection) or die("Couldn't execute query.");
  7.     }
  8. } else {
  9. ?>
  10. <FORM method=POST action="<? echo $PHP_SELF; ?>">
  11. <TR ALIGN="CENTER">
  12. <TD> somename</TD>
  13. <TD>somespouse</TD>
  14. <TD>somelastname</TD>
  15. <TD>somephone</TD>
  16. <TD><input type="checkbox" name="b_hbday[]" value="2"></TD><BR>
  17. </TR>
  18. <TR ALIGN="CENTER">
  19. <TD> somename</TD>
  20. <TD>somespouse</TD>
  21. <TD>somelastname</TD>
  22. <TD>somephone</TD>
  23. <TD><input type="checkbox" name="b_hbday[]" value="3"></TD><BR>
  24. </TR>
  25. <TR ALIGN="CENTER">
  26. <TD>somenextperson</TD>
  27. <TD>nextpersonspouse</TD>
  28. <TD>nextpersonlastname</TD>
  29. <TD>nextpersonphone</TD>
  30. <TD><input type="checkbox" name="b_hbday[]" value="4"></TD><BR>
  31. </TR>
  32. <input type="submit" name="submit" value="Submit">
  33. </FORM>
  34. <?
  35. }
  36. ?>

Reply With Quote
  #3  
Old October 10th, 2002, 11:29 AM
tmurphy tmurphy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Apopka Fl. USA
Posts: 56 tmurphy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to tmurphy
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>


Reply With Quote
  #4  
Old October 10th, 2002, 11:33 AM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: help with mysql update

Did you add you mysql_connect and mysql_select_db lines to the top of that script?

Reply With Quote
  #5  
Old October 10th, 2002, 11:45 AM
tmurphy tmurphy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Apopka Fl. USA
Posts: 56 tmurphy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to tmurphy
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

Reply With Quote
  #6  
Old October 10th, 2002, 11:51 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: help with mysql update

Paste the entire script here that you are using.

Reply With Quote
  #7  
Old October 10th, 2002, 11:56 AM
tmurphy tmurphy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Apopka Fl. USA
Posts: 56 tmurphy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to tmurphy
RE: help with mysql update

[snip]

Reply With Quote
  #8  
Old October 10th, 2002, 12:14 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: help with mysql update

OK, use this script and then past back what the echo "$sql<BR>n"; lines show you...

[snip]

Reply With Quote
  #9  
Old October 10th, 2002, 12:23 PM
tmurphy tmurphy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Apopka Fl. USA
Posts: 56 tmurphy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to tmurphy
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/

Reply With Quote
  #10  
Old October 10th, 2002, 12:34 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: help with mysql update

Sorry about that...try this:

[snip]

Reply With Quote
  #11  
Old October 10th, 2002, 12:41 PM
tmurphy tmurphy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Apopka Fl. USA
Posts: 56 tmurphy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to tmurphy
RE: help with mysql update

got it but there is still no values writing to the database

Reply With Quote
  #12  
Old October 10th, 2002, 01:03 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
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...

Reply With Quote
  #13  
Old October 10th, 2002, 01:14 PM
tmurphy tmurphy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Apopka Fl. USA
Posts: 56 tmurphy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to tmurphy
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

Reply With Quote
  #14  
Old October 10th, 2002, 01:17 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
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'])) {


Reply With Quote
  #15  
Old October 10th, 2002, 01:22 PM
tmurphy tmurphy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Apopka Fl. USA
Posts: 56 tmurphy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time sp