|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
||||
|
||||
|
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 |
|
#4
|
|||
|
|||
|
Quote:
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. |
|
#5
|
|||
|
|||
|
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 |
|
#6
|
||||
|
||||
|
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.
|
|
#7
|
|||
|
|||
|
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... |
|
#8
|
|||
|
|||
|
What output do you get from print $specs?
|
|
#9
|
|||
|
|||
|
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... |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > Checkboxes into MySql |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|