roeyhaim Posted November 4, 2010 Share Posted November 4, 2010 hello when i try to get the checkbox status from my class i get only those who checked i send the &_POST to my class. how should i get also the values of checkboxes which not selected? Quote Link to comment https://forums.phpfreaks.com/topic/217750-_post-checkbox-status/ Share on other sites More sharing options...
AbraCadaver Posted November 4, 2010 Share Posted November 4, 2010 Only selected checkboxes will be sent in post. Quote Link to comment https://forums.phpfreaks.com/topic/217750-_post-checkbox-status/#findComment-1130271 Share on other sites More sharing options...
roeyhaim Posted November 4, 2010 Author Share Posted November 4, 2010 but i need also the value of the checkboxes which not checked. any idea? Quote Link to comment https://forums.phpfreaks.com/topic/217750-_post-checkbox-status/#findComment-1130273 Share on other sites More sharing options...
akitchin Posted November 4, 2010 Share Posted November 4, 2010 what are you using the checkboxes for here? if you need the values in the unchecked checkboxes, then presumably your choice of element is incorrect. Quote Link to comment https://forums.phpfreaks.com/topic/217750-_post-checkbox-status/#findComment-1130276 Share on other sites More sharing options...
AbraCadaver Posted November 4, 2010 Share Posted November 4, 2010 but i need also the value of the checkboxes which not checked. any idea? They don't have a value because they are not checked. If all checkbox values were sent, how would you know which ones were checked and which were not? There are different ways to handle this, but what it comes down to is that you need to know what checkboxes are on the form and then check to see if they are submitted. Example using an array: FORM <input type="checkbox" name="color[red]"> <input type="checkbox" name="color[green]"> <input type="checkbox" name="color[blue]"> PHP if(isset($_POST['color']['red'])) echo 'RED'; if(isset($_POST['color']['green'])) echo 'GREEN'; if(isset($_POST['color']['blue'])) echo 'BLUE'; Quote Link to comment https://forums.phpfreaks.com/topic/217750-_post-checkbox-status/#findComment-1130278 Share on other sites More sharing options...
roeyhaim Posted November 4, 2010 Author Share Posted November 4, 2010 i have a form with some checkboxes. when the user want to edit his profile i need to take the data from the db an put it in the form. and when he updated his profile i need to put in the db the value of each choice. the problem is that i cannot do this on the same page with "if" statement. i need to send the whole data to a class and from there i need to insert it into the db. Quote Link to comment https://forums.phpfreaks.com/topic/217750-_post-checkbox-status/#findComment-1130281 Share on other sites More sharing options...
akitchin Posted November 4, 2010 Share Posted November 4, 2010 you still haven't explained why exactly you need the "value" of the checkbox... can we see the code that produces the HTML form? Quote Link to comment https://forums.phpfreaks.com/topic/217750-_post-checkbox-status/#findComment-1130287 Share on other sites More sharing options...
roeyhaim Posted November 5, 2010 Author Share Posted November 5, 2010 <?php if(!isset($_POST['Submit'])) { ?> <form method=post action=addOmna.php?action=add name=add> <center> <table align="center" border="5" dir="rtl" style="border-style: double;"> <tr><td align="center" nowrap="nowrap"> fullname: <input type="text" name="fullname" value="" /></td></tr> <tr><td align="center" nowrap="nowrap"> phone: <input type="text" name="phone" value="" /></td></tr> <tr><td align="center" nowrap="nowrap"> Address: <input type="text" name="address" value="" /></td></tr> <tr><td align="center" nowrap="nowrap"> E-Mail: <input type="text" name="email" value="" /></td></tr> <tr><td align="center" nowrap="nowrap"> agree to get mails: <input type="checkbox" name="mails" value="1" /></td></tr> <tr><td align="center" nowrap="nowrap"> show image profile: <input type="checkbox" name="status" value="1" checked /></td></tr> <tr><td align="center" nowrap="nowrap"> comments: <br><textarea rows="5" name="comments"></textarea></td></tr> <tr><td align="center" nowrap="nowrap"> <BR> <input type="submit" value="Submit" name="Submit" /> </form></td></tr> </table> </html> <?php } else { $db->insert("users", $_POST); } And this is the insert() function from the $db class: function insert($table, $vars){ foreach($vars as $key => $var){ $values .= "'$var', "; $cols .= "$key, "; } $values = substr_replace($values, "", -12); $cols = substr_replace($cols, "", -10); $sql = "INSERT INTO $table ($cols) VALUES ($values)"; mysql_query($SQL) or die('Error, insert query failed: ' . mysql_error()); echo "<center><font size=5 color=red>"; echo "Process Complete ."; echo "<BR>"; echo "<a href=index.php>Home Page</a>"; echo "</font></center>"; } as you can see i need all the values else i got error message: Error, insert query failed: Query was empty unless you have another idea to this class... Quote Link to comment https://forums.phpfreaks.com/topic/217750-_post-checkbox-status/#findComment-1130642 Share on other sites More sharing options...
rwwd Posted November 5, 2010 Share Posted November 5, 2010 echo the sql to screen to see if your getting the information through that you think you should, in other words debug the sql statement. Rw Quote Link to comment https://forums.phpfreaks.com/topic/217750-_post-checkbox-status/#findComment-1130643 Share on other sites More sharing options...
roeyhaim Posted November 5, 2010 Author Share Posted November 5, 2010 did this.... its all OK, i get the strings as i wanted.... but something dont work... i think its the checkbox that missing. Quote Link to comment https://forums.phpfreaks.com/topic/217750-_post-checkbox-status/#findComment-1130644 Share on other sites More sharing options...
PFMaBiSmAd Posted November 5, 2010 Share Posted November 5, 2010 The error message you are getting is because you are not using the same variable to form your query and to execute your query. $sql is not the same as $SQL Quote Link to comment https://forums.phpfreaks.com/topic/217750-_post-checkbox-status/#findComment-1130646 Share on other sites More sharing options...
rwwd Posted November 5, 2010 Share Posted November 5, 2010 [EDIT]^^^ I was beaten to that one ;-p $sql = "INSERT INTO $table ($cols) VALUES ($values)"; mysql_query($SQL) or die('Error, insert query failed: ' . mysql_error()); Your error is obvious (hint: variables are CaSeSeNsItIvE) And hopefully your connection handle is correct too. A bit of error handling wouldn't be amis here either:- $success = mysql_query($sql) or die('Error, insert query failed: ' . mysql_error()); if ($success){ echo "<center><font size=5 color=red>"; echo "Process Complete ."; echo "<BR>"; echo "<a href=index.php>Home Page</a>"; echo "</font></center>"; } else{ echo "something went wrong"; exit; } See what I mean - mysql_query() returns a bool, you may as well use it.. Rw Quote Link to comment https://forums.phpfreaks.com/topic/217750-_post-checkbox-status/#findComment-1130647 Share on other sites More sharing options...
roeyhaim Posted November 5, 2010 Author Share Posted November 5, 2010 thanks a lot, i missed this part Quote Link to comment https://forums.phpfreaks.com/topic/217750-_post-checkbox-status/#findComment-1130655 Share on other sites More sharing options...
PFMaBiSmAd Posted November 5, 2010 Share Posted November 5, 2010 You should be developing and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON so that all the php detected errors will be reported and displayed. You will save a ton of time. The nonexistent $SQL variable would have produced an undefined error message that would have alerted you to a problem with it. Quote Link to comment https://forums.phpfreaks.com/topic/217750-_post-checkbox-status/#findComment-1130657 Share on other sites More sharing options...
roeyhaim Posted November 5, 2010 Author Share Posted November 5, 2010 I'm developing in NuSphere PhpED. you know how i can config the debugger to that? or its in the php code? Quote Link to comment https://forums.phpfreaks.com/topic/217750-_post-checkbox-status/#findComment-1130663 Share on other sites More sharing options...
PFMaBiSmAd Posted November 5, 2010 Share Posted November 5, 2010 On a development system, you would typically set those in the master php.ini so that parse errors will be reported and displayed as well (setting those in your script will only show fatal runtime, warning, and notice errors.) Stop and start your web server to get any change made to the master php.ini to take effect and use a phpinfo(); statement to confirm that the settings actually changed in case the php.ini that you changed is not the one that php is using. Quote Link to comment https://forums.phpfreaks.com/topic/217750-_post-checkbox-status/#findComment-1130669 Share on other sites More sharing options...
rwwd Posted November 5, 2010 Share Posted November 5, 2010 <tangent> I'm developing in NuSphere PhpED. you know how i can config the debugger to that? or its in the php code? I have been looking for a new text editor that supports code folding, and from what the blurb tells me this looks pretty good. I have used text pad for 8+ years (notepad before that for a few years too!), and am quite happy with it, but having code folding would make it THE perfect tool Thanks for sharing your chosen IDE with us, I shall have to try it, it seems like the only downside is that it is a complete IDE similar to zend IDE & Eclipse IDE (which I use for NIOS) which is a pig to set up. </tangent> Yes, developing with error reporting/display errors is an absolute must, though I do set it to this: error_reporting(E_ALL|E_STRICT|E_DEPRECATE); I find as this satisfies all compatibility issues, and makes you structure things a little better when designing the flow of your work; especially with in class context. Rw Quote Link to comment https://forums.phpfreaks.com/topic/217750-_post-checkbox-status/#findComment-1130673 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.