Jump to content

Archived

This topic is now archived and is closed to further replies.

chrisgunton

Form checkbox status and changing

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!

Share this post


Link to post
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]

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.