chrisgunton Posted April 11, 2006 Share Posted April 11, 2006 Hi,Ive only been working with PHP since the weekend, and so far im pretty happy with myself. Ive built a rough CMS using PHP and MySQL for a University project. It can add, edit and delete pages, as well as set "Published" or "Draft" status for each page.This is where the problem lies. Im using a checkbox to set the Published status, which sets the value to 1 or 0 in the DB. The following code gets the current status of the page and displays the checkbox, ticked or not depending on the status.[code]<?if ($islive) { echo "<input type='checkbox' name='ud_islive' value='0' checked />";} else { echo "<input type='checkbox' name='ud_islive' value='1' />";}?>[/code]Problem here is that if the page is Published, when being edited, no matter what you do its set to Draft when saved. I can be set to Published again but it sure is anoying.You can try it out here. But PLEASE dont go nuts with the editing. (also note, this is 2 days work from someone who hasnt even attempted PHP before so be kind!)[a href=\"http://digimed.chrisgunton.com/admin/\" target=\"_blank\"]http://digimed.chrisgunton.com/admin/[/a]Any help with this would be greatly appreciated, as my brain is starting to ache! Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 11, 2006 Share Posted April 11, 2006 Hi,I've had a look with "The Fox" page and changed the Published tickbox to ticked and unticked and saved and when I go back into it its as I set it so I can't see what the problem is.Your "if ($islive)" will be TRUE if $islive is anything [b]but[/b] a zero or null. If its -1 or lower or 1 or higher then it'll become TRUE.Its nothing to do with the code but I noticed you're using a mix of HTML and XHTML even though you have an HTML DOCTYPE header. If you're leaning towards XHTML then the "checked" parameter should be closed by using the following:[code]checked="checked"[/code] Quote Link to comment Share on other sites More sharing options...
craygo Posted April 11, 2006 Share Posted April 11, 2006 I looked at the page and it seems fine. The problem looks like the caching of the page. When I go back and forth and keep checking published and unchecking it. When I return to the page, i get it as it was the first time i went to it. If i just click refresh it shows me the changes. So it looks like it is a caching problem and not a script problem.Ray Quote Link to comment Share on other sites More sharing options...
chrisgunton Posted April 11, 2006 Author Share Posted April 11, 2006 [!--quoteo(post=363753:date=Apr 11 2006, 07:41 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Apr 11 2006, 07:41 PM) [snapback]363753[/snapback][/div][div class=\'quotemain\'][!--quotec--]I looked at the page and it seems fine. The problem looks like the caching of the page. When I go back and forth and keep checking published and unchecking it. When I return to the page, i get it as it was the first time i went to it. If i just click refresh it shows me the changes. So it looks like it is a caching problem and not a script problem.Ray[/quote]go to the admin page i linked to, choose a Published page, dont make any changes, just click Save. go back to the CMS main screen and look at the status again. Quote Link to comment Share on other sites More sharing options...
craygo Posted April 11, 2006 Share Posted April 11, 2006 I see you point well in order to do it corectly do this hereI do not know what your sql looks like so I will wing it here. This is also done outside of the php tags[code]<input type=checkbox name="ud_islive" value"1" <? if($row['isalive'] == '1'){ print 'checked'; }>[/code]And obviousely you will have it grabbing the value on the next page. on updated.php you should have an if then there.[code]if(isset($_POST['ud_isalive'])){$isalive = 1;} else {$isalive = 0;}[/code]Than use $isalive in your update queryRay Quote Link to comment 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.