Jump to content

help with check box


bamfon

Recommended Posts

i i need some help with adding check box to my form

 

right now the form is like this

 

<?php
include "auth.php";
?><html>
<head>
<title>Add page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.maintable {
background: #EEEEEE;
color: Black;
background-position: center;
font: 11px;
vertical-align: middle;
}
</style>
<?php include("editor.php");?>
<link href="style.css" rel="stylesheet" type="text/css">
</head>

<body>
<?php
/**
* Sent - add news
*/
if(isset($_POST['submit'])) { 
$title = $_POST['title'];
$keywords = $_POST['keywords'];
$text = $_POST['text'];
$status = 1;

database_connect();			
$insert = "INSERT INTO
		content (title, text, keywords, status) 
		VALUES ('$title', '$text', '$keywords', $status)";
mysql_query($insert) or die(mysql_error()); 
} else {
?>
<form method="post" enctype="multipart/form-data" id="Compose" name="Compose">
<p>title <input name="title" type="text" class="input" id="title" size="35" maxlength="100"></p>
<p>meta description <input type="text" name="keywords" id="keywords" size="53"></p>
<textarea cols="40" rows="20" name="text"></textarea>
<input name="submit" type="submit" value="submit" onClick="SetVals()">
  </form>
<?php } ?>
    
</body>
</html>

 

 

how would i go about adding in check box

 

<input type="checkbox" />
      Adventure</li>
    <li>
      <input type="checkbox" />
      Bishounen</li>
    <li>
      <input type="checkbox" />
      Comed</li>
    <li>
      <input type="checkbox" />
      Demons

where would i go from here?

 

 

i have never added check box to a site before,

 

 

i  want it to do let say they click on

"Demons" and "Bishounen" it save that in the database  long with the title and other stuff it saves    pls help

Link to comment
https://forums.phpfreaks.com/topic/195240-help-with-check-box/
Share on other sites

<input type="checkbox" name="box[]" value="A" />

<input type="checkbox" name="box[]" value="B" />

<input type="checkbox" name="box[]" value="C" />

$box=$_POST['box'];

 

The values of any checked boxs would be within the array $box

 

 

HTH

Teamatomic

Link to comment
https://forums.phpfreaks.com/topic/195240-help-with-check-box/#findComment-1026099
Share on other sites

ok done that his the update code

 

<?php
require "auth.php";
require "./dbfunctions.php";
$errormessage = NULL;
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Modify Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style.css" rel="stylesheet" type="text/css">

<?php include("editor.php");?>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->
</script>
</head>

<body>
<span class="title1">Modify Page</span> <br>
<?php
if(!isset($_GET['id'])) {
	echo "wrong parameters";
	exit;
}

