Find whether checkbox is checked in php - php

This question has been asked before but i used the same thing as said in the answer to the question but it is not working
My form:
$home=
"<div class='heading' >
<p><b>EHD HOME AUTOMATION</b></p>
</div>
<div class='menu-wrap'>
<nav class='menu'>
<ul class='clearfix'>
<li><a href='./member.php'>$username's Home</a></li>
<li>
<a href='#'>States <span class='arrow'>▼</span></a>
<ul class='sub-menu'>
<li><a href='#' onclick='changeAllStatesToFalse();'>ALL APPLIANCES OFF</a></li>
<li><a href='#' onclick='changeAllStatesToTrue();'>ALL APPLIANCES ON</a></li>
<li><a href='#' onclick='getStates();'>GET STATES</a></li>
</ul>
</li>
<li><a href='#'>Security</a></li>
<li><a href='#'>Page info</a></li>
<li><a href='./logout.php'>Logout</a></li>
</ul>
</nav>
</div>
<!3 Toggle Buttons start>
<div class='buttonsArea'>
<div class='display'>
<label class='label toggle'>
Appliance 1
<input type='checkbox' class='toggle_input' id='button1' name='A1'/>
<div class='toggle-control'></div>
</label>
</div>
<div class='display'>
<label class='label toggle'>
Appliance 2
<input type='checkbox' class='toggle_input' id='button2' onclick='updateTable(2);'/>
<div class='toggle-control'></div>
</label>
</div>
<div class='display'>
<label class='label toggle'>
Appliance 3
<input type='checkbox' class='toggle_input' id='button3' onclick='updateTable(3);' />
<div class='toggle-control'></div>
</label>
</div>
</div>
<!3 Toggle Buttons end>";
if(isset($_POST['A1'])){
echo "<script type='text/javascript'>alert('A1 pressed');</script>";
}
if($username && $userid){
echo "$home";
if($errormsg)
echo "<script type='text/javascript'>alert('$errormsg');</script>";
}
The checkbox A1 is not responding to isset function. No matter set or not set nothing echo's.
Please help
See the 3 toggle button division

Related

How can I dynamically fetch data in Tabs and Pills using their IDs? Using PHP & Codeigniter

I am creating a module for Question and Answers and I need to fetch the data separatedly each.
I created a Tab where I'll click the Question I want to answers, and its children or the answer should match.
For visual reference, here is my problem
I have this data that are all fetched, which should not be. That is why I created Tabs and Pills so I can separate questions and answers
12 and 13 are the id number of each data
So in Tabs and Pills, I got this
The problem of this, is that I cannot fetch the data dynamically, it just shows ID 13 data for question and answer. How can I change this dynamically so I can click back and forth the tabs and show the right data by its id?
I need to fetch the ID 12 of the 1st Tab
So here is my view
<ul class="nav nav-tabs" role="tablist">
<?php foreach($questions as $question){ ?>
<?php echo $question->id; ?>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#<?php echo $question->id ?>" role="tab"><h4><?php echo $question->question ?></h4></a>
</li>
<?php } ?>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane" id="13" role="tabpanel">
<div class="card" style="border:2px solid black;">
<div class="card-body">
<?php foreach($this->question_model->findAnswersByQuestion($question->id) as $answer){ ?>
<?php if($answer->type_id==0): ?>
<input type="radio" name="question_<?php echo $question->id; ?>" value="<?php echo $answer->answer ?>" required/>
<?php echo $answer->answer; ?><hr>
<?php endif; ?>
<?php if($answer->type_id==1): ?>
<div class="input-group input-group-lg">
<input type="text" class="form-control col-md-6" placeholder="Enter Answer" name="question_<?php echo $question->id; ?>" required/>
</div>
<?php endif; ?>
<?php } ?>
</div>
</div><br>
</div>
</div>
Fix the tabs structure, your looping over questions for nav-item, but not looping over for tab-pane which is why clicking the tab link does nothing.
<ul class="nav nav-tabs" role="tablist">
<?php foreach($questions as $question){ ?>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#tab-<?php echo $question->id ?>" role="tab"><h4><?php echo $question->question ?></h4></a>
</li>
<?php } ?>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<?php foreach($questions as $question){ ?>
<div class="tab-pane" id="tab-<?= $question->id ?>" role="tabpanel">
<div class="card" style="border:2px solid black;">
<div class="card-body">
<?php foreach($this->question_model->findAnswersByQuestion($question->id) as $answer){ ?>
<!-- form input $answer / item -->
<?php } ?>
</div>
</div>
</div>
<?php } ?>
</div>

