genista Posted August 21, 2006 Share Posted August 21, 2006 Hi,I have checkboxes which I need a user to be able to update, the issue is that when you load the page the checkboxes are not echoing the results from the database. I have the following code which is the html:[code=php:0]<p>Beautician:</td><td><input type="checkbox" name="beautician" value="<?php if($test1 == "on"){echo" CHECKED";}?></p>[/code]The value that checks for 'on' is actually in the page that receives the result from the above code:if (isset($_POST['test1']) == "on") $test1 = "true"; // I don't know what $test1 is supposed to be, change as needed. else $test1= "null";[/code]So the question is how can I echo these results?Thanks,G Quote Link to comment https://forums.phpfreaks.com/topic/18181-checkbox-echo-issue/ Share on other sites More sharing options...
HuggieBear Posted August 21, 2006 Share Posted August 21, 2006 For a start there's no closing tag on the <Input> tag...Try this:[code]<p>Beautician:</td><td><input type="checkbox" name="beautician" value="<?php if($test1 == "on"){echo" CHECKED";}?>"></p>[/code]Also although you've only posted a snippet of your code here, it looks as though your HTML tags are nested incorrectly. The first tag in a paragraph tag should not be a closing table tag as in your example "<p></td>".Maybe try this:[code]<p> Beautician: <td> <input type="checkbox" name="beautician" value="<?php if($test1 == "on"){echo" CHECKED";}?>"> </td></p>[/code]RegardsRich Quote Link to comment https://forums.phpfreaks.com/topic/18181-checkbox-echo-issue/#findComment-77971 Share on other sites More sharing options...
genista Posted August 21, 2006 Author Share Posted August 21, 2006 Thanks, yes I have only posted a snippet of the html. I have edited it though with your suggestion, but still nothing. Should I move:[code=php:0]if (isset($_POST['test1']) == "on") $test1 = "true"; // I don't know what $test1 is supposed to be, change as needed. else $test1= "null";[/code]from the results page to the page that contains the html? But then when you submit the page it runs the above routine anyway, oh I am confused now.. Quote Link to comment https://forums.phpfreaks.com/topic/18181-checkbox-echo-issue/#findComment-77973 Share on other sites More sharing options...
HuggieBear Posted August 21, 2006 Share Posted August 21, 2006 I'm assuming this code was taken from somewhere else.Are you able to post the full code of the two pages so I can get a better look?Rich Quote Link to comment https://forums.phpfreaks.com/topic/18181-checkbox-echo-issue/#findComment-77975 Share on other sites More sharing options...
ToonMariner Posted August 21, 2006 Share Posted August 21, 2006 ok have a look at your source... Is CHECKED being echoed out?If not then there is something amiss in the code if it IS then...swap echo " CHECKED" for echo " checked=\"checked\"";and DO make sure the input tag is closed Quote Link to comment https://forums.phpfreaks.com/topic/18181-checkbox-echo-issue/#findComment-77976 Share on other sites More sharing options...
HuggieBear Posted August 21, 2006 Share Posted August 21, 2006 [quote author=ToonMariner link=topic=105042.msg419336#msg419336 date=1156157482]swap echo " CHECKED" for echo " checked=\"checked\"";[/quote]I can see what genista's done here. HTML will allow an input type of 'checkbox' to be checked with just CHECKED in the tag, it doesn't require a descriptor of checked="checked" but it certainly would help here.Rich Quote Link to comment https://forums.phpfreaks.com/topic/18181-checkbox-echo-issue/#findComment-77979 Share on other sites More sharing options...
ToonMariner Posted August 21, 2006 Share Posted August 21, 2006 Yeah I know but I just like standards - if the doctype is strict then I think just CHECKED will fail! Quote Link to comment https://forums.phpfreaks.com/topic/18181-checkbox-echo-issue/#findComment-77986 Share on other sites More sharing options...
HuggieBear Posted August 21, 2006 Share Posted August 21, 2006 [quote]Yeah I know but I just like standards[/quote]Someone after my own heart 8) Quote Link to comment https://forums.phpfreaks.com/topic/18181-checkbox-echo-issue/#findComment-77987 Share on other sites More sharing options...
ToonMariner Posted August 21, 2006 Share Posted August 21, 2006 hugss n kisses ;) Quote Link to comment https://forums.phpfreaks.com/topic/18181-checkbox-echo-issue/#findComment-77995 Share on other sites More sharing options...
genista Posted August 21, 2006 Author Share Posted August 21, 2006 Ok I have done that but still nothing, here are the two pages:updatedetails.php[code=php:0]$id = $_SESSION['username'];$query = "select * from suppliers where username='$id'"; //now we pass the query to the database $result=mysql_query($query, $link) or die("MySQL query $query failed. Error if any: ".mysql_error()); //get the first (and only) row from the result $row = mysql_fetch_array($result, MYSQL_ASSOC); $username=$row['username']; $password=$row['password']; $first_name=$row['first_name'];$test1=$row['test1']; html part:<p>test1:</td><td><input type="checkbox" name="test1" value="<?php if($test1 == "on"){" checked=\"checked\"";}?>[/code]Then we have the results page:[code=php:0]$first_name=$_POST['first_name']; $last_name=$_POST['last_name']; if (isset($_POST['test1']) == "on") $test1 = "true"; else $test1 = "null"; $query = "UPDATE suppliers SET first_name='$first_name', etc etc.[/code]Hugs and kisses to all of you if you can help with this! Quote Link to comment https://forums.phpfreaks.com/topic/18181-checkbox-echo-issue/#findComment-78001 Share on other sites More sharing options...
ToonMariner Posted August 21, 2006 Share Posted August 21, 2006 You STILL hav not closed the checkbox tag!!!!!!!!!!!<input type="checkbox" name="test1" value="<?php if($test1 == "on"){" checked="checked\"";}?> [color=red]/>[/color] Quote Link to comment https://forums.phpfreaks.com/topic/18181-checkbox-echo-issue/#findComment-78022 Share on other sites More sharing options...
genista Posted August 21, 2006 Author Share Posted August 21, 2006 Ah sorry about that didn't post that, but have done it and no its still not working. Is it something to do with?:[code=php:0]if (isset($_POST['test1']) == "on") $test1 = "true"; else $test1 = "null";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/18181-checkbox-echo-issue/#findComment-78023 Share on other sites More sharing options...
ToonMariner Posted August 21, 2006 Share Posted August 21, 2006 run your script - have a look at the html source and see if it does echo checked.....in fact run your script and post the html source on here... Quote Link to comment https://forums.phpfreaks.com/topic/18181-checkbox-echo-issue/#findComment-78026 Share on other sites More sharing options...
genista Posted August 21, 2006 Author Share Posted August 21, 2006 Ok so the php code looks like so:[code=php:0]<p>test1:</td><td><input type="checkbox" name="test1" value="<?php if($test1 == "on"){"checked=\"checked\"";}?>/></p>[/code]and this is what we get from the html source: [code=php:0]<p>test1:</td><td><input type="checkbox" name="test1" value="/></p>[/code]Doesn't say 'checked' thats for sure... Quote Link to comment https://forums.phpfreaks.com/topic/18181-checkbox-echo-issue/#findComment-78032 Share on other sites More sharing options...
ToonMariner Posted August 21, 2006 Share Posted August 21, 2006 didn't see it before....value is an attribute that is not going to chnage so each check box should have a value set. What you want is.....<input type="checkbox" name="test1" value="1"<?php if($test1 == "on"){echo "checked="checked\"";}?> /><input type="checkbox" name="test2" value="2"<?php if($test2 == "on"){echo " checked=\"checked\"";}?> /> Quote Link to comment https://forums.phpfreaks.com/topic/18181-checkbox-echo-issue/#findComment-78041 Share on other sites More sharing options...
HuggieBear Posted August 21, 2006 Share Posted August 21, 2006 I can't understand why you're even using 'on'. You're converting it for insert into the database anyway, so you may as well just use '[color=red]true[/color]' as the valueYou'd be better off with this surely:[code][code=php:0]<input type="checkbox" name="test1" value="true" <?php if($test1 == "true"){echo "checked=\"checked\"";}?> />[/code][/code]And then change your code on the results page to:[code]$first_name=$_POST['first_name'];$last_name=$_POST['last_name']; if (isset($_POST['test1']) != "true"){ $test1 = "null";}[/code]RegardsRich Quote Link to comment https://forums.phpfreaks.com/topic/18181-checkbox-echo-issue/#findComment-78059 Share on other sites More sharing options...
genista Posted August 21, 2006 Author Share Posted August 21, 2006 And we are there! Great thanks everybody! Quote Link to comment https://forums.phpfreaks.com/topic/18181-checkbox-echo-issue/#findComment-78109 Share on other sites More sharing options...
HuggieBear Posted August 21, 2006 Share Posted August 21, 2006 [quote]And we are there! Great thanks everybody![/quote]Glad to have been of some help.RegardsRich Quote Link to comment https://forums.phpfreaks.com/topic/18181-checkbox-echo-issue/#findComment-78112 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.