hungryOrb Posted October 2, 2007 Share Posted October 2, 2007 ??? hii< I started leaning php recently, and am having a go at making an editable database which runs through MySQL. At this point, I have a problem with recognising or storing a value that is (hopefully) sent via a checked checkbox.. I assume that checked is one return value and unchecked is another, but using the print_r function, the return value from a checked checkbox is simply "" null and nothing and its making me very sad Is there something stupidly simple that I've tripped over? Thanks you very much in advance.. orb P.S. The form sends all inputs to a form called amendjob.php - and this php is currently simply has enabled the code: print_r($_POST); Quote Link to comment https://forums.phpfreaks.com/topic/71519-solved-nub-q/ Share on other sites More sharing options...
MmmVomit Posted October 2, 2007 Share Posted October 2, 2007 Can you post some of your actual code? Quote Link to comment https://forums.phpfreaks.com/topic/71519-solved-nub-q/#findComment-360059 Share on other sites More sharing options...
hungryOrb Posted October 2, 2007 Author Share Posted October 2, 2007 Well the form code is like this: <form name="input" action="amendjob.php" method="post"> <input type="hidden" name="id" value="<?php echo $_GET['id'] ?>"> Priority: <select name="priority" value="<?php echo $queryrow['Priority']; ?>"> <option value="">Not Set</option> <?php //$queryrow['Priority']=2; for ($i=0; $i<=5; $i++){ echo "<option "; if ($queryrow['Priority']==$i) {echo "selected=\"selected\" ";} echo "value=\"".$i."\">".$i."</option>\n"; } ?> </select> <br> IT Staff: <input type="text" name="itstaff" size="20" value="<?php echo $queryrow['IT Staff']; ?>"> <br> Started: <input type="checkbox" name="started" size="8" value="<?php echo $queryrow['Started']; ?>"> <br> Finished: <input type="checkbox" name="finished" size="8" value="<?php echo $queryrow['Finished']; ?>"> <br> Complete: <input type="checkbox" name="complete" value="Car" value="<?php echo $queryrow['Complete']; ?>" /> <br> Hold: <input type="checkbox" name="hold" value="Car" value="<?php echo $queryrow['Hold']; ?>" /> <br> On hold since:<br> <input type="text" name="onholdsince" size="8" value="<?php echo $queryrow['On hold since']; ?>"> <br> Notes:<br> <textarea rows="10" cols="30" name="notes" value="<?php echo $queryrow['Notes']; ?>"> </textarea> <br>Time Spent:<br> <input type="text" name="sumofduration" size="8" value="<?php echo $queryrow['Sum of duration']; ?>"> <br> <br><br><b>Update fields:<br></b><input align="center" type="submit" value="Update" > </form> Obviously, all this does is send the fields to amendjob.php, while displaying the contents of the database (if there are any values there) on this page which is workonjob.php. Quote Link to comment https://forums.phpfreaks.com/topic/71519-solved-nub-q/#findComment-360079 Share on other sites More sharing options...
MmmVomit Posted October 2, 2007 Share Posted October 2, 2007 Unfortunately, I haven't actually used check boxes before, so I don't know what to expect. I do see a couple of errors, though. Started: <input type="checkbox" name="started" size="8" value="<?php echo $queryrow['Started']; ?>"> <br> Finished: <input type="checkbox" name="finished" size="8" value="<?php echo $queryrow['Finished']; ?>"> <br> Complete: <input type="checkbox" name="complete" value="Car" value="<?php echo $queryrow['Complete']; ?>" /> <br> Hold: <input type="checkbox" name="hold" value="Car" value="<?php echo $queryrow['Hold']; ?>" /> <br> On the complete and hold check boxes, you have two value attributes. For testing, try changing all the value attributes to a static value. Also, where you're trying to set the value attribute to a piece of data from the database, I think you may want to use the checked attribute instead. Quote Link to comment https://forums.phpfreaks.com/topic/71519-solved-nub-q/#findComment-360106 Share on other sites More sharing options...
MmmVomit Posted October 2, 2007 Share Posted October 2, 2007 Okay, I did some fiddling around. Save this as test.php, and play around with it. See if it answers your questions. <html> <head> <title> This is a test page </title> </head> <body> <form action="test.php" method="GET"> One: <input type="checkbox" name="one" checked value="j0" /> Two: <input type="checkbox" name="two" value="foo" /> <input type="submit" name="submit" value="submit" /> </form> <pre> <?php print_r($_GET); ?> </pre> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/71519-solved-nub-q/#findComment-360116 Share on other sites More sharing options...
hungryOrb Posted October 2, 2007 Author Share Posted October 2, 2007 Yes.. the only static value to put in the 'started form' (which is the current problem) is CHECKED. I'm just not sure how to store it.. and yeh Quote Link to comment https://forums.phpfreaks.com/topic/71519-solved-nub-q/#findComment-360117 Share on other sites More sharing options...
MmmVomit Posted October 2, 2007 Share Posted October 2, 2007 Did you play around with test.php? Did it answer any of your questions? Quote Link to comment https://forums.phpfreaks.com/topic/71519-solved-nub-q/#findComment-360118 Share on other sites More sharing options...
MmmVomit Posted October 2, 2007 Share Posted October 2, 2007 Try this. Started: <input type="checkbox" name="started" value="started" <?= $queryrow['Started'] ? 'checked' : '' ?> /> <br> Finished: <input type="checkbox" name="finished" value="finished" <?= $queryrow['Finished'] ? 'checked' : '' ?> /> <br> Complete: <input type="checkbox" name="complete" value="complete" <?= $queryrow['Complete'] ? 'checked' : '' ?> /> <br> Hold: <input type="checkbox" name="hold" value="hold" <?= $queryrow['Hold'] ? 'checked' : '' ?> /> <br> Quote Link to comment https://forums.phpfreaks.com/topic/71519-solved-nub-q/#findComment-360123 Share on other sites More sharing options...
hungryOrb Posted October 2, 2007 Author Share Posted October 2, 2007 Hmm, thanks for having a crack at it ;] ----- The print function is printing Array and a '(' and a ')' on new lines, which is more than mine is printing ;] ... Still don't understand the values that are being printed Quote Link to comment https://forums.phpfreaks.com/topic/71519-solved-nub-q/#findComment-360127 Share on other sites More sharing options...
hungryOrb Posted October 2, 2007 Author Share Posted October 2, 2007 Try this. Started: <input type="checkbox" name="started" value="started" <?= $queryrow['Started'] ? 'checked' : '' ?> /> <br> Finished: <input type="checkbox" name="finished" value="finished" <?= $queryrow['Finished'] ? 'checked' : '' ?> /> <br> Complete: <input type="checkbox" name="complete" value="complete" <?= $queryrow['Complete'] ? 'checked' : '' ?> /> <br> Hold: <input type="checkbox" name="hold" value="hold" <?= $queryrow['Hold'] ? 'checked' : '' ?> /> <br> Thanks for this, I think this will work for showing the stored value, although can't check because can't track the value to put into the database. Arg, You'd think the form would send the value as a 1 or 0... Quote Link to comment https://forums.phpfreaks.com/topic/71519-solved-nub-q/#findComment-360141 Share on other sites More sharing options...
MmmVomit Posted October 2, 2007 Share Posted October 2, 2007 What version of PHP are you using? Quote Link to comment https://forums.phpfreaks.com/topic/71519-solved-nub-q/#findComment-360142 Share on other sites More sharing options...
hungryOrb Posted October 2, 2007 Author Share Posted October 2, 2007 Version 5.0.5 Quote Link to comment https://forums.phpfreaks.com/topic/71519-solved-nub-q/#findComment-360146 Share on other sites More sharing options...
MmmVomit Posted October 2, 2007 Share Posted October 2, 2007 That's very odd. Try adding a name to your submit input. Quote Link to comment https://forums.phpfreaks.com/topic/71519-solved-nub-q/#findComment-360151 Share on other sites More sharing options...
hungryOrb Posted October 2, 2007 Author Share Posted October 2, 2007 Do you mean it is odd that the values are not printing? Please could you also add why you think adding a name to the submit input is a good idea? Is it so that an additional reference could be used? It is definetly the case that not any of the values inputted are stored in the database.. haha ;] Thanks for your time though ^^ Much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/71519-solved-nub-q/#findComment-360155 Share on other sites More sharing options...
hungryOrb Posted October 2, 2007 Author Share Posted October 2, 2007 MmmVomit, thanks for your time, I'm going to be away a while, so cannot reply. If I don't speak to you again, I hope all your positive ventures go great ;] Quote Link to comment https://forums.phpfreaks.com/topic/71519-solved-nub-q/#findComment-360161 Share on other sites More sharing options...
MmmVomit Posted October 2, 2007 Share Posted October 2, 2007 Yes, it's odd that nothing is printing. I thought it was possible that it could have been a version problem, and you were using $POST instead of $_HTTP_POST_VARS, but that wouldn't be an issue in PHP 5. Here's what generally happens when submitting data from a form. You've got several inputs in a form. <input type="sometype" name="input_name" value="input_value"> When these are submitted, they should populate either the $_GET array or $_POST array depending on the method attribute in the form tag. The name attribute will be the index in the array, and the value attribute will be the value stored in that index. Even an submit button should do this. If not even the value of the submit button is being passed, then there's probably something wrong with PHP, and not your code. Also, on the page that is supposed to be receiving the data, print out both th $_GET array and the $_POST array. I have to admit, I'm kind of grasping at straws here. Something to remember, if you have this input <input type="checkbox" name="foo" value="bar"> If the checkbox is not checked, the form will not pass a "foo" element at all. If the check box is checked, an element "foo" will be passed with the value "bar". Quote Link to comment https://forums.phpfreaks.com/topic/71519-solved-nub-q/#findComment-360165 Share on other sites More sharing options...
hungryOrb Posted October 4, 2007 Author Share Posted October 4, 2007 Aha, thankyou ;] This has helped a lot! Quote Link to comment https://forums.phpfreaks.com/topic/71519-solved-nub-q/#findComment-361678 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.