if (isset($_POST['submit']))
{
	database_connect();
	//--- TESTen
	$id = $_GET['id'];
	$title = valid($_POST['title']);
	$menutitle = valid($_POST['menutitle']);
	$keywords = valid($_POST['keywords']);
	$description = valid($_POST['description']);
	$text = valid($_POST['text']);
	$apic = valid($_POST['apic']);
        $type = $_POST['type'];
	//begin image uploaden

	if($title=="") $errormessage .= "Please fill in a title.<br>";

	if($errormessage) echo "<br>" . $errormessage . "<br><input name=\"back\" type=\"button\" value=\"< Back\" onClick=\"history.go(-1)\">";
	else {
				$sql = "UPDATE content
						SET title='$title',menutitle='$menutitle', keywords='$keywords', description='$description', text='$text', apic='$apic', type='$type'
						WHERE id='$id'"; 

				}
		$query = mysql_query($sql)or die("There's a problem with the query: ". mysql_error()); 	
		if($query) echo "<br>The page is succesfully edit.<br><br>\n<a href=\"item_list.php\" target=\"links\"><img src=\"../img/ico_overview.gif\" width=\"19\" height=\"19\" border=\"0\" alt=\"Pages\"></a> <a href=\"item_detail.php?id=$id\"><img src=\"../img/ico_detail.gif\" width=\"19\" height=\"19\" border=\"0\" alt=\"More info\"></a> <a href=\"item_modify.php?id=$id\"><img src=\"../img/ico_edit.gif\" width=\"19\" height=\"19\" border=\"0\" alt=\"Edit\"></a>";
        	
} 
else 
{	
	database_connect();		
	if(isset($_GET['id'])) {
		$id = ($_GET['id']);
	}
	$select = "SELECT *
				FROM content
				where id = '$id'";
	$query = 		mysql_query($select);
	$nieuws = 		mysql_fetch_object($query);
	$deid = 		$nieuws->id;
	$menutitle =    $nieuws->menutitle;
	$title = 		$nieuws->title;
	$keywords =     $nieuws->keywords;
	$description =  $nieuws->description;
	$text = 		$nieuws->text;
	$apic = 		$nieuws->apic;
	$type = 		$nieuws->type;

?>
<form action="" method="post" enctype="multipart/form-data" id="Compose" name="Compose"> 
<p>title <input name="title" type="text" value="<?php echo $title; ?>" size="50" maxlength="75"></p>
<p>menu title 
  <input name="menutitle" type="text" value="<?php echo $menutitle; ?>" size="25" maxlength="50"> 
  (Name it the same thing as the title)</p>
<p>meta keywords <input type="text" name="keywords" id="keywords" value="<?php echo $keywords; ?>" size="53"> 
  (name it the anime name and eps number as well as other words)</p>
<p>meta description <input type="text" name="description" id="description" value="<?php echo $description; ?>" size="75">
  (put a </p>
<p>Type
  ------ 
  
  <input name="type[]" type="checkbox"  value="Movie" />
  Movie
<input name="type[]" type="checkbox"  value="ONA" />
ONA
<input name="type[]" type="checkbox"  value="OVA" />
OVA  (Movie, 	ONA, 	OVA, 	Short,
  TV,	TV Special)</p>
<p>Year
  <input type="text" name="apic3" id="apic3" value="<?php echo $apic; ?>" size="75"> 
  (What year was the anime released  in)</p>
<p>Genre
  <input type="text" name="apic4" id="apic4" value="<?php echo $apic; ?>" size="75">
</p>
<p>anime pictures 
  <input type="text" name="apic" id="apic" value="<?php echo $apic; ?>" size="75">
</p>
<h2>Summary</h2>
<textarea cols="40" rows="20" name="text"><?php echo $text; ?></textarea></td>
<input name="submit" type="submit" value="submit" onClick="SetVals()">
</form>
<?php } ?>						               
</body>
</html>

 

 

now when i pressed submit the only thing it saves form the check box is "Array"

 

 

 	id 	title 	menutitle 	startpage 	last_updated 	posting_time 	type 	text 	apic 	description 	keywords 	position 	status
Edit 	Delete 	1 	The Fruit Stand - Your source for Fruit! 	Fruit Stand Home 	1 	2010-03-15 01:14:40 	2010-01-19 00:30:51 	Array 	<h3>This is the home page. Here you find lots of i... 	gfdgdgdfgdgdgdfgdfdgdgf 	Come to appleton and find all your fruit needs in ... 	fruit,apples,grapes 	0 	1

Link to comment
https://forums.phpfreaks.com/topic/195240-help-with-check-box/#findComment-1026111
Share on other sites

probably because: echo $array will output array, as you see. If you want the output of an array you need to loop through it.

foreach($array as $item)

or

foreach($array as $key => $value)

 

Are you wanting more than one check box to be checked? if so you will need to loop through. If you only want one to be selected then use radio buttons as a group(all with the same name). If you use radio buttons only one will work, when another from the group is pushed the selected one will unselected. The when you name the radio's just use name=type without any square brackets.

 

 

HTH

Teamatomic

Link to comment
https://forums.phpfreaks.com/topic/195240-help-with-check-box/#findComment-1026143
Share on other sites

Archived

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

×
×
  • 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.