Jump to content

[SOLVED] checking my checkbox


runnerjp

Recommended Posts

you are not getting it from the form,

 

is your form using post or get?

anway you will need this:

 


$check = '';
$forumlock = $_GET['forumlock']; // use this line if it is get
$forumlock = $_POST['forumlock']; // use this line if it is post
   if($forumlock==1) {
      $check = "CHECKED";
   }

<input type='checkbox' name='forumlock' />

 

i believe thats what you are after,

 

oh and to answer paulman8888888's question about the forum, building a forum is a good exercise to get better at your php skills as it involves alot of different techniques, i know i did it myself purly because i could.

 

Link to comment
Share on other sites

hey blueman... ur correct i want it to

 

A. be able to teach my php more as im still poor lol and its helping alot

and

B. make the froum how I want it :)

 

 

ok what you said above wont work as it needs to collect the value from my db...

 

<?php
$forumlock=0;// default value if it's not set
if (isset($_POST['edit'])) {
if(isset($_POST['forumlock'])){
	$forumlock=1;
}else{
	$forumlock=0;
}
$title = $_POST['title'];
$query = "UPDATE forumtutorial_posts SET forumlock = '$forumlock', title = '$title' WHERE postid='$getthreads3[postid]' ";
mysql_query($query) or die('Error, query failed');
echo "Your title is ". $title . "<br />";
}else{
$check = '';
if($forumlock==1) {
	$check = "CHECKED";
}

?>

<h4> </h4>
<form name='input' action='index.php?page=forum&forum=<?php echo $forum ?>' method='post'>

Title:
  <input class='input' name='title' type='text' value='<?php echo $getthreads3[title];?>' />
  <br/>
  <input type='checkbox' name='forumlock' $check> Lock a Room<br/>
<input type='submit' name='edit' value='edit'/>
</form>
    
  <?
}
?>

Link to comment
Share on other sites

And remember single or double quotes around strings. You forgot that in your query and further down: $getthreads3[postid] should be $getthreads3['postid']. And of course, the single quotes will break your syntax if you're not rearranging things a bit (in the query).

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.