Unable to retrieve dates from attendance record - php

I have attendance record database
id | emp_id | attendance_date.
I inserted attendance_date by varchar(200).I want to retrieve dates between startdate and enddate if I choose datetime picker.My date format is m/d/Y.
If I retrieve 04/1/2015 and 04/30/2015,it isn't displayed.But If I retrieve
12/1/2014 and 12/31/2014,record is displayed.The problem is the month.It have unnecessary zero in front of month.How can I do that?
Please help me?Database is like that.
id emp_id attendance_date
1 1 10/4/2014 10:36
2 1 10/30/2014 9:36
attendanceRecord.php
<form enctype="multipart/form-data" method="post" class="form-inline" role="form" action="attendance_search.php">
<!--Start Date-->
<div class="">
<div class="form-group required">
<label for="startdate" class="control-label">Start Date:</label>
<input class="form-control" placeholder="Choose Date " type="text" id="datepicker-8" name="startdate" required="required" />
</div>
</div><br/><br/>
<!--End Date-->
<div class="">
<div class="form-group required">
<label for="enddate" class="control-label">End Date:</label>
<input class="form-control" placeholder="Choose Date " type="text" id="datepicker-9" name="enddate" required="required" />
</div>
</div>
<!--Create Button-->
<div class=""> <br/>
<input class="btn btn-success" type="submit" value="Search" />
</div>
</form>
**attendance_search.php**
<form method="post" name="salaryform" action="" class="form-vertical">
<div class="table table-hover">
<table border="1" cellspacing="0" class="table" >
<tr class="success" >
<th>Employee ID</th>
<th>Date</th>
<th>Timein Timeout</th>
</tr>
<?php
include 'connect.php';
error_reporting(E_ALL ^ E_NOTICE);
if(!empty($_POST)){
$startdate= mysql_real_escape_string(date( "m/d/Y H:i:s",strtotime($_POST["startdate"])));
$enddate= mysql_real_escape_string(date("m/d/Y H:i:s",strtotime($_POST["enddate"])));
$sql="SELECT * FROM attendance2 WHERE attendance_date between '".$startdate."' and '".$enddate."'";
$retval = mysql_query($sql);
if (!$retval) {
die('Could not get data: ' . mysql_error());
}
while ($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
echo '<tr class="active">';
echo '<td >'.$row['emp_id'].'</td>';
echo '<td>'.$row['attendance_date'].'</td>';
echo '<td>'.$row['timein_timeout'].'</td>';
}
echo '</tr>';
echo '</table>';
}
?>
</table>
</div>
</form>

If you don't need the time of start date and end date then you could do something like this,
$startdate = mysql_real_escape_string(date( "m/d/Y",strtotime($_POST["startdate"])));
$enddate = mysql_real_escape_string(date("m/d/Y",strtotime($_POST["enddate"])));
$sql="SELECT * FROM attendance2 WHERE date(attendance_date) between '".$startdate."' and '".$enddate."'";

Related

PHP MYSQL Displaying the same data from table to another page

<div class="card-header py-3">
<h4 class="m-2 font-weight-bold text-primary">Asset Approval List</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>Asset</th>
<th>Serial Number</th>
<th>Model Name</th>
<th>Owner ID</th>
<th>Owner Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<script>
function approval(){
window.location.href = "AddAssetApproval.php";
}
</script>
<?php
$query = "SELECT * FROM waiting_approval";
$result = mysqli_query($conn, $query) or die (mysqli_error($conn));
while ($row = mysqli_fetch_assoc($result)) {
echo '<tr>';
echo '<td>'. $row['Category'].'</td>';
echo '<td>'. $row['SerialNumber'].'</td>';
echo '<td>'. $row['ModelName'].'</td>';
echo '<td>'. $row['OwnerID'].'</td>';
echo '<td>'. $row['OwnerName'].'</td>';
echo '<td>'. $row['Description'].'</td>';
echo '<td><input type="button" value = "View" onclick="approval()"></td>';
echo '</tr> ';
}
?>
<div class="title">
Add Asset Approval Form
</div>
<div class="form">
<div class="inputfield">
<label>Category</label>
<input type="text" class="input" name="Category">
</div>
<div class="inputfield">
<label>Serial Number</label>
<input type="text" class="input" name="SN">
</div>
<div class="inputfield">
<label>Model Name</label>
<input type="text" class="input" name="Model Name">
</div>
<div class="inputfield">
<label>Owner ID</label>
<input type="text" class="input" name="OID">
</div>
<div class="inputfield">
<label>Owner Name</label>
<input type="text" class="input" name="OName">
</div>
<div class="inputfield">
<label>Description</label>
<input type="text" class="input" name="Desc">
</div>
Asset Approval List is a table with lots of row of data and a button, after clicking the button, it will link to Asset Approval Form. I would like to fetch the data from the same row in Asset Approval List to my Asset Approval Form. The data in the table of Asset Approval List is fetched from mysql phpmyadmin. Any idea how to link the same data to Asset Approval Form?
This is my Asset Approval List
This is my Asset Approval Form
Assuming there's a unique ID column in the table, you should include that in the call to approval():
echo '<td><input type="button" value = "View" onclick="approval(\'' . $row['SerialNumber'] . '\')"></td>';
Then change approval() to include the ID in the URL.
function approval(serial){
window.location.href = "AddAssetApproval.php?serial=" + serial;
}
And AddAssetApproval.php should use $_GET['serial'] to display the appropriate approval form for that serial number.
$stmt = $conn->prepare("SELECT * FROM waiting_approval WHERE SerialNumber = ?");
$stmt->bind_param("i", $_GET['serial']);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();

Update Table Row Value with Post Button

I have some data in my mysql database which I am displaying in table using PHP like below
$requirement_qry="SELECT t1.*, t2.id as unit_id, t2.name as unit_name FROM `tbl_requirements`
t1 INNER JOIN tbl_units AS t2 on unit_type = t2.id AND project_id='".$_GET['project_id']."' AND user_id='".$userid."'";
$requirement_result=mysqli_query($mysqli,$requirement_qry);
<form action="" name="addeditcategory" method="post" class="form form-horizontal" enctype="multipart/form-data">
<input type="hidden" name="project_id" value="<?php echo $_GET['project_id'];?>" />
<div class="section">
<div class="section-body">
<div class="form-group">
<label class="col-md-3 control-label" >Project Name :-</label>
<div class="col-md-6">
<input type="text" name="name" id="name" value="<?php if(isset($_GET['project_id'])){echo $row['name'];}?> " class="form-control" disabled>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" >Location :-</label>
<div class="col-md-6">
<input type="text" name="location" id="location" value="<?php if(isset($_GET['project_id'])){echo $row['location'];}?> " class="form-control" disabled>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Project Status :-</label>
<div class="col-md-6">
<select name="status" id="status" class="select2" disabled>
<?php if (!isset($_GET['project_id'])) { ?>
<option value="1">--Project Status--</option>
<?php } ?>
<option value="1" <?php echo $row['status'] == '1' ? 'selected' : ''; ?> >Open</option>
<option value="2" <?php echo $row['status'] == '2' ? 'selected' : ''; ?> >Closed</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-md-3">
<label class="control-label">Project Details :-</label>
</div>
<div class="col-md-6">
<textarea name="details" id="details" rows="4" class="form-control" disabled><?php echo stripslashes($row['details']);?></textarea>
</div>
</div>
<div class="form-group">
<div class="col-md-3">
<label class="control-label">Project Requirements :-</label>
</div>
<div class="col-md-6">
<table id="t01">
<thead>
<tr>
<th>#</th>
<th>Requirements</th>
<th>Required</th>
<th>Sent</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$no = 1;
while ($row1 = mysqli_fetch_array($requirement_result))
{
$id = $row1['id'];
$unit_name = $row1['unit_name'];
echo '<input type="hidden" name="reqId" id= "reqId" value="'.$id.'" />';
echo '<tr>
<td>'.$no.'</td>
<td>'.$row1['name'].'</td>
<td>'.$row1['unit_required']." ".$unit_name.'</td>
<td><input type="number" id = "received" name = "received" value ="'.$row1['unit_received'].'"/></td>
<td><button type="submit" name="submit" class="btn btn-primary" style="padding:5px 10px;">Submit</button></td>
</tr>';
$no++;
}?>
</tbody>
</table>
</div>
</div>
</div>
</form>
Above code is properly displaying my data. I have one field value from row need to update using submit button. Its working fine if there only one row...if there multiple row, its not updating data of it except last row.
My submit code is like below
if(isset($_POST['submit']) and isset($_POST['project_id']))
{
$projectId = $_GET['project_id'];
$data = array(
'unit_received' => $_POST['received']
);
$unit_edit=Update('tbl_requirements', $data, " WHERE id = '".$_POST['reqId']."'");
print_r($unit_edit);
echo $unit_edit;
if ($unit_edit > 0)
{
$_SESSION['msg']="11";
header( "Location:view_open_project.php?project_id=".$_POST['project_id']);
exit;
}
}
I am little new in PHP, Let me know if someone can help me for solve the bug.
Thanks a lot :)
As #Saji has already stated, you are replicating your name through the loop.You should rather use
echo '<input type="hidden" name="reqId[]" id= "reqId" value="'.$id.'" />';
Note the [] brackets that were appended so that you create an array of names.
To update, you need a loop like
for($i=0;$i<count($_POST['reqId']);$i++){
$unit_edit=Update('tbl_requirements', $data, " WHERE id = '".$_POST['reqId'][$i]."'");
}
What you can do is just create a hidden form where you will keep original elements. When the save button click you just find the actual value and set this to the elements inside hidden form, then trigger the submit button inside hidden form.
Note the changes I have done on your code.
1.Removed the hidden element reqId from inside loop.
2.Given a class name to the button inside loop and changed the button type from submit to button. Added data attribute data-id="'.$id.'".
3.The input received inside the loop has given unique id and name by concatenated the $id.
4.Created hidden form with hidden input in it. It has your actual input names.
5.Created a jquery function to attach click event to the button inside loop.
6.Moved the hidden element project_id to inside hidden form.
Now see the below code for more details. Hope this will help you..
<form action="" name="addeditcategory" method="post" class="form form-horizontal" enctype="multipart/form-data">
<input type="hidden" name="project_id" value="<?php echo $_GET['project_id']; ?>"/>
<div class="section">
<div class="section-body">
<div class="form-group">
<label class="col-md-3 control-label">Project Name :-</label>
<div class="col-md-6">
<input type="text" name="name" id="name" value="<?php if (isset($_GET['project_id'])) {
echo $row['name'];
} ?> " class="form-control" disabled>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Location :-</label>
<div class="col-md-6">
<input type="text" name="location" id="location" value="<?php if (isset($_GET['project_id'])) {
echo $row['location'];
} ?> " class="form-control" disabled>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Project Status :-</label>
<div class="col-md-6">
<select name="status" id="status" class="select2" disabled>
<?php if (!isset($_GET['project_id'])) { ?>
<option value="1">--Project Status--</option>
<?php } ?>
<option value="1" <?php echo $row['status'] == '1' ? 'selected' : ''; ?> >Open</option>
<option value="2" <?php echo $row['status'] == '2' ? 'selected' : ''; ?> >Closed</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-md-3">
<label class="control-label">Project Details :-</label>
</div>
<div class="col-md-6">
<textarea name="details" id="details" rows="4" class="form-control"
disabled><?php echo stripslashes($row['details']); ?></textarea>
</div>
</div>
<div class="form-group">
<div class="col-md-3">
<label class="control-label">Project Requirements :-</label>
</div>
<div class="col-md-6">
<table id="t01">
<thead>
<tr>
<th>#</th>
<th>Requirements</th>
<th>Required</th>
<th>Sent</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$no = 1;
while ($row1 = mysqli_fetch_array($requirement_result)) {
$id = $row1['id'];
$unit_name = $row1['unit_name'];
echo '<tr>
<td>' . $no . '</td>
<td>' . $row1['name'] . '</td>
<td>' . $row1['unit_required'] . " " . $unit_name . '</td>
<td><input type="number" id = "received' . $id . '" name = "received' . $id . '" value ="' . $row1['unit_received'] . '"/></td>
<td><button type="button" name="submit" class="btn btn-primary submit-click" data-id="' . $id . '" style="padding:5px 10px;">Submit</button></td>
</tr>';
$no++;
} ?>
</tbody>
</table>
</div>
</div>
</div>
</form>
<form action="" id="addeditcategory_temp" name="addeditcategory_temp" method="post" class="form form-horizontal" enctype="multipart/form-data" style="display:none;>
<input type="hidden" name="project_id" value="<?php echo $_GET['project_id']; ?>"/>
<input type="hidden" name="reqId" id= "reqId" value="" />
<input type="number" id = "received" name = "received" value ="">
<button id="submitButton" type="submit" name="submit" class="btn btn-primary" style="padding:5px 10px;">
</form>
<script>
$(document).ready(function(e){
$('.submit-click').off('click').on('click', function(e){
var reqId = $(this).data('id');
var received = $('#received'+reqId).val();
var form = $('#addeditcategory_temp');
form.find('#reqId').val(reqId);
form.find('#received').val(received);
form.find('#submitButton').trigger('click');
})
});
</script>

Using radio buttons to show approved or unapproved users in admin panel in php mysql

I have a project wherein I need to show unapproved and approved user from the database. I have to show it by radio buttons such as All, Approved and Unapproved. I want to know how to list each of them ,as the radio choice is clicked, on the same page. I am a fresher in PHP and its my first project and so highly confused.
I am trying to put in switch for radio and no idea about how to write MySQL query in each switch case. Is there any solution or code available? Is there any way to solve this?
Here is my code:
<?php include 'blocks/headerInc.php' ; ?>
<?php
$errmsg = "" ;
$module_id = '';
$query = '';
$date_from = '';
$date_to = '';
//Search section start here
$sqlQuery = "SELECT * FROM tbl_user WHERE type =3 " ;
if(isset($_REQUEST['submit']))
{
if(!empty($_REQUEST['date_from']))
{
$date_from = date("Y-m-d", strtotime($_REQUEST['date_from'])) ;
}
if(!empty($_REQUEST['date_to']))
{
$date_to = date("Y-m-d", strtotime($_REQUEST['date_to'])) ;
}
if(!empty($date_to) && empty($date_from))
{
$errmsg = "Please select valid date range.";
}
if(!empty($date_to) && (strtotime($date_from)> strtotime($date_to)))
{
$errmsg = "Please select valid date range.";
}
if($errmsg =='')
{
if(!empty($date_to) && (strtotime($date_from)<= strtotime($date_to)))
{
$sqlQuery .= " AND created_on BETWEEN '$date_from' AND '$date_to'";
}
$sqlQuery .= " order by id DESC";
}
$date_from = date("m/d/Y",strtotime($date_from));
$date_to = date("m/d/Y",strtotime($date_to));
$date_from = $date_from != '01/01/1970' ? $date_from : '';
$date_to = $date_to != '01/01/1970' ? $date_to : '';
}
?>
<div class="container pagecontainer">
<!-- Static navbar -->
<div class="row row-offcanvas row-offcanvas-right">
<!--/.col-xs-12.col-sm-9-->
<div class="col-sm-3 col-md-3 sidebar" id="sidebar">
<div id="left_panel" class="clearfix left">
<?php include 'blocks/leftnavInc.php' ; ?>
</div>
</div>
<div class="col-xs-12 col-sm-9 page-right">
<div class="panel panel-primary">
<div class="panel-heading">Search Registered Candidate</div>
<div class="panel-body">
<div class="column col-sm-offset-0">
<?php
if($errmsg!="")
{
echo "<div class='error'>".ucwords($errmsg)."</div>";
}
?>
<form class="form-horizontal" method="get" action="">
<div class="form-group">
<div class="col-md-6">
<div class="col-md-4">
<label for="username" class="control-label">Date From:</label>
</div>
<div class="col-md-8">
<div class="input-group date">
<input class="form-control datepicker" data-val="true" data-val-date="The field Dob must be a date." data-val-required="The Dob field is required." id="Dob" name="date_from" placeholder="Date From" type="text" value="<?php echo $date_from ; ?>" >
</div>
</div>
</div>
<div class="col-md-6">
<div class="col-md-4">
<label for="username" class="control-label">Date To:</label>
</div>
<div class="col-md-8">
<div class="input-group date">
<input class="form-control datepicker" data-val="true" data-val-date="The field Dob must be a date." data-val-required="The Dob field is required." id="Dob" name="date_to" placeholder="Date To" type="text" value="<?php echo $date_to ; ?>" >
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<div class="col-md-8 text-left">
<button type="submit" name="submit" value="submit" class="btn btn-success"><i class="glyphicon glyphicon-floppy-disk"></i> Search</button>
<button type="reset" onClick="javascript:window.location.href='reportRegisteredUsers.php'" class="btn btn-danger"><i class="glyphicon glyphicon-ban-circle"></i> Cancel</button>
</div>
</div>
<div class="col-md-6">
<div class="col-md-4">
<label for="username" class="control-label"> </label>
</div>
<div class="col-md-8 text-right">
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="panel panel-primary">
<div class="panel-heading">Report:Candidate Reports</div>
<div class="panel-body">
<input type="radio" name="gender" value="male" checked="checked"> All Candidates<br>
<input type="radio" name="gender" value="female"> Approved Candidates<br>
<input type="radio" name="gender" value="other"> Unapproved Candidates<br>
<div class="column col-sm-offset-0">
<table id="example" class="table table-striped table-hover table-bordered dataTableReport dt-responsive nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>S.No.</th>
<th>Email ID</th>
<th>SBI Employee ID</th>
<th>Name</th>
<th>Mobile No.</th>
<th>Date of Birth</th>
<th>Registration Date</th>
</tr>
</thead>
<tbody>
<?php
$sq = $db->query($sqlQuery);
$i = 1 ;
if($db->affected_rows > 0)
{
while($row=mysql_fetch_array($sq))
{
extract($row);
?>
<tr>
<td><?php echo $i ; ?></td>
<td><?php echo $email ; ?></td>
<td><?php echo $employee_id ; ?></td>
<td><?php echo $first_name." ".$middle_name." ".$last_name ; ?></td>
<td><?php echo $mobile ; ?></td>
<td><?php if($dob !='1970-01-01'){echo date("d-m-Y", strtotime($dob)) ; }?></td>
<td><?php echo date("d-m-Y", strtotime($created_on)) ; ?></td>
</tr>
<?php $i++;}} ?>
</tbody>
</table>
</div>
</div>
</div>
<div> <button type="reset" onClick="javascript:history.go(-1)" class="btn btn-danger"><i class="glyphicon glyphicon-ban-circle"></i> Go Back</button> </div>
<!--/row-->
</div>
<!--/.sidebar-offcanvas-->
</div>
</div>
<?php include 'blocks/footerInc.php'
This would be a very very simple page for what you want to archive.
<?php
//connection with database here.
if(isset($_POST['users']) && $_POST['users'] == 'approved'){
$sql = "your query";
$result = mysqli_query($mysql, $sql);
while($row = result->fetch_assoc()){
$users[] = $row;
}
}elseif(isset($_POST['users']) && $_POST['users'] == 'unapproved'){
$sql = "your query";
$result = mysqli_query($mysql, $sql);
while($row = result->fetch_assoc()){
$users[] = $row;
}
}elseif(isset($_POST['users']) && $_POST['users'] == 'other'){
$sql = "your query";
$result = mysqli_query($mysql, $sql);
while($row = result->fetch_assoc()){
$users[] = $row;
}
}
?>
<div>
<form action="" method="POST">
Approved<input type="radio" name="users" value="approved">
Unapproved<input type="radio" name="users" value="unapproved">
Other<input type="radio" name="users" value="other">
<input type="submit" value="Submit">
</form>
</div>
<div class="results">
<?php foreach ($users as $key => $value) {
?>
<div class="user">
<div><?php echo $value['firstName']; ?></div>
<div><?php echo $value['lastName']; ?></div>
</div>
<?php
} ?>
</div>

get value of checkbox submit to a variable

I'm trying to work out how to get the value of a checkbox submit it to a variable which is an id from a sql db.
Below is my current code:
-- Index.php
<?php
$sql = "SELECT * FROM `file`";
if (!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']');
}
?>
<form method="post">
<button class="btn btn-success">New</button>
<button type="submit" class="btn btn-warning">Edit</button>
<button class="btn btn-danger">Delete</button>
<table class="table table-condensed">
<thead>
<th>#</th>
<th>Name</th>
<th>Category</th>
<th>Date</th>
</thead>
<tbody>
<?php while($row = $result->fetch_assoc()){ ?>
<td><input type="checkbox" name="id_grab" value="<?php echo $row['file_id']; ?>"></td>
<td><?php echo $row['file_name']; ?></td>
<td><?php echo $row['file_category']; ?></td>
<td><?php echo date('d-m-y', strtotime($row['file_date'])); ?></td>
</tbody>
<?php } ?>
</table>
</form>
-- file_edit.php
<?php include('../db_connect.php') ;
$id=isset($_POST['id_grab']);
$sql = "SELECT * FROM `file` WHERE file_id = $id";
if (!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']');
}
$row = $result->fetch_assoc();
?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">× </button>
<h4 class="modal-title" id="myModalLabel">Edit Invoice / Receipt</h4>
</div>
<div class="modal-body">
<form action="../includes/file_update.php" method="post" role="form" enctype="multipart/form-data">
<div class="form-group">
<label for="File_Name">Name</label>
<input type="text" name="file_name" class="form-control" id="file_name" value="<?php echo $row['file_name']; ?>">
</div>
<div class="form-group">
<lable for="File_Category">Category</label>
<input type="text" name="file_category" class="form-control" id="file_category" placeholder="Financial">
</div>
<div class="form-group">
<label for="file_tag">Tag</label>
<input type="text" name="file_tag" class="form-control" id="file_tag" placeholder="statement">
</div>
<div class="form-group">
<label for="file_description">Description</label>
<input type="text" name="file_description" class="form-control" id="file_description">
</div>
<div class="form-group">
<label for="file_date">Date</label>
<input type="date" name="file_date" class="form-control" id="file_date">
</div>
<div class="form-group">
<label for="file_location">File</label>
<input type="file" class="form-control" name="file_location" value="file">
<p class="help-block">Select appropriate file for upload.</p>
</div>
<button type="button" class="btn btn-info" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-success">Upload</button>
</form>
</div>
I can't work it out, spent hours looking online... My concern is at it's using Bootstraps Modal I wasn't sure if it would be able to grat the POST data... As if I enter the ID manually it works...
Any assistance would be greatly appreciated.
change this
$id=isset($_POST['id_grab']);
to
$id=isset($_POST['id_grab'])?$_POST['id_grab']:'';
//if id_grab dont have a value then $id value will be ''
isset() Returns TRUE if var exists and has value other than NULL, FALSE otherwise.

insert checkboxes in sql and echo them using php

I am building a form to input different data to characterize events (name, date, type of event) into a sql db so that they can be searched by location later on.
Below are the html form, the php file (insert.php) to put the data in the db and finally the php of the search result.
The issue is with the checkboxes, I am trying to make it so that the multiple values get stored in the same sql column, a little like tags that can be used in the search.
My issue right now is that when I process the form, the entry in my sql table in the column of the checkbox says "Array" and then it does not display on the search result.
I don't know if the issue is that I input the data incorrectly in the table or if the results display is the issue.
Any help much appreciated.
FORM
<form class="form-horizontal" enctype="multipart/form-data" action="insert.php" method="post">
<label class="control-label"> Name Of The Event
<input type="text" placeholder="Name of the event" name="name"></label>
<div class="control-group">
<label class="control-label"> Address</label>
<input type="text" placeholder="address" name="address">
<label class="control-label"> City</label>
<input type="text" name="citycountry" class="location" autocomplete="off" id="searchTextField" placeholder="City">
<div id="map_canvas"></div>
</div>
</div>
<div class="control-group">
<label class="control-label"> Description</label>
<div class="controls">
<input type="text" name="description" placeholder="Add details about this event.">
</div>
</div>
<div class="control-group">
<label class="control-label"> Start</label>
<div class="controls">
<div id="sandbox-container">
<input type="date" name="startdate" placeholder="mm/dd/yyyy"> <!--<span class="add-on"><i class="icon-th"></i></span>-->
</div> <input type="time" class="span2" name="starttime">
</div>
</div>
<div class="control-group">
<label class="control-label"> End</label>
<div class="controls">
<div id="sandbox-container">
<input type="date" name="enddate" placeholder="mm/dd/yyyy"> <!--<span class="add-on"><i class="icon-th"></i></span>-->
</div> <input type="time" name="endtime">
</div>
</div>
<div class="control-group">
<label class="control-label"> Add Image</label>
<div class="input-append">
<input type="file" name="picture"></br>
</div> </div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" name="eventtype[]" value="Lesson"> Dance Lesson
</label>
<label class="checkbox">
<input type="checkbox" name="eventtype[]" value="Social"> Social Dancing
</label>
<label class="checkbox">
<input type="checkbox" name="eventtype[]" value="Competition"> Competition
</label>
<label class="checkbox">
<input type="checkbox" name="eventtype[]" value="Show"> Show
</label>
<label class="checkbox">
<input type="checkbox" name="eventtype[]" value="Convention"> Dance Convention
</label>
</div>
</div> <div class="control-group">
<div class="controls">
<input class="btn btn-info" type="submit">
</div>
</div>
</form>
INSERT.PHP
<?php
//preparing the patch to copy the uploaded file
$target_path = "upload/";
$target_path = $target_path . uniqid();
//adding the name of the file, finishing the path
$target_path = $target_path . $_FILES["file"]. basename( $_FILES['picture']['name']);
//moving the file to the folder
if(move_uploaded_file($_FILES['picture']['tmp_name'], "$target_path")) {
echo "The file ". basename( $_FILES['picture']['name']).
" has been uploaded";
}
else{
echo "There was an error uploading the file, please try again!";
}
//preparing the query to insert the values
$query = "INSERT INTO complete_table (eventtype, name, address, citycountry, starttime, startdate, endtime, enddate, description,picture) VALUES ( '$_POST[eventtype]' ,'$_POST[name]','$_POST[address]','$_POST[citycountry]','$_POST[starttime]', '$_POST[startdate]','$_POST[enddate]','$_POST[endtime]','$_POST[description]', '". $target_path ."')";
//opening connection to db
$link = mysql_connect('localhost', 'root', ' ');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
//selecting a db
mysql_select_db("wcs_venues", $link) or die(mysql_error());
//running the query
$result = mysql_query($query) or die (mysql_error());
//closing the connection
mysql_close($link);
SEARCH RESULTS
<?php
mysql_connect ("localhost", "root"," ") or die (mysql_error());
mysql_select_db("wcs_venues") or die(mysql_error());
$term = $_POST['term'];
$sql = mysql_query("SELECT * FROM complete_table WHERE citycountry LIKE '%$term%'")or die(mysql_error());
}
/* echo '<td width="250px;" style="float:left;"><img src="http://s3-media3.ak.yelpcdn.com/bphoto/CJziwp9QDcSPuYVjy4uasg/l.jpg" class="bigthumb" style="margin:30px; width:114px; height:auto;"></td>';*/
echo '<table class="table table-bordered">';
echo ' <tbody> <tr> <td> Name of the venue </td>';
echo '<td> </td> </tr>';
echo '<tr> <td> Address </td>';
echo '<td>'.$row['citycountry'];
echo '</td> </tr>';
echo '<tr> <td> Date </td>';
echo '<td>'.$row['date'];
echo '</td> </tr>';
echo '<tr> <td> Picture </td>';
echo '<td><img src=http://localhost/theme/'.$row['picture'] .'> </td>';
echo '</td> </tr>';
echo '<tr> <td> Eventtype </td>';
if(isset($_POST["eventtype"])) //checks if any interest is checked
{
foreach($_POST["eventtype"] as $value) //Iterate the interest array and get the values
{
echo '<td>'.$value; //print the values
}
}
echo '</td> </tr>';
echo '</table>';
}
?>
Convert $_POST['eventtype'] into string:
if( isset( $_POST['eventtype'] ) && is_array( $_POST['eventtype'] )) {
$eventtypes = join( ',', $_POST['eventtype'] );
} else {
$eventtypes = '';
}
use $eventtypes in your INSERT.

Categories