473,396 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

checkboxes help needed

Hi I just started to try and learn PHP, so sorry if this is a simple thing to do.

I have been try to use checkboxes on a website that I am making, but the only problem is that for the life of me i can't seem to check which onces have been checked. Also to make things more difficult for what I am doing i don't actually know how many checkboxes that there will be until run time. So any help would be nice.
Mar 13 '07 #1
6 1503
ronverdonk
4,258 Expert 4TB
How can you expect to help out when we cannot see anything of what you have done so far?

So post the code you have made sofar and we will look at it. When you post coe, show it within [php] tags! See the Posting Guidelines for the rules on posting code.

Ronald :cool:
Mar 13 '07 #2
here is the code for what i have so far. I have tried a few things so there is code at the top that is just there to see if different things would work. Every thing else work so far, all that is stopping me from finishing this part is those checkboexes.


[PHP]

<?php
session_start();
?>
<html>
<body>
<?php
include("menu.php");


if ((($_POST["name"]=="aaron")&&($_POST["pass"]=="hi"))||($_SESSION['name2']=="scary"))
{
$count=($_SESSION['result2']);
$comdel=$POST["del[]"];
echo $comdel[1];
//echo $count;
for($s=0;$s<$count;$s++)
{
echo " Hi";
echo $comdel[$s];
echo $_POST["del[$s]"];
if (($_POST["del".$s])=="hi")
{
echo "Delete";
}
}

$hi=$_POST['del'];
foreach ($del as $statename)
{
echo "$statename is checked";
}


foreach(($_POST['del[]']) as $myKey)
{
echo " Hi2";
echo $myKey."<br />";
}

echo "The latest comments :<br />";
$comen=(scandir("comments",1));
$result = count($comen);
$result=$result-2;
$_SESSION['result2']=($result);

echo "<table border='1'>";
echo "<form action='comments.php' method='post'>";

$del=array_fill(0,$result,"");

for ($i=0; $i<($result); $i++)
{
echo "<tr align='left'><th>";
echo "Delete<input type='checkbox' name='del[]' value='hi'.$i />";
echo "</th><th>";

if(file_exists("comments/$comen[$i]"))
{
$file = fopen("comments/$comen[$i]", "r+");
//Output a line of the file until the end is reached
while(!feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);
}
else
{
echo ("There are no new comments");
}

echo "</th></tr>";

}
//echo "</table>";
echo "<input type='submit' value='Delete' />";
echo "</form>";
}
else
{
echo "incorrect username or password ";
echo "<a href='/scary_little_ryn/Info/index.php'>Return to login</a>";
}
?>

</body>
</html>

[/PHP]

hope that helps
Mar 14 '07 #3
Atli
5,058 Expert 4TB
Hi.

I have a simple example for you that I hope can help you.

The code prints out check-boxes using an array I created, and then checks if any of the boxes have been posted.

[PHP]
<?php
// Create an array with each box's index and label
$boxes = array(
array(1, "Box 1"),
array(2, "Box 2"),
array(3, "Box 3"),
array(4, "Box 4"),
array(5, "Box 5")
);

// Create the form
echo '<form action="#" method="post">';
foreach($boxes as $box)
{
echo '<input type="checkbox" name="cb-'. $box[0] .'" value="'. $box[0] .'" /> '. $box[1] ."<br />";
}
echo '<br /><input type="submit" name="submit" value="Submit" />
</form>';

// Check each value to see if it has been posted
if(isset($_POST['submit']))
{
// Print the header
echo "<p>Selected boxes:<br />";

foreach($boxes as $box)
{
// Check if the box has been posted
if(isset($_POST["cb-". $box[0]]))
{
echo " - ". $box[1] ."<br />";
}
}
}
?>
[/PHP]
Mar 14 '07 #4
Just a question quick question is it possible for the following part to be done using a loop? So that it can be as big or as small as the situation required.

[php]
$boxes = array(
array(1, "Box 1"),
array(2, "Box 2"),
array(3, "Box 3"),
array(4, "Box 4"),
array(5, "Box 5")
);
[/php]
Mar 14 '07 #5
Atli
5,058 Expert 4TB
Sure.

You can create the array any way you like.

You could do this, for example:
[PHP]
$boxes = array();
for($x = 0; $x < 10; $x++)
{
$boxes[] = array($x, "Box ". $x);
}
[/PHP]
Mar 14 '07 #6
Thank you very much that worked like a charm
Mar 15 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Ralph Freshour | last post by:
I have multiple checkbox's created with an array name because I have many on the same web page - their names are like: frm_chk_delete frm_chk_delete frm_chk_delete frm_chk_delete etc. Here...
9
by: Gary | last post by:
Hello, Is it possible to dynamically update a textbox with words chosen from a list using form checkboxes and javascript? Gary
5
by: Bob Bedford | last post by:
I create checkboxes using datas from a database (with PHP). I store all values in an array, as I must pass this value like a Form value. Now, in some cases, when a checkbox is selected, I must...
1
by: Patrick | last post by:
Hello - I am designing a form that only allows 2 checkboxes to be checked out of a series of checkboxes. However, checkedchanged and checkstatechanged both act when the box is clicked on. I want...
3
by: payne747 | last post by:
Hi everyone, Can anyone help me with the following code, for some reason I can't understand if I'm being thick of if javascript is so backwards! HTML defines some checkboxes such as: <form...
5
by: ameshkin | last post by:
What I want to do is very simple, but I'm pretty new at PHP and its a little hard for me. I have one page, where there are a rows of checkboxes. A button selects all checkboxes, and then...
1
by: l1k3kah | last post by:
How to update mydatabase when the data needed is in checkboxes and the value to be saved is either true/false-yes/no? How can I get the records which needed to be updated...with the use of...
1
by: zufie | last post by:
I have a main form containing 2 checkboxes. The respective checkboxes when checked cause the SepcialEffect Property to make all the textboxes to appear Shadowed. 1)Although the Textboxes and...
3
by: goldybobble | last post by:
Hello, I had an Access database that would classify items with one classification, and then classify one sub-classification based on the selection for the main classification. This worked well,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.