laurajohn89 Posted February 19, 2010 Share Posted February 19, 2010 Hi, I've searched everywhere and had no luck... I have a form where users tick checkboxes to enter horse riding event types. I need to store these types on my database and display them in a table. However when I look at the results I get the word 'array' under the type column in my database. Thank you very much for your help. HTML code: <form action="insert.php" method="post"> <table width="400" border="0" cellspacing="0" cellpadding="2"> <tr> <td width="200">Title: </td> <td><input type="text" name="title" /> </td> </tr> <td width="200">Type of Event: </td> <td><p class="contentclass"><input type="checkbox" name="type[combined training]" id="type[combined training]" value="1" />Combined Training</p></td> <td><p class="contentclass"><input type="checkbox" name="type[dressage]" id="type[dressage]" value="1" />Dressage</p></td> <td><p class="contentclass"><input type="checkbox" name="type[demos/trials]" id="type[demos/trials]" value="1" />Demos / Trials</p></td> <td><p class="contentclass"><input type="checkbox" name="type[driving]" id="type[driving]" value="1" />Driving</p></td> </tr><tr> <td><p class="contentclass"><input type="checkbox" name="type[endurance]" id="type[endurance]" value="1" />Endurance</p></td> <td><p class="contentclass"><input type="checkbox" name="type[eventing]" id="type[eventing]" value="1" />Eventing</p></td> <td><p class="contentclass"><input type="checkbox" name="type[ex-racehorse classes]" id="type[ex-racehorse classes]" value="Ex-Racehorse Classes" />Ex-Racehorse lasses</p></td> <td><p class="contentclass"><input type="checkbox" name="type[fun/sponsored]" id="type[fun/sponsored]" value="Fun / Sponsored" />Fun / Sponsored</p></td> </tr><tr> <td><p class="contentclass"><input type="checkbox" name="type[hunting]" id="type[hunting]" value="Hunting" />Hunting</p></td> <td><p class="contentclass"><input type="checkbox" name="type[jumpcross]" id="type[jumpcross]" value="Jumpcross" />Jumpcross</p></td> <td><p class="contentclass"><input type="checkbox" name="type[ride]" id="type[ride]" value="Ride" />Ride</p></td> <td><p class="contentclass"><input type="checkbox" name="type[sale/auction]" id="type[sale/auction]" value="Sale/Auction" />Sale/Auction</p></td> </tr><tr> <td><p class="contentclass"><input type="checkbox" name="type[show jumping]" id="type[show jumping]" value="Show Jumping" />Show Jumping</p></td> <td><p class="contentclass"><input type="checkbox" name="type[shows/mixed discplins]" id="type[shows/mixed discplins]" value="Shows / Mixed Discplins" />Shows / Mixed Discplins</p></td> <td><p class="contentclass"><input type="checkbox" name="type[training clinic]" id="type[training clinic]" value="Training Clinic" />Training Clinic</p></td> <td><p class="contentclass"><input type="checkbox" name="type[trec]" id="type[trec]" value="Trec" />Trec</p></td> </tr><tr> <td><p class="contentclass"><input type="checkbox" name="type[other]" id="type[other]" value="Other" />Other</p></td> <tr> </tr> </tr> <tr> PHP code: $sql="INSERT INTO events (title, type, place, address, date, time, website, contact, additional) VALUES ('$_POST[title]','$_POST[type]','$_POST[place]','$_POST[address]','$_POST[date]','$_POST[time]','$_POST[website]','$_POST[contact]','$_POST[additional]')"; thanks in advanced Link to comment https://forums.phpfreaks.com/topic/192635-checkbox-array-help/ Share on other sites More sharing options...
sader Posted February 19, 2010 Share Posted February 19, 2010 try $_POST['type']['dressage'] ... $_POST['type']['driving'] also I suggest not use 'spaces' '/' symbols in names Link to comment https://forums.phpfreaks.com/topic/192635-checkbox-array-help/#findComment-1014840 Share on other sites More sharing options...
laurajohn89 Posted February 21, 2010 Author Share Posted February 21, 2010 Thanks but no help. Now I just get a blank page comming up. Link to comment https://forums.phpfreaks.com/topic/192635-checkbox-array-help/#findComment-1015622 Share on other sites More sharing options...
laurajohn89 Posted February 21, 2010 Author Share Posted February 21, 2010 and now I get this error Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'combinedtraining'] Array['demostrails'] Array['dressage'] Array['driving'] Array' at line 4 Link to comment https://forums.phpfreaks.com/topic/192635-checkbox-array-help/#findComment-1015626 Share on other sites More sharing options...
perseadrian Posted February 21, 2010 Share Posted February 21, 2010 Hi, I've searched everywhere and had no luck... I have a form where users tick checkboxes to enter horse riding event types. I need to store these types on my database and display them in a table. However when I look at the results I get the word 'array' under the type column in my database. Thank you very much for your help. HTML code: <form action="insert.php" method="post"> <table width="400" border="0" cellspacing="0" cellpadding="2"> <tr> <td width="200">Title: </td> <td><input type="text" name="title" /> </td> </tr> <td width="200">Type of Event: </td> <td><p class="contentclass"><input type="checkbox" name="type[combined training]" id="type[combined training]" value="1" />Combined Training</p></td> <td><p class="contentclass"><input type="checkbox" name="type[dressage]" id="type[dressage]" value="1" />Dressage</p></td> <td><p class="contentclass"><input type="checkbox" name="type[demos/trials]" id="type[demos/trials]" value="1" />Demos / Trials</p></td> <td><p class="contentclass"><input type="checkbox" name="type[driving]" id="type[driving]" value="1" />Driving</p></td> </tr><tr> <td><p class="contentclass"><input type="checkbox" name="type[endurance]" id="type[endurance]" value="1" />Endurance</p></td> <td><p class="contentclass"><input type="checkbox" name="type[eventing]" id="type[eventing]" value="1" />Eventing</p></td> <td><p class="contentclass"><input type="checkbox" name="type[ex-racehorse classes]" id="type[ex-racehorse classes]" value="Ex-Racehorse Classes" />Ex-Racehorse lasses</p></td> <td><p class="contentclass"><input type="checkbox" name="type[fun/sponsored]" id="type[fun/sponsored]" value="Fun / Sponsored" />Fun / Sponsored</p></td> </tr><tr> <td><p class="contentclass"><input type="checkbox" name="type[hunting]" id="type[hunting]" value="Hunting" />Hunting</p></td> <td><p class="contentclass"><input type="checkbox" name="type[jumpcross]" id="type[jumpcross]" value="Jumpcross" />Jumpcross</p></td> <td><p class="contentclass"><input type="checkbox" name="type[ride]" id="type[ride]" value="Ride" />Ride</p></td> <td><p class="contentclass"><input type="checkbox" name="type[sale/auction]" id="type[sale/auction]" value="Sale/Auction" />Sale/Auction</p></td> </tr><tr> <td><p class="contentclass"><input type="checkbox" name="type[show jumping]" id="type[show jumping]" value="Show Jumping" />Show Jumping</p></td> <td><p class="contentclass"><input type="checkbox" name="type[shows/mixed discplins]" id="type[shows/mixed discplins]" value="Shows / Mixed Discplins" />Shows / Mixed Discplins</p></td> <td><p class="contentclass"><input type="checkbox" name="type[training clinic]" id="type[training clinic]" value="Training Clinic" />Training Clinic</p></td> <td><p class="contentclass"><input type="checkbox" name="type[trec]" id="type[trec]" value="Trec" />Trec</p></td> </tr><tr> <td><p class="contentclass"><input type="checkbox" name="type[other]" id="type[other]" value="Other" />Other</p></td> <tr> </tr> </tr> <tr> PHP code: $sql="INSERT INTO events (title, type, place, address, date, time, website, contact, additional) VALUES ('$_POST[title]','$_POST[type]','$_POST[place]','$_POST[address]','$_POST[date]','$_POST[time]','$_POST[website]','$_POST[contact]','$_POST[additional]')"; thanks in advanced Dear Laura, It because $_POST, must be outside the string, otherwise will no work, and the title must be like $_POST['title'] . If this not work you can check all variables submitted with echo phpinfo() at the top of your file . It will display all data you need. Link to comment https://forums.phpfreaks.com/topic/192635-checkbox-array-help/#findComment-1015639 Share on other sites More sharing options...
laurajohn89 Posted February 21, 2010 Author Share Posted February 21, 2010 If I move the POST outside the string it doesn't work. Everything else shows up on the database except for the type column which just shows array when I display the table. Link to comment https://forums.phpfreaks.com/topic/192635-checkbox-array-help/#findComment-1015698 Share on other sites More sharing options...
sader Posted February 21, 2010 Share Posted February 21, 2010 in top of insert.php type this: var_dump($_POST); what u get? Link to comment https://forums.phpfreaks.com/topic/192635-checkbox-array-help/#findComment-1015702 Share on other sites More sharing options...
laurajohn89 Posted February 21, 2010 Author Share Posted February 21, 2010 thanks but I've sorted it now. Another forum helped. I inserted $type = implode(",",$_POST['type']); for($i = 0; $i < sizeof($type); $i++) { $query = "INSERT INTO events (type) VALUES ('".$type."')"; $result = mysql_query($query) or die(mysql_error()); } mysql_close($dbh); // Echo to the browser. if(count($type) == 0){echo "<p>No Checkbox selected !</p>";} if (count($type) > 0) { for ($i=0;$i<count($type);$i++) { echo "<li>$type[$i] \n"; } } and its fine. thanks Link to comment https://forums.phpfreaks.com/topic/192635-checkbox-array-help/#findComment-1015730 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.