Jump to content


Photo

Form checkbox status and changing


  • Please log in to reply
4 replies to this topic

#1 chrisgunton

chrisgunton
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 11 April 2006 - 03:47 PM

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.
<?
if ($islive) {
    echo "<input type='checkbox' name='ud_islive' value='0' checked />";
} else {
    echo "<input type='checkbox' name='ud_islive' value='1' />";
}
?>

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!

#2 Yesideez

Yesideez
  • Members
  • PipPipPip
  • Advanced Member
  • 2,334 posts
  • LocationDevon, UK

Posted 11 April 2006 - 04:29 PM

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 but 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:
checked="checked"

Not a pro just an enthusiast :)

if (empty($coffee)) {$coffee=new coffee();}

Please surround any code using the CODE tags - I rarely look at anything without them

#3 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 11 April 2006 - 06:41 PM

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

#4 chrisgunton

chrisgunton
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 11 April 2006 - 06:45 PM

[!--quoteo(post=363753:date=Apr 11 2006, 07:41 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Apr 11 2006, 07:41 PM) View Post[/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.

#5 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 11 April 2006 - 07:27 PM

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

<input type=checkbox name="ud_islive" value"1" <? if($row['isalive'] == '1'){ print 'checked'; }>

And obviousely you will have it grabbing the value on the next page. on updated.php you should have an if then there.

if(isset($_POST['ud_isalive'])){
$isalive = 1;
} else {
$isalive = 0;
}

Than use $isalive in your update query

Ray




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users