Value are not storing in database

When i put the value from this page its not saving my value in database. The program stopped on this link www.mywebsite.com/index.php?admin/manage_language/update_phrase/english and show a blank page. whenever i run on my local machine its run successfully. update the record and come back to again on www.mywebsite.com/index.php?admin/manage_language/edit_phrase/english on this link. But on my cpanel its not working well.
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<ul class="nav nav-tabs nav-bordered mb-3">
<?php if(isset($edit_profile)):?>
<li class="nav-item">
<a href="#edit" data-toggle="tab" aria-expanded="true" class="nav-link active">
<?php echo get_phrase('edit_phrase');?>
</a>
</li>
<?php endif;?>
<li class="nav-item">
<a href="#list" data-toggle="tab" aria-expanded="false" class="nav-link <?php if(!isset($edit_profile))echo 'active';?>">
<i class="mdi mdi-home-variant d-lg-none d-block mr-1"></i>
<span class="d-none d-lg-block"><?php echo get_phrase('language_list');?></span>
</a>
</li>
<li class="nav-item">
<a href="#add" data-toggle="tab" aria-expanded="true" class="nav-link">
<i class="mdi mdi-account-circle d-lg-none d-block mr-1"></i>
<span class="d-none d-lg-block"><?php echo get_phrase('add_phrase');?></span>
</a>
</li>
<li class="nav-item">
<a href="#add_lang" data-toggle="tab" aria-expanded="false" class="nav-link">
<i class="mdi mdi-settings-outline d-lg-none d-block mr-1"></i>
<span class="d-none d-lg-block"><?php echo get_phrase('add_language');?></span>
</a>
</li>
</ul>
<div class="tab-content">
<!----PHRASE EDITING TAB STARTS-->
<?php if (isset($edit_profile)):?>
<div class="tab-pane show active" id="edit" style="padding: 30px">
<div class="">
<div class="row">
<?php
$current_editing_language = $edit_profile;
echo form_open(base_url() . 'index.php?admin/manage_language/update_phrase/english' , array('id' => 'phrase_form'));
$count = 1;
$language_phrases = $this->db->query("SELECT `phrase_id` , `phrase` , `$current_editing_language` FROM `language`")->result_array();
foreach($language_phrases as $row)
{
$count++;
$phrase_id = $row['phrase_id']; //id number of phrase
$phrase = $row['phrase']; //basic phrase text
$phrase_language = $row[$current_editing_language]; //phrase of current editing language
?>
<!----phrase box starts-->
<div class="col-md-12">
<div class="tile-stats tile-gray">
<div class="icon"><i class="entypo-mail"></i></div>
<h5><?php echo $row['phrase'];?></h5>
<p>
<input type="text" name="phrase<?php echo $row['phrase_id'];?>"
value="<?php echo $phrase_language;?>" class="form-control"/>
</p>
</div>
</div>
<!----phrase box ends-->
<?php
}
?>
</div>
<input type="hidden" name="total_phrase" value="<?php echo $count;?>" />
<input type="submit" value="<?php echo get_phrase('update_phrase');?>" onClick="document.getElementById('phrase_form').submit();" class="btn btn-primary"/>
<?php
echo form_close();
?>
</div>
</div>
<?php endif;?>
<!----PHRASE EDITING TAB ENDS-->
<!----TABLE LISTING STARTS-->
<div class="tab-pane <?php if(!isset($edit_profile))echo 'show active';?>" id="list">
<div class="table-responsive-sm">
<table class="table table-bordered table-centered mb-0">
<thead>
<tr>
<th><?php echo get_phrase('language');?></th>
<th><?php echo get_phrase('option');?></th>
</tr>
</thead>
<tbody>
<?php
$fields = $this->db->list_fields('language');
foreach($fields as $field)
{
if($field == 'phrase_id' || $field == 'phrase')continue;
?>
<tr>
<td><?php echo ucwords($field);?></td>
<td>
<a href="<?php echo base_url();?>index.php?admin/manage_language/edit_phrase/<?php echo $field;?>"
class="btn btn-info">
<?php echo get_phrase('edit_phrase');?>
</a>
<a href="<?php echo base_url();?>index.php?admin/manage_language/delete_language/<?php echo $field;?>"
class="btn btn-danger">
<?php echo get_phrase('delete_language');?>
</a>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
<!----TABLE LISTING ENDS--->
<!----PHRASE CREATION FORM STARTS---->
<div class="tab-pane box" id="add" style="padding: 30px">
<div class="box-content">
<?php echo form_open(base_url() . 'index.php?admin/manage_language/add_phrase/' , array('class' => 'form-horizontal form-groups-bordered validate', 'style' => 'width:100%;'));?>
<div class="padded">
<div class="form-group justify-content-md-center">
<label class="col-3 control-label"><?php echo get_phrase('phrase');?></label>
<div class="col-5">
<input type="text" class="form-control" name="phrase" data-validate="required" data-message-required="<?php echo get_phrase('value_required');?>" placeholder="e.g. name, email"/>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-5">
<button type="submit" class="btn btn-info"><?php echo get_phrase('add_phrase');?></button>
</div>
</div>
<?php echo form_close();?>
</div>
</div>
<!----PHRASE CREATION FORM ENDS--->
<!----ADD NEW LANGUAGE---->
<div class="tab-pane box" id="add_lang" style="padding: 30px">
<div class="box-content">
<?php echo form_open(base_url() . 'index.php?admin/manage_language/add_language/' , array('class' => 'form-horizontal form-groups-bordered validate', 'style' => 'width:100%;'));?>
<div class="padded">
<div class="form-group">
<label class="col-sm-3 control-label"><?php echo get_phrase('language');?></label>
<div class="col-sm-5">
<input type="text" class="form-control" name="language" data-validate="required" data-message-required="<?php echo get_phrase('value_required');?>" placeholder="e.g. Spanish, Portugese"/>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-5">
<button type="submit" class="btn btn-info"><?php echo get_phrase('add_language');?></button>
</div>
</div>
<?php echo form_close();?>
</div>
</div>
<!----LANGUAGE ADDING FORM ENDS-->
</div>
</div>
</div>
</div>

Why it says something goes wrong and can't update to database in mysql?

I am new to PHP. When I create the below code following tutorial, I am puzzle why I can't update my data to database. As it shows below error
"Something went wrong, please try again"
Can anyone help to see through my scripts on where did I go wrong? Or is there anyway that I can do step by step debug to find out which line goes wrong?
<?php require_once("Includes/DB.php"); ?>
<?php require_once("Includes/Functions.php"); ?>
<?php require_once("Includes/Sessions.php"); ?>
<?php
if (isset($_POST["Submit"]))
{
$PostTitle = $_POST["PostTitle"];
$Category = $_POST["Category"];
$Image = $_FILES["Image"]["name"];
$Target = "Upload/".basename($_FILES["Image"]["name"]);
$PostText = $_POST["PostDescription"];
$Admin = "Sharon";
date_default_timezone_set("Asia/Singapore");
$CurrentTime=time();
$DateTime=strftime("%B-%d-%Y %H:%M:%S",$CurrentTime);
if(empty($PostTitle))
{
$_SESSION["ErrorMessage"] = "Title Can't be empty";
Redirect_to("AddNewPost.php");
} elseif (strlen($PostTitle)<5) {
$_SESSION["ErrorMessage"] = "Post Title should be greater
than 5 characters";
Redirect_to("AddNewPost.php");
} elseif (strlen($PostText)>999) {
$_SESSION["ErrorMessage"] = "Post Description should be less than 1000
characters";
Redirect_to("AddNewPost.php");
} else {
// Query to insert Post in DB when everything is fine
global $ConnectingDB;
$sql="INSERT INTO posts(datetime,title,category,author,image,post)";
$sql.="VALUES
:dateTime,:postTitle,:categoryName,:adminName,:imageName,:postDescription
)";
$stmt=$ConnectingDB->prepare($sql); // - > means PDO object rotation
$stmt->bindValue(':dateTime',$DateTime);
$stmt->bindValue(':postTitle',$PostTitle);
$stmt->bindValue(':categoryName',$Category);
$stmt->bindValue(':adminName',$Admin);
$stmt->bindValue(':imageName',$Image);
$stmt->bindValue(':postDescription',$PostText);
$Execute=$stmt->execute();
move_uploaded_file($_FILES["Image"]["tmp_name"],$Target);
if($Execute)
{
$_SESSION["SuccessMessage"]="Post Added Successfully";
Redirect_to("AddNewPost.php");
} else {
$_SESSION["ErrorMessage"]="Something went wrong, please
try again";
Redirect_to("AddNewPost.php");
}
}
} //Ending of Submit Button If- Condition
?>
<!DOCTYPE>
<html lang="en">
<head>
<link rel="stylesheet"
href="https://use.fontawesome.com/releases/v5.7.2/css/all.css"
integrity="sha384-
fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr"
crossorigin="anonymous">
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/
bootstrap.min.css" integrity="sha384-
ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous">
<link rel="stylesheet" href="css/Styles.css">
<title>Categories</title>
</head>
<body>
<div style="height:10px; Background:#27aae1;"></div>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container" ">
<a href="#" class="navbar-brand"> Application
Department </a>
<button class="navbar-toggler" data-
toggle="collapse" data-target="#navbarcollapseCMS">
<span class="navbar-toggler-
icon"></span>
</button>
<div class="collapse navbar-collapse"
id="navbarcollapseCMS">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a href="Main.php" class="nav-
link"><i class="fas fa-home text-success"></i> Main page </a>
</li>
<li class="nav-item">
<a href="Post.php" class="nav-
link"> Posts </a>
</li>
<li class="nav-item">
<a href="Categories.php"
class="nav-link"> Categories</a>
</li>
<li class="nav-item">
Admin
</li>
<li class="nav-item">
<a href="Comment.php"
class="nav-link"> Comments</a>
</li>
</ul>
<ui class="navbar-nav ml-auto">
<li class="nav-item"><a
href="Logout.php" class="nav-link text-warning"><i class="fas fa-user-
times"></i> Logout</a></li>
</ul>
</div>
</div>
</nav>
<div style="height:10px; Background:#27aae1;"></div>
<!--NAVBAR END-->
<!--header-->
<header class="bg-dark text-white py-3">
<div class="container">
<div class="row">
<div class="col-md-12">
<p style="font-size:30px;"> <i class="fas fa-edit"
style="color:#27aae1;"></i> Add New Post </p>
</div>
</div>
</div>
</header>
<!--header end-->
<!--Main Area -->
<section class="container py-2 mb-4">
<div class="row">
<div class="offset-lg-1 col-lg-10" style="min-height:420px;">
<?php
echo ErrorMessage();
echo SuccessMessage();
?>
<form class="" action="AddNewPost.php" method="post"
enctype="multipart/form-data">
<div class="card bg-secondary text-
light mb-2">
<div class="card-body bg-dark">
<div class="form-group">
<label for="title"> <span class="FieldInfo"> Post Title: </span></label>
<input class="form-control" type="text" name="PostTitle" id="title"
placeholder="Type title here" value="">
</div>
<div
class="form-group">
<label
for="CategoryTitle"> <span class="FieldInfo"> Choose Category:
</span></label>
<select
class="form-control" id="CategoryTitle" name="Category">
<?php
//Fetching all the categories from category mysql_list_tables
global $ConnectingDB;
$sql = "SELECT id,title FROM category";
$stmt = $ConnectingDB->query($sql);
while ($DateRows = $stmt->fetch()) {
$Id = $DateRows["id"];
$CategoryName = $DateRows["title"];
?>
<option> <?php echo $CategoryName; ?> </option>
<?php } ?>
</select>
</div>

How to set a <li> as active with php

I'm editing a photography website with a portfolio with links at the top to filter by: View All, Fashion, Family, Weddings, etc.
I'd like to remove "View All" and make "Fashion" (the next list item) set as "active". I'm able to remove the "View All" label by taking it out of the php but it still doesn't set Fashion as active.
I'm using the Miami theme.
I'd appreciate any help!
HTML:
<div id="filters" class="fillter-wrap">
<ul>
<li>
<button class="but activbut active-fillter" data-filter="*">View All</button>
</li>
<li>
<button class="but" data-filter=".fltr-fashion">Fashion</button>
</li>
<li>
<button class="but" data-filter=".fltr-families-couples">Family</button>
</li>
</ul>
PHP:
// filter
if( $filter=='center' ){
$filter_html = "<div id='filters' class='fillter-wrap'>
<ul>
<li>
<button class='but active-fillter' data-filter='*'>View All</button>
</li>
$filter_html
</ul>
</div>";
}
else if( $filter=='toggle' ){
$filter_html = "<div id='filters' class='port5-filters fillter-wrap marg-lg-b15'>
<div class='clearfix show-filter'>
<div class='filter-button'>
<div class='w-embed'>
<i class='fa fa-filter'></i>
</div>
</div>
<div class='filter-effect'>
<span class='filter-txt'>Hide</span><span class='filter-txt-hide'>".esc_html__('Show', 'miami')."</span>
<span class='filter-static'>".esc_html__('Filter', 'miami')."</span>
</div>
</div>
<ul>
<li>
<button class='but active-fillter' data-filter='*'>".esc_html__('', 'miami')."</button>
</li>
$filter_html
</ul>
</div>";
}
else{
$filter_html = "";
}
return "<div class='main-categories n-marg-b30'>
<div class='row'>
$filter_html
<div class='izotope-container col-".abs($columns)." popup-gallery $space'>
<div class='grid-sizer'></div>
$items
</div>
</div>
</div>";
}
Would it be something like this...?
<div id="filters" class="fillter-wrap">
<ul>
<li>
<button class="but activbut active-fillter" data-filter=".fltr-fashion">Fashion</button>
</li>
<li>
<button class="but" data-filter=".fltr-families-couples">Family</button>
</li>
</ul>
Edit: Just realised I may have misunderstood the question. Can you tell us how $filter_html is created? I am not familiar with the miami theme.

Change class for active menu item with php

I am trying to change the class of an active element in my menu with php, but I am having trouble when using "?side=testpage" as URL
I'm typing the href in php to get the pages opened in the correct div according to my index where this code is included.
The whole code is:
<?php
function echo_Active_Tab ($requestUri){
$current_file_name = basename($_SERVER['REQUEST_URI'], ".php");
if ($current_file_name == $requestUri)
echo 'class="active"';
}
?>
<div class="navbar">
<div class="navbar-inner">
<a class="brand"<?php echo "href='?side=mainpage'>Økonomiprogrammet</a>"; ?>
<ul class="nav">
<li <?=echo_Active_Tab("mainpage")?>><?php echo "<a href='?side=mainpage.php'>Startside</a>"; ?></li>
<li <?=echo_Active_Tab("overview")?>><?php echo "<a href='?side=overview'>Oversikten</a>"; ?> </li>
<li <?=echo_Active_Tab("invoice")?>><?php echo "<a href='?side=invoice'>Fakturaer</a>"; ?></li>
<li <?=echo_Active_Tab("expences")?>><?php echo "<a href='?side=expences'>Utgifter</a>"; ?></li>
</ul>
<form class="navbar-form navbar-right" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
<button type="submit" class="btn btn-default">Søk</button>
</div>
</form>
</div>
</div>
Does anyone spot the error in my code?
EDIT: Don't mind the wrong function name, fixed and edited. The code doesn't do as I'd hoped.

Categories