Display the names of selected checkboxes and the values [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I am trying to display the name of all the selected check boxes and their values. At the moment it shows the values of all the selected check boxes but not the name of the selected check box. How would I do this?
The sections of code are below. The HTML form section has 9 identical checkboxes apart from the name and value.
<?php
echo $_POST['jan'];
echo $_POST['feb'];
echo $_POST['mar'];
echo $_POST['apr'];
echo $_POST['may'];
echo $_POST['jun'];
echo $_POST['jul'];
echo $_POST['aug'];
echo $_POST['sep'];
?>
<div class="checkbox">
<label>$15 :
<input name="jan" value="15" type="checkbox"> January
</label>
</div>
Any help would be great.

Checkbox parameters are only set if the box is checked. So test whether it's set:
if (isset($_POST['jan'])) {
echo 'jan: ' . $_POST['jan'];
}
You can put this into a loop:
$months = array('jan', 'feb', ...);
foreach ($months as $m) {
if (isset($_POST[$m])) {
echo $m . ': ' . $_POST[$m];
}
}

Related

How to print all even numbers between two input values typed by user. please write code hint only in php [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 3 years ago.
Improve this question
How to print all even numbers between two input values typed by user. please write code hint only in php.
I can give you a hint. Lookup the modulo operator. With it you can do something like this:
<?php
if (($number % 2) === 1)
{
echo "$number is odd.";
}
if (($number % 2) === 0)
{
echo "$number is even." ;
}
?>
Also. Have a look at how you ask questions on stack overflow. Or they will prevent you from asking questions in the future if you don't adhere to those rules.
use this code, for user input i have created a form.
<html>
<body>
<form method="post">
<input type="number" name="num1">
<input type="number" name="num2">
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
<?php
if(isset($_POST['submit'])){
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
// while loop that will print number
while($num1 <= $num2){
// here is the condition to check the EVEN number
if($num1%2!==0){
echo $num1."<br>";
}
// increasing the loope counter by 1
$num1++;
}
}
?>
i hope now your problem has been solved..

How to convert data from database into a link? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have a list of courses that looks like this:
course
SE1111
SE2222
SE3333
I need to show it in my page and then it should redirect to a page saving the value (name of course) for future purposes.
This is what I have done so far:
<div id="join_courses" class="">
<form action="" method="post">
<label>Join a course:<br></label>
<input placeholder="select a course" list="courses" name="courses">
<datalist id="courses">
<option value="
<?php
include('student_register.php');//include php code that gets the tables (courses)
while($table = mysqli_fetch_array($result)) {
echo $student_courses[0];
}
?>
This gives me the input list form but it is showing me all the "courses" in one same field. (NOT IN A LIST).
any suggestions on how to approach this?
try with a proper anchor something like this
while($table = mysqli_fetch_array($result)) {
echo '<a href="yourPath/'. $student_courses[0] . '">' .
$student_courses[0] . '</a>';
}

HTML and PHP webdesign and formating [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I nedd some help formating HTML for my website. I have created a html page for my contact form. Then a php page that corrects errors in my page. then I also created another php page that thanks the person for submitting a contact form. After they submit the contact form I want them php to do the following:
On the form processing page:
say thank you
Echo back the users first and last name.
Show today's date
Echo back the visitor's age in years
If the visitor is older than 55 indicate that they are entitled
to a senior citizen discount
If the visitor is 30-54 years old indicate that they are
entitled to a middle aged citizen discount
If the visitor is younger than 17 indicate that they are entitle to a
youth discount
<?php echo "thanks for contacting us";?>
See..for you above provided code you can do this in PHP and HTML by..
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
//assuming you used this for age and have the rest form
<input type="number" min="0" max="100" name="age">
</form>
<?php
$age = $_POST['age'];
echo date("m.d.y");
echo "Your age is :".$age. ", you are entitled to";
if($age > 55){
echo 'Discount';
}
else if($age > 30 && $age < 55){
echo 'Discount';
}
else if($age < 17){
echo 'discount';
}
?>
It is a simple if-else conditon.
$_POST gets you the value from the form using name tag..I fyou want to generate any HTML tag in PHP just put it inside echo.Like this
echo "<p class="text" id="new1">Sample para tag<p>";
In the similar way you can generate nay html tag in php by just enclosing in echo ' ';

PHP implode function in if and foreach condition [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
This is my HTML Code
<input type="checkbox" value="fotoğraf" name="materyal[]"> Fotoğraf
<input type="checkbox" value="resim" name="materyal[]">Resim
<input type="checkbox" value="çizelge" name="materyal[]">Çizelge
<input type="checkbox" value="katlanabilir harita" name="materyal[]"> Katlanabilir Harita
There are checkbox and i'll take values with $_POST['materyal'] and then i want to write screen values with comma if values more than one. if checkbox values empty i don't write anything screen.
if (isset($_POST['materyal']) && !empty($_POST['materyal'])) {
$materyal = $_POST['materyal'];
echo "İçerdiği extra materyaller ; ";
foreach ($materyal as $materyallist) {
foreach ($materyallist as $yenimateryal){
array_push($sonmateryal, $yenimateryal);
}
}
echo implode(", ", $sonmateryal);
}
This is my code. when i want to use implode in if contiditon, I take mistake.
How can i do
It seems like you just want to show the contents?
$sonmateryal = array();
if (isset($_POST['materyal']) && !empty($_POST['materyal'])) {
echo "İçerdiği extra materyaller ; ";
foreach ($_POST['materyal'] as $materyallist) {
foreach ($materyallist as $yenimateryal) {
$sonmateryal[] = $yenimateryal;
}
}
}
echo implode(", ", $sonmateryal);
update according to given HTML
if (!empty($_POST['materyal'])) {
echo "İçerdiği extra materyaller ; ".htmlentities(implode(',', $_POST['materyal']));
}
Since you're posting the inputs as simple array's this will implode the results with a comma if the post-ed value isn't empty..

Dropdown variable script [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have the following code:
echo "<td><textarea wrap='soft' class=tarea3 name='inston[]'>".$r['inston']."</textarea></td>\n";
I'd like to use that inston variable to associate with a dropdown list. I have working code for the dropdown list:
<tr><td class="tdt">
<?php te('Hosting Server');?>:</td> <td title='Select server'>
<select validate='required:true' class='mandatory' name='manufacturerid'>
<option value=''>Select</option>
<?php
foreach ($agents5 as $a) {
$dbid=$a['id'];
$atype=$a['label']; $s="";
if (isset($manufacturerid) && $manufacturerid==$a['id']) $s=" SELECTED ";
echo "<option $s value='$dbid' title='$dbid'>$atype</option>\n";
}
echo "</select>\n";
?>
</td></tr>
and a sql query for the above mentioned dropdown script,
$sql="SELECT * FROM items where itemtypeid=32 OR itemtypeid=44 order by label";
$sth=db_execute($dbh,$sql);
while ($r=$sth->fetch(PDO::FETCH_ASSOC)) $agents5[$r['id']]=$r;
How can we use the code above to associate inston variable?
Your question isn't clear and from what i understood, is suppose the answer to be this
First of all , use an id for the select tag and textarea and use an onChange function like this:
<textarea wrap='soft' class=tarea3 name='inston[]' id='inston'>".$r['inston']."</textarea>
<select validate='required:true' class='mandatory' name='manufacturerid' id='manufacturerid' onChange='setInston()'>
and the use this javascript function :
function setInston() {
var x = document.getElementById("manufacturerid").value;
document.getElementById("inston").innerHTML= x+"
";
}

Categories