I have this Dropdown made with bootstrap. I'm trying to take the id from the company the user has chosen to my $_POST method. In my table "empresas" I have two columns in it: 'id' and 'name';
This is my Dropdown code:
<ul class="nav nav-pills" role="tablist">
<li role="presentation" class="dropdown" style = "margin-left: auto; margin-right: auto">
</span>
<?php
require 'includes/dbh.inc.php';
$result = $conn->query("SELECT * from empresas") or die($conn->error);
?>
<ul class="dropdown-menu" id="menu1" aria-labelledby="drop4">
<?php
while ($row = $result->fetch_assoc()) : ?>
<li><a class="dropdown-item" href="#" name="idEmpresa" id = "idEmpresa" value = "<?php echo $row['id'] ?>" style="display:none;"><?php echo $row['id']; ?></a></li>
<li><a class="dropdown-item" href="#" value = "<?php echo $row['id'] ?>"><?php echo $row['nome']; ?> </a></li>
<?php endwhile; ?>
</ul>
</li>
</ul>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
<button type="submit" name="addDataDep" class="btn btn-primary" id="addbtn1">Adicionar</button>
</div>
</div>
</div>
</form>
</div>
</div>
And this is where i'll use the $_POST method:
if(isset($_POST['addDataDep'])) {
require 'dbh.inc.php';
$nomeDepartamento = $_POST['nomeDepartamento'];
$id = $_POST['idEmpresa'];
$_SESSION['message'] = "O departamento $idEmpresa foi adicionada com sucesso!";
}
require 'dbh.inc.php' already connects to my database.
When I try to $_POST it, it returns me this error: "Undefined index: idEmpresa".
Thank you for your help!
Related
This question already has answers here:
display div inside php using echo
(2 answers)
Closed 4 months ago.
I'm trying to use echo in this code
<?php
require 'connect.php';
$query = mysqli_query($conn, "SELECT * FROM `videos`") or die(mysqli_error());
while($fetch = mysqli_fetch_array($query)){
$id= $fetch['id'];
?>
<?php echo "
<li class='col-lg-4 col-md-6 col-dm-12'>
<div class='da-card box-shadow'>
<div class='da-card-photo'>
<img src=' echo $fetch['video_name']' alt=''>
<div class='da-overlay'>
<div class='da-social'>
<h4 class='mb-10 color-white pd-20'></h4>
<ul class='clearfix'>
<li>
<a href='' data-fancybox='images'><i class='fa fa-picture-o'></i></a>
</li>
<li>
<a href='#'><i class='fa fa-link'></i></a>
</li>
</ul>
</div>
</div>
</div>
</div>
</li>
"; ?>
<?php
}
?>
I'm getting this error Parse error: syntax error, unexpected string content "", expecting "-" or identifier or variable or number in C:\xampp\htdocs\desk\gallery.php on line 572
Why this error?
.................................................................
You can escape the string and concatenate the variable in the place your hoping to have it like this:
<img src='". $fetch['video_name'] ."' alt=''>
<?php
require 'connect.php';
$query = mysqli_query($conn, "SELECT * FROM `videos`") or die(mysqli_error());
while($fetch = mysqli_fetch_array($query)){
$id= $fetch['id'];
?>
<?php echo "
<li class='col-lg-4 col-md-6 col-dm-12'>
<div class='da-card box-shadow'>
<div class='da-card-photo'>
<img src='". $fetch['video_name'] ."' alt=''>
<div class='da-overlay'>
<div class='da-social'>
<h4 class='mb-10 color-white pd-20'></h4>
<ul class='clearfix'>
<li>
<a href='' data-fancybox='images'><i class='fa fa-picture-o'></i></a>
</li>
<li>
<a href='#'><i class='fa fa-link'></i></a>
</li>
</ul>
</div>
</div>
</div>
</div>
</li>
"; ?>
<?php
}
?>
You can't use echo inside an echo or should I say string statement.
What you have to do is variable substitution like:
echo 'This is my variable '.$x.'.';
Or...
echo "This is my variable $x.";
In your code:
<?php
require 'connect.php';
$query = mysqli_query($conn, "SELECT * FROM `videos`") or die(mysqli_error());
while($fetch = mysqli_fetch_array($query)){
$id= $fetch['id'];
$video_name = $fetch['video_name'];
?>
<?php echo "
<li class='col-lg-4 col-md-6 col-dm-12'>
<div class='da-card box-shadow'>
<div class='da-card-photo'>
<img src='$video_name' alt=''>
<div class='da-overlay'>
<div class='da-social'>
<h4 class='mb-10 color-white pd-20'></h4>
<ul class='clearfix'>
<li>
<a href='' data-fancybox='images'><i class='fa fa-picture-o'></i></a>
</li>
<li>
<a href='#'><i class='fa fa-link'></i></a>
</li>
</ul>
</div>
</div>
</div>
</div>
</li>
"; ?>
<?php
}
?>
Also you can ditch the <?php ?>:
<?php
require 'connect.php';
$query = mysqli_query($conn, "SELECT * FROM `videos`") or die(mysqli_error());
while($fetch = mysqli_fetch_array($query)) {
$id = $fetch['id'];
$video_name = $fetch['video_name'];
echo "
<li class='col-lg-4 col-md-6 col-dm-12'>
<div class='da-card box-shadow'>
<div class='da-card-photo'>
<img src='$video_name' alt=''>
<div class='da-overlay'>
<div class='da-social'>
<h4 class='mb-10 color-white pd-20'></h4>
<ul class='clearfix'>
<li>
<a href='' data-fancybox='images'><i class='fa fa-picture-o'></i></a>
</li>
<li>
<a href='#'><i class='fa fa-link'></i></a>
</li>
</ul>
</div>
</div>
</div>
</div>
</li>
";
}
I got only 0 values in this code. When I write this inside the function I get 3 same values. Please help me with this problem. Thanks in advance
$('#main_cat button, #price button, #color button').click(function() {
// Get data of category
var main_id = $("#main_cat button").data('filter');
var price = $("#price button").data('filter');
var color = $("#color button").data('filter');
alert(main_id + " " + price + " " + color);
$.ajax({
url: "<?php echo base_url(); ?>user/fetch",
method: "POST",
data: {
main_id: main_id,
price: price,
color: color
},
success: function(data) {
$('#products_list').css("height", "455px");
$('#products_list').html(data);
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="main_cat" class="flex-w flex-l-m filter-tope-group m-tb-10">
<button
class="stext-106 cl6 hov1 bor3 trans-04 m-r-32 m-tb-5 how-active1"
data-filter="0"
>
All Products
</button>
<?php foreach ($main_cat as $key =>
$value) { ?>
<button
class="stext-106 cl6 hov1 bor3 trans-04 m-r-32 m-tb-5"
data-filter="<?php echo $value['id']; ?>"
>
<?php echo $value['name']; ?>
</button>
<?php } ?>
</div>
<div class="filter-col3 p-r-15 p-b-27">
<div class="mtext-102 cl2 p-b-15">
Color
</div>
<ul id="color">
<li class="p-b-6">
<button data-filter="0" class="filter-link stext-106 trans-04">
All
</button>
</li>
<?php foreach ($color as $key =>
$value) { ?>
<li class="p-b-6">
<button
data-filter="<?php echo $value['name'];?>"
class="filter-link stext-106 trans-04"
>
<?php echo $value['name']; ?>
</button>
</li>
<?php } ?>
</ul>
</div>
<div class="filter-col2 p-r-15 p-b-27">
<div class="mtext-102 cl2 p-b-15">
Price
</div>
<ul id="price">
<li class="p-b-6">
<button
data-filter="0"
class="filter-link stext-106 trans-04 filter-link-active"
>
All
</button>
</li>
<li class="p-b-6">
<button data-filter="1" class="filter-link stext-106 trans-04">
$0.00 - $50.00
</button>
</li>
<li class="p-b-6">
<button data-filter="2" class="filter-link stext-106 trans-04">
$50.00 - $100.00
</button>
</li>
</ul>
</div>
I have a system that after uploading multiple photos it generates a subtitles field for each photo, I want to update the database of these subtitles. How to do this. My table in database - tb_fotos_portfolio table (id, portfolio_id, legenda, arquivo).
Obs .: It would be only the part of UPDATE the subtitles
<?php
$sql = "SELECT * FROM tb_fotos_portfolio WHERE id_portfolio = $id";
$query = $DB->Select($sql);
if (count($query) == 0) { ?>
<div class="box-body">
<h3 class="text-center text-danger" style="margin: 140px 0;">Imagem não enviada!</h3>
</div>
<?php } else { ?>
<div class="box-body no-padding">
<ul class="users-list clearfix">
<?php foreach($query as $item) { ?>
<li>
<a class="popup-link" href="../../../upload/portfolio/imagem/<?php echo $item['arquivo']; ?>">
<img src="../../../upload/portfolio/miniatura/<?php echo $item['arquivo']; ?>" alt="<?php echo $item['arquivo']; ?>"/>
<span class="users-list-name"><?php echo $item['arquivo']; ?></span>
</a>
<a class="btn btn-label btn-danger btn-xs" href="acoes.php?acao=deleteFotos&id=<?php echo $_GET['id'];?>&arquivo=<?php echo $item['arquivo'];?>"><i class="fal fa-trash-alt"></i>Excluir</a>
<span class="users-list-name"><?php echo $item['legenda']; ?></span>
<form id="" action="acoes.php?acao=legendas_fotos" method="post" enctype="multipart/form-data">
<input type="text" name="legenda[]" id="legenda" class="form-control" placeholder="Legenda" value="<?php echo $item['legenda']; ?>"/>
</li>
<?php } ?>
</ul><!-- /.users-list -->
</div>
<button type="submit" class="btn btn-success btn-label btn-sm"><i class="fa fa-check"></i> Atualizar Legendas</button>
</form>
acao.php
case 'legendas_fotos':
$legenda = $_POST['legenda'];
...
$sql = "UPDATE tb_fotos_portfolio SET legenda= $legenda ";
$vCampos = array('id'=>$id);
$DB->Execute($sql, $vCampos);
// Volta para o form
header("location:form.php?id=" . $id);
exit;
break
I have a drop down with name="country1" where I am getting dynamic data through query inside it. Now, I want to get the value of in my alert box but it's not working right now. So, How can I do this? Please help me.
code:
<div class="btn-group bootstrap-select show-tick">
<div class="dropdown-menu open">
<div class="bs-actionsbox">
<div class="btn-group btn-group-sm btn-block">
<button type="button" class="actions-btn bs-select-all btn btn-default">Select All</button>
<button type="button" class="actions-btn bs-deselect-all btn btn-default">Deselect All</button>
</div>
</div>
<ul class="dropdown-menu inner state1" role="menu">
<?php
$this->db->select('*');
$this->db->from('states');
$this->db->where('country_id','101');
$sql = $this->db->get();
$result = $sql->result_array();
foreach($result as $row)
{
?>
<li data-original-index="0">
<a tabindex="0" data-tokens="null">
<span class="text"><?php echo $row['name']; ?></span><span class="glyphicon glyphicon-ok check-mark"></span>
</a>
</li>
<?php
}
?>
</ul>
</div>
<select name="country1" class="bootstrap-select" title="India:State" multiple="" data-actions-box="true" tabindex="-98">
<?php
$this->db->select('*');
$this->db->from('states');
$this->db->where('country_id','101');
$sql1 = $this->db->get();
$result1 = $sql1->result_array();
foreach($result1 as $row1)
{
echo "<option value='".$row1['id']."'>".$row1['name']."</option>";
}
?>
</select>
</div>
jquery code:
<script>
$(document).ready(function(){
$('.state1 li').click(function(){
state = $(this).text();
alert(state);
});
});
</script>
i have bootstrap tabs along with filters. When user selects the filter and submits, the ajax call is generated and tabs should display the content.
<ul class="nav nav-tabs " role="tablist">
<li class="active col-md-3"><a data-toggle="tab" href="#home">Notes</a></li>
<li class="col-md-3"><a data-toggle="tab" href="#menu1">Question Bank</a></li>
<li class="col-md-3"><a data-toggle="tab" href="#menu2">Summary</a></li>
<li class="col-md-3"><a data-toggle="tab" href="#menu3">Videos</a></li>
</ul>
<hr>
<div class="tab-content">
<div id="home" class="tab-pane fade in active">
<?php
include "notes.php"
?>
<br><br><hr>
<div class="col-md-12">
</div>
</div>
Notes.php contain the code for filter which is in enclose in form
<script type="text/javascript">
$(function(){
$('input[type=submit]').click(function(){
$.ajax({
type: "GET",
url: "filter_form.php",
data: $("#filter_search").serialize(),
beforeSend: function(){
$('#home').html('<img src="/img/loading.gif" />');
},
success: function(data){
$('#home').html(data);
}
});
});
});
</script>
form action="" method="GET" id="filter_search">
<ul class="nav navbar-nav container-fluid col-md-12">
<li class="col-md-3">
<select class="form-control dropdown-toggle" data-toggle="dropdown" name="select_category">
<option value="category">Select Category</option>
<?php
$sql1 = mysqli_query($conn,"call category_dropdown()");
while($row = mysqli_fetch_array($sql1))
{
echo "<option value='" . $row['category'] ."'>" . $row['category'] . "</option>";
}
mysqli_free_result($sql1);
mysqli_next_result($conn);
?>
</select>
</li>
<li class="col-md-3">
<select class="form-control dropdown-toggle" data-toggle="dropdown" name="select_course"></a>
<option value="course">Select Course</option>
<?php
$sql2 = mysqli_query($conn,"call courses_dropdown()");
while($row = mysqli_fetch_array($sql2))
{
echo "<option value='" . $row['courses'] ."'>" . $row['courses'] . "</option>";
}
mysqli_free_result($sql2);
mysqli_next_result($conn);
?>
</select>
</li>
<li class="col-sm-3">
<select class="form-control dropdown-toggle" name="select_subject">
<option value="subjects">Select Subjects</option>
<?php
$sql3 = mysqli_query($conn,"call subject_dropdown()");
while($row = mysqli_fetch_array($sql3))
{
echo "<option value='" . $row['subjects'] ."'>" . $row['subjects'] . "</option>";
}
mysqli_free_result($sql3);
mysqli_next_result($conn);
?>
</select>
</li>
<li class="col-md-3">
<input type="submit" name="filter" class="btn form-control btn-warning" value="Filter Results">
</li>
</ul>
</form>
filter_search.php
<?php
include 'includes/dbconfig.php';
if(isset($_GET['id']))
{
$id=$_GET['id'];
$start=($id-1)*$limit;
}
else{
$id=1;
}
if(isset($_GET['filter']))
{
$start = 0;
$limit = 16;
$category = $_GET['select_category'];
$course = $_GET['select_course'];
$subject = $_GET['select_subject'];
$sql = mysqli_query($conn,"call filter('category','course','subject')") or die('Query failed: '. mysqli_error($conn));
while($row = mysqli_fetch_array($sql))
{
$title = $row['title'];
$description = $row['description'];
$url = $row['content_url'];
$icon = $row['thumb_icon'];
?>
<div class="col-md-3">
<a href="<?php echo $url ;?>">
<div class="well well-sm">
<img class="img" alt="PDF" src="<?php echo $icon ;?>" >
<h4><small><?php echo $title ; ?></small></h4>
<p> <a data-toggle="modal" data-target="#myModal">Preview</a></p>
</div>
</a>
</div>
<?php
}
}
?>