Jump to content

Form checkbox status and changing


chrisgunton

Recommended Posts

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!
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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
Link to comment
Share on other sites

[!--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.
Link to comment
Share on other sites

I see you point well in order to do it corectly do this here

I 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 query

Ray
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.