MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old March 2nd, 2004, 08:22 PM
dotcomma dotcomma is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: New Zealand
Posts: 20 dotcomma User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Checkboxes into MySql

Hi all,
I'm having trouble updating a db field with a checkbox array. In fact I have twi arrays, and one will update but not the other. Here's the code:

$specials = ($_POST["SpecialName"]);
$specs = implode("<br> ", $specials);

$sqlSpec = ("UPDATE jobs SET specialname = ('" . $specs . "') WHERE jobid='" . $_SESSION['jobid'] . "'") or DIE("Couldn't update the Specials in the jobs table.</h3></center>");
mysql_query ($sqlSpec);
print $specs . "<br />\n";

if ($_POST["extras"]){
$xtras = ($_POST["extras"]);
$extras = implode(", ", $xtras);

$sqlXtra = ("UPDATE jobs SET extras = ('" . $extras . "') WHERE jobid='" . $_SESSION['jobid'] . "'") or DIE("Couldn't update the Extras in the jobs table.</h3></center>");
mysql_query ($sqlXtra);
print $extras;
}

The Extra's will update, but not the Specials. The code is identical, and the "print" statements output both correctly onto the screen, just not into the database.
Any help would be greatly appreciated.

Toine

Reply With Quote
  #2  
Old March 3rd, 2004, 07:21 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Weird. I don't see any problems with the code. Maybe consolidate the queries into one. I don't know that that'd solve your problem, but it's more efficient. Maybe you're doing them separately so that you can have a different failure message for each type of update.
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
  #3  
Old March 3rd, 2004, 09:56 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
Perhaps add your queries into your Die statement, and perhaps a mysql_error()... this way you can tell exactly what the error is and perhaps where...

...or die("Couldn't update the Extras in the jobs table<br>$sqlXtra<br>".mysql_query());

Just don't forget to take it out when you go into production...
In the past i've found that dealing with checkboxes are the hardest, because when its not checked it simply doesn't exist

Reply With Quote
  #4  
Old March 3rd, 2004, 03:23 PM
Everah Everah is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: East Bay Area
Posts: 3 Everah User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by dotcomma
$specials = ($_POST["SpecialName"]);
$specs = implode("<br> ", $specials);

...

if ($_POST["extras"]){
$xtras = ($_POST["extras"]);
$extras = implode(", ", $xtras);

...
}

The Extra's will update, but not the Specials. The code is identical, and the "print" statements output both correctly onto the screen, just not into the database.
Any help would be greatly appreciated.

Toine

Have you looked at the HTML form fields to make sure the checkbox field named 'SpecialName' is labeled as 'SpecialName[]'? Just a thought if one is working and the other is not. It might not be the processing but how the information is captured.

Reply With Quote
  #5  
Old March 5th, 2004, 03:40 AM
dotcomma dotcomma is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: New Zealand
Posts: 20 dotcomma User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Sorry I took so long getting back to you... and thanks for your help so far!
Adding the queries into my Die statement didn't do anything? I was hoping to get some meaningful errormessage, but it made no difference at all.
I have found out however that the string may be too long. When I check only 2 or 3 choices the string will get added to the DB. After consulting the MySql manual I have changed the DB field from VARCHAR(255) to LONGTEXT but again, no difference. Even if the string is only 141 characters long, it won't insert (I checked the number of characters in Word).
Any ideas on what else the problem could be?
Thanks,

Toine

Reply With Quote
  #6  
Old March 5th, 2004, 07:52 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Just to verify: In your HTML form code, are you adding brackets ([]) after the field name for both fields? Could be that PHP's not treating your field as an array if not and that the implode therefore isn't working and is giving you a blank value.

Reply With Quote
  #7  
Old March 5th, 2004, 09:11 AM
dotcomma dotcomma is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: New Zealand
Posts: 20 dotcomma User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I have indeed added those brackets... and the Print command (print $specs . "<br />\n") outputs the array correctly onto the screen - it just won't go into the db!
Here's the current code (I have also tried listing 2 or 3 items manually, with the same result):

<td valign="top">
<?php while (($Repeat1__numRows-- != 0) && (!$rsSpecials->EOF))
{
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<input type="checkbox" name="SpecialName[]" value="<?php echo $rsSpecials->Fields("specialname") . " - " . $rsSpecials->Fields("specialdate")?>" checked>
</td>
<td align="left">
<?php echo $rsSpecials->Fields("specialname")?>,
<?php echo $rsSpecials->Fields("specialdate")?>
</td>
</tr>
</table>
<?php
$Repeat1__index++;
$rsSpecials->MoveNext();
}
?>
</td>

As you see I am adding both the name and the date, but I have also tried just adding the name - same result...

Reply With Quote
  #8  
Old March 5th, 2004, 11:15 AM
Everah Everah is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: East Bay Area
Posts: 3 Everah User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
What output do you get from print $specs?

Reply With Quote
  #9  
Old March 6th, 2004, 03:00 AM
dotcomma dotcomma is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: New Zealand
Posts: 20 dotcomma User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
This is what appears on my screen:

Holy Places - 9/04/04
Easter - 11/04/04
Seminary - 2/05/04
Peter's Pence - 27/06/04
M.P.C. - 22/08/04
Missions - 24/10/04
Christmas - 25/12/04
Holy Places - 25/03/05
Easter - 27/03/05

When I check my DB, the field is empty.

~*~*~*~*~*~*~

Update:
I am having this problem on my laptop, which is what I do all my work on these days.
Last night I have installed Apache, PHP and MySql onto a desktop machine, which will eventually go into the printery when everything's working properly. They're different (older) versions and the OS is Win98SE. It is working fine there!
My laptop is running WinXP Home and newer versions of Apache etc. Perhaps if I feel like it I might intall the older versions on my laptop and see what happens...

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Checkboxes into MySql


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway