I have this php code
<div class="form-group box">
<div class="col-lg-7">
<?php
foreach ($results as $row) {
echo '<select class="form-control" required name="article[]">
<option value="'.$row->articles_id.'">'.$row->article_name.'</option>';
$sql="SELECT * FROM articles WHERE article_active = 1";
$query = $this->db->query($sql);
$articles = $query->result();
foreach ($articles as $row){
echo'
<option value="'.$row->articles_id.'">'.$row->article_name.'</option>';
}
echo'</select>';
}
?>
</div>
<div class="col-lg-3">
<?php foreach ($results as $row) {
echo '<input class="form-control kolicina" type="text" value="'.$row->order_qty.'" name="qty[]" '.$disabled.' required/>'; }
?>
</div>
<div class="col-lg-2">
<?php foreach ($results as $row) {
echo'<button type="button" class="btn btn-danger button-remove">Remove</button>';
}
?>
</div>
</div>
When display this i got this HTML code
<div class="col-lg-7">
<select class="form-control" required="" name="article[]">
<option value="10">Cipiripi</option>
<option value="8">Koka Kola</option>
<option value="10">Cipiripi</option>
</select>
<select class="form-control" required="" name="article[]">
<option value="8">Koka Kola</option>
<option value="8">Koka Kola</option>
<option value="10">Cipiripi</option>
</select>
</div>
<div class="col-lg-3">
<input class="form-control kolicina" value="44" name="qty[]" required="" type="text">
<input class="form-control kolicina" value="44" name="qty[]" required="" type="text">
</div>
<div class="col-lg-2">
<button type="button" class="btn btn-danger button-remove">Remove</button>
<button type="button" class="btn btn-danger button-remove">Remove</button>
</div>
I have tried a lot ways with loop, to get proper code, this is example hos html should look?
<div class="form-group box">
<div class="col-lg-7">
<select class="form-control" required="" name="article[]">
<option value="10">Cipiripi</option>
<option value="8">Koka Kola</option>
<option value="10">Cipiripi</option>
</select>
</div>
<div class="col-lg-3">
<input class="form-control kolicina" value="44" name="qty[]" required="" type="text">
</div>
<div class="col-lg-2">
<button type="button" class="btn btn-danger button-remove">Remove</button>
</div>
</div>
<div class="form-group box">
<div class="col-lg-7">
<select class="form-control" required="" name="article[]">
<option value="8">Koka Kola</option>
<option value="8">Koka Kola</option>
<option value="10">Cipiripi</option>
</select>
</div>
<div class="col-lg-3">
<input class="form-control kolicina" value="44" name="qty[]" required="" type="text">
</div>
<div class="col-lg-2">
<button type="button" class="btn btn-danger button-remove">Remove</button>
</div>
</div>
What i need that loops goes in different wrapper, not in in same col?
This is working fiddle how it has to look
http://jsfiddle.net/ckqth4a7/
And this is what i have now
http://jsfiddle.net/q0njhgfk/
No, just ditch that inner foreach loops inside just build it by the whole row.
Something like:
<?php foreach($results as $row): ?> <!-- loop this as a whole row -->
<div class="form-group box">
<div class="col-lg-7">
<select class="form-control" required="" name="article[]">
<?php
// this is the only loop for the options inside the select
$sql = "SELECT * FROM articles WHERE article_active = 1";
$query = $this->db->query($sql);
$articles = $query->result();
?>
<?php foreach($articles as $article): ?>
<option value="<?php echo $article->articles_id; ?>"><?php echo $article->article_name; ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-lg-3">
<input class="form-control kolicina" value="<?php echo $row->order_qty; ?>" name="qty[]" required="" type="text">
</div>
<div class="col-lg-2">
<button type="button" class="btn btn-danger button-remove">Remove</button>
</div>
</div>
<?php endforeach; ?>
Or maybe, if the query is just standing there and will not be dynamic take it off the parent loop.
<?php
// take this outside, its always the same anyway, so that it queries only once
// this is the only loop for the options inside the select
$sql = "SELECT * FROM articles WHERE article_active = 1";
$query = $this->db->query($sql);
$articles = $query->result();
?>
<?php foreach($results as $row): ?> <!-- loop this as a whole row -->
<div class="form-group box">
<div class="col-lg-7">
<select class="form-control" required="" name="article[]">
<?php foreach($articles as $article): ?>
<option value="<?php echo $article->articles_id; ?>"><?php echo $article->article_name; ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-lg-3">
<input class="form-control kolicina" value="<?php echo $row->order_qty; ?>" name="qty[]" required="" type="text">
</div>
<div class="col-lg-2">
<button type="button" class="btn btn-danger button-remove">Remove</button>
</div>
</div>
<?php endforeach; ?>
Related
I have 3 php files and I want to get the month from form1.php for form3.php but the thing is, it needs to be processed in form2.php as well, how can I just get the month from form1 and display it in form3?
form1.php
<form action="form2.php" method="post">
<div class="form-title">
<p class="display-6">Salary Calculator (Part 1)</p>
</div>
<div class="form-subtitle">
<p>Employee Information</p>
</div>
<div class="form-row">
<div class="form-row-child">
<label for="inputPlaceholder4">Employee Name</label>
<select class="form-select" aria-label="Default select example" name="displayName" id="displayName">
<option selected>Select Employee</option>
<?php while($row = $result->fetch_assoc()) { ?>
<option value="<?php echo $row['displayName']; ?>"><?= $row["displayName"] ?></option>
<?php }; ?>
</select>
</div>
<div class="form-row-child">
<label for="inputPlaceholder4">Month</label>
<select class="form-select" aria-label="Default select example" name="month" id="month">
<option selected disabled>Select Month</option>
<option value="January">January</option>
<option value="Febuary">Febuary</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select>
</div>
</div>
<div class="form-row">
<div class="form-row-child">
<input type="submit" class="btn btn-danger form1-btn" value="Proceed">
</div>
<div class="form-row-child">
</div>
</div>
</form>
form2.php
<form action="form3.php" method="post">
<div class="form-title">
<p class="display-6">Salary Calculator (Part 2)</p>
</div>
<div class="half-form">
<div class="half-form-left">
<div class="half-form-subtitle">
<p>Holidays</p>
</div>
<div class="half-form-child">
<label for="inputPlaceholder3">Regular (Per day)</label>
<select class="form-select" aria-label="Default select example" name="holidayReg" id="holidayReg">
<?php foreach ($regHolidays as $value) { ?>
<option value="<?php echo $value; ?>"><?= $value ?></option>
<?php }; ?>
</select>
</div>
<div class="half-form-child">
<label for="inputPlaceholder3">Special (Per day)</label>
<select class="form-select" aria-label="Default select example" name="holidaySpec" id="holidaySpec">
<?php foreach ($specHolidays as $value) { ?>
<option value="<?php echo $value; ?>"><?= $value ?></option>
<?php }; ?>
</select>
</div>
</div>
<div class="half-form-right">
<div class="half-form-subtitle">
<p>Overtime</p>
</div>
<div class="half-form-child">
<label for="inputPlaceholder3">Normal (Per hour)</label>
<input type="Placeholder" class="form-control" id="overtimeHoursNormal" placeholder="Placeholder" name="overtimeHoursNormal">
</div>
<div class="half-form-child">
<label for="inputPlaceholder3">Rest Day (Per hour)</label>
<input type="Placeholder" class="form-control" id="overtimeHoursSpecial" placeholder="Placeholder" name="overtimeHoursSpecial">
</div>
</div>
</div>
<div class="half-form">
<div class="half-form-left">
<div class="half-form-subtitle">
<p>Absences</p>
</div>
<div class="half-form-child">
<label for="inputPlaceholder3">Day/s absent</label>
<input type="Placeholder" class="form-control" id="absences" placeholder="Placeholder" name="absences">
</div>
</div>
<div class="half-form-right">
<input type="Placeholder" class="form-control" id="basePay" name="basePay" style="display: none;" value="<?php echo $vagueEmployee->getBasePay(); ?>">
<input type="Placeholder" class="form-control" id="workingHours" name="workingHours" style="display: none;" value="<?php echo $vagueEmployee->getWorkingHours(); ?>">
<input type="Placeholder" class="form-control" id="salaryPerHour" name="salaryPerHour" style="display: none;" value="<?php echo $salaryPerHour; ?>">
<input type="Placeholder" class="form-control" id="payFor13thMonth" name="payFor13thMonth" style="display: none;" value="<?php echo $payFor13thMonth; ?>">
</div>
</div>
<div class="form-row">
<div class="form-row-child">
<input type="submit" class="btn btn-danger form1-btn" value="Proceed">
</div>
<div class="form-row-child">
</div>
</div>
</form>
form3.php
<main class="main">
<div class="form-title">
<p class="display-6">Employee Salary</p>
</div>
<div class="">
<p>Pay after additions: Php <?php echo $payAfterAdditions; ?></p>
<p>Deductions</p>
<p>Philhealth: Php <?php echo $philhealth; ?></p>
<p>SSS: Php <?php echo $sss; ?></p>
<p>Total deductions: Php <?php echo $totalDeductions; ?></p>
<p>Taxable Salary: Php <?php echo $taxableSalary; ?></p>
<p>Final Salary: Php <?php echo $finalTax; ?></p>
<!-- lalabas lang kapag december -->
<p>13 month pay: </p>
<p> <?php echo $totalAbsences; ?></p>
<p> <?php echo $basePay; ?></p>
</div>
</main>
In form 2
Add the following field inside the form
<input type=hidden name=month value="<?php echo $_POST["month"]; ?>">
Then in form 3, you can use $_POST["month"] to access the month value.
`<div class="tab-content">
<div class="row">
<div class="col-lg-6">
<form method="post" data-toggle="modal" enctype="multipart/form-data" action="data/pegawai/proses.php">
<div class="form-group">
<label>NIP</label>
<input class="form-control" name="nip" type="text" value="<?php echo $r['nip'];?>" readonly="">
</div>
<div class="form-group">
<label>Nama Lengkap</label>
<input class="form-control" type="text" value="<?php echo $r['nm_pegawai'];?>" name="nama" placeholder="Nama Lengkap" autofocus="" required="">
</div>
<div class="form-group">
<label>Jenis Kelamin</label>
<div class="radio">
<label class="radio-inline">
<input type="radio" name="jk" id="optionsRadiosInline1" value="Laki-laki" <?php $ob->cek("Laki-laki",$r['jenis_kelamin'],"radio") ?>>Laki-laki
</label>
<label class="radio-inline">
<input type="radio" name="jk" id="optionsRadiosInline2" value="perempuan" <?php $ob->cek("Perempuan",$r['jenis_kelamin'],"radio") ?>>perempuan
</label>
</div>
</div>
<div class="form-group">
<label>Tempat Lahir</label>
<input class="form-control" type="text" value="<?php echo $r['tempat_lahir'];?>" name="tmp_lahir" placeholder="Tempat Lahir" required="">
</div>
<div class="form-group">
<label>Tanggal Lahir</label>
<input type="date" name="tgl_lahir" value="<?php echo $r['tanggal_lahir'];?>" class="form-control" placeholder="Tanggal Lahir" required="">
</div>
<div class="form-group">
<label>Agama</label>
<select class="form-control" name="agama" required="">
<option <?php $ob->cek("Islam",$r['agama'],"select") ?> value="Islam">Islam</option>
<option <?php $ob->cek("Kristen",$r['agama'],"select") ?> value="Kristen">Kristen</option>
<option <?php $ob->cek("Katholik",$r['agama'],"select") ?> value="Katholik">Katholik</option>
<option <?php $ob->cek("Protestan",$r['agama'],"select") ?> value="Protestan">Protestan</option>
<option <?php $ob->cek("Hindu",$r['agama'],"select") ?> value="Hindu">Hindu</option>
<option <?php $ob->cek("Budha",$r['agama'],"select") ?> value="Budha">Budha</option>
</select>
</div>
<div class="form-group">
<label>Alamat</label>
<textarea class="form-control" name="alamat" rows="3" placeholder="Alamat Lengkap" required=""><?php echo $r['alamat'];?></textarea>
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label>Nomor Telepon</label>
<input class="form-control" type="text" value="<?php echo $r['no_telp'];?>" name="telp" onkeypress="return isNumberKey(event)" maxlength="15" placeholder="Nomor telepon" required="">
</div>
<div class="form-group">
<label>Tahun Masuk</label>
<input class="form-control" type="text" value="<?php echo $r['tahun_masuk'];?>" name="thn_masuk" placeholder="Tahun Masuk" onkeypress="return isNumberKey(event)" maxlength="4" required="">
</div>
<div class="form-group">
<label>Bagian</label>
<select class="form-control" name="bagian" required="">
<option <?php $ob->cek("Teller",$r['bagian'],"select") ?> value="Teller">Teller</option>
<option <?php $ob->cek("CSO",$r['bagian'],"select") ?> value="CSO">CSO</option>
<option <?php $ob->cek("BO",$r['bagian'],"select") ?> value="BO">BO</option>
</select>
</div>
<div class="form-group">
<label>Cabang</label>
<?php
echo '<select class="form-control" name="cabang" required="">';
$query=mysql_query("
SELECT *
FROM bank");
while($entry1=mysql_fetch_array($query))
{
echo "<option";
if($entry1['kd_bank']==$r['kd_bank']){echo " selected=selected";}
echo " value='".$entry1['kd_bank']."'>" . $entry1['nm_bank'] . "</option>";
}
echo "</select>";
?>
</div>
<div class="form-group">
<label>Kata Sandi</label>
<input class="form-control" type="password" value="<?php echo $r['password']?>" name="password" placeholder="Kata Sandi">
</div>
</div>
<!-- /.col-lg-6 (nested) -->
</div>
<!-- /.row (nested) -->
<div class="modal-footer">
<button type="button" name="ubah" class="btn btn-primary">Ubah</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</form>
</div> `
my source code, my button cannot active, how to solving it?
Thank you
Pandhu
Make your button type as "submit" like below.
<button type="submit" name="ubah" class="btn btn-primary">Ubah</button>
Else you can also keep it as button, but in that case u need to use ajax(javascript) and onclick event on button , for example :
<button type="button" name="ubah" class="btn btn-primary" onclick="save()">Ubah</button>
where save() is some function in javascript that you will create to save the form data.
i have this html form
<div class="box box-info">
<div class="box-header with-border">
<h3 class="box-title">Please Input Below Information</h3>
</div>
<!-- /.box-header -->
<!-- form start -->
<form method="POST" action="model.php" class="form-horizontal">
<div class="box-body">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Model Code *</label>
<div class="col-sm-10">
<input type="text" name="ModelCode" class="form-control" id="inputEmail3" placeholder="e.g KTI">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Model Name *</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="ModelName" id="inputPassword3" placeholder="e.g 0002">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Model Units *</label>
<div class="col-sm-10">
<select class="form-control" name="ModelUnit" style="width: 100%;">
<option value="" selected disabled>Choose Model Unit</option>
<?php
$sql = mysqli_query($con, "select departmentname from department");
while ($row = mysqli_fetch_array($sql)) {
?>
<option value="<?php echo $row['departmentname']; ?>"><?php echo $row['departmentname']; ?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Model Hour Theroy *</label>
<div class="col-sm-10">
<select class="form-control" name="ModelHourT" style="width: 100%;">
<option value="" selected disabled>Choose Model Hour</option>
<?php
$sql = mysqli_query($con, "select GroupTeory from grouptheory");
while ($row = mysqli_fetch_array($sql)) {
?>
<option value="<?php echo $row['GroupTeory']; ?>"><?php echo $row['GroupTeory']; ?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Model Hour Practice *</label>
<div class="col-sm-10">
<select class="form-control" name="ModelHourP" style="width: 100%;">
<option value="" selected disabled>Choose Model Practice</option>
<?php
$sql = mysqli_query($con, "select GroupPractical from grouppractical");
while ($row = mysqli_fetch_array($sql)) {
?>
<option value="<?php echo $row['GroupPractical']; ?>"><?php echo $row['GroupPractical']; ?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Model Type *</label>
<div class="col-sm-10">
<input type="text" name="ModelType" class="form-control" id="inputEmail3" placeholder="e.g KTI">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Semister *</label>
<div class="col-sm-10">
<select class="form-control" style="width: 100%;" name="SemsterID">
<option value="" selected disabled>Choose Model Type</option>
<?php
$sql = mysqli_query($con, "select Semester from semester");
while ($row = mysqli_fetch_array($sql)) {
?>
<option value="<?php echo $row['Semester']; ?>"><?php echo $row['Semester']; ?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<input type="submit" name="submit" class="btn btn-info pull-right" value="Submit" />
</div>
<!-- /.box-footer -->
</form>
</div>
and this is my php insert function
include("Connection.php");
if(isset($_POST['submit']))
{
echo "<script>alert($query1)</script>";
$ModelCode = mysqli_real_escape_string($con,$_POST['ModelCode']);
$ModelName = mysqli_real_escape_string($con,$_POST['ModelName']);
$ModelUnit = mysqli_real_escape_string($con,$_POST['ModelUnit']);
$ModelHourT =mysqli_real_escape_string($con,$_POST['ModelHourT']);
$ModelHourP = mysqli_real_escape_string($con,$_POST['ModelHourP']);
$ModelType = mysqli_real_escape_string($con,$_POST['ModelType']);
$SemsterID = mysqli_real_escape_string($con,$_POST['SemsterID']);
$query1 = mysqli_query($con, "INSERT INTO 'model' (ModelCode,ModelName,ModelUnit,ModelHourTheory,ModelHourPractical,ModelType,StageID) VALUES ('$ModelCode','$ModelName','$ModelUnit','$ModelHourT','$ModelHourP','$ModelType' ,'$SemsterID')");
echo "<script>alert($query1)</script>";
}
and it doesn't work .... i didn't no what's happen !! even i have been compare fields of the table with the name of the database ... but it still doesn't work ... anyone knows what is problem ?
You don't should use single quote for table name (in this case single quote is for literal value )
Assuming that you table is named model you should use
$query1 = mysqli_query($con,
"INSERT INTO model (ModelCode, ModelName,ModelUnit,
ModelHourTheory,ModelHourPractical,ModelType,StageID)
VALUES ('$ModelCode','$ModelName','$ModelUnit',
'$ModelHourT','$ModelHourP','$ModelType','$SemsterID')");
I have an advanced form that looks like this:
I am using a template from Bootsnipp which contains my code, and am trying to adjust it - available here.
My method of doing search is to append values to specific URL parameters based on the search, and then further down in the PHP code, check if those parameters are blank or contain values, and then execute code which fetches auctions from a database.
Since I started playing around to do this, the "Filter By State" buttons are not filling in the states filters from the database (the only thing that appears is the blank option), and also my search buttons (with the eyeglass icons) have disappeared. No idea why as this was working before. Note I am using PDO. Here is HTML and PHP code for the filter section:
<!-- Page Content -->
<div class="container">
<!--This is the search bar-->
<div class="container">
<div class="row">
<div class="col-sm-12">
<!-- http://stackoverflow.com/questions/8476602/appending-get-parameters-to-url-from-form-action-->
<!--If this is a form it messes up the styling-->
<div method="get" class="input-group" id="adv-search" action="listings.php">
<input type="text" name="q" class="form-control"
placeholder="Search for auctions by name or description" value=""/>
<div class="input-group-btn">
<div class="btn-group" role="group">
<div class="dropdown dropdown-lg">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
aria-expanded="false"><span class="caret"></span></button>
<div class="dropdown-menu dropdown-menu-right" role="menu">
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="filter">Sort By</label>
<select class="form-control" name="sort" value="by_lowest_time">
<!-- By default by lowest time remaining-->
<option value="by_lowest_time" selected>Lowest Time Remaining</option>
<option value="by_highest_time">Highest Time Remaining</option>
<option value="by_lowest_price">Lowest Price</option>
<option value="by_highest_price">Highest Price</option>
</select>
</div>
<div class="form-group">
<label for="filter">Filter by Category</label>
<?php
try {
$catsql = 'SELECT * FROM ebay_clone.Category';
$catq = $db->query($catsql);
$catq->setFetchMode(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
?>
<select class="form-control" name="cat">
<option value=""></option>
<!-- http://stackoverflow.com/questions/3078192/how-to-set-html-value-attribute-with-spaces-using-php-->
<?php while ($r = $catq->fetch()): ?>
<option
value="<?php echo str_replace(' ', '_', strtolower(htmlspecialchars($r['item_category']))); ?>"> <?php echo htmlspecialchars($r['item_category']) ?></option>
<?php endwhile; ?>
</select>
</div>
<div class="form-group">
<label for="filter">Filter by State</label>
<?php
try {
// error_reporting(E_ERROR | E_PARSE);
$statsql = 'SELECT * FROM ebay_clone.State';
$statq = $db->query($statsql);
$statq->setFetchMode(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
?>
<select class="form-control" name="state">
<!-- Blank option-->
<option value=""></option>
<?php while ($r = $statq->fetch()): ?>
<option value="<?php echo trimstr_replace(' ', '_', strtolower(htmlspecialchars($r['state']))); ?>"> <?php echo htmlspecialchars($r['state']) ?> </option>
<?php endwhile; ?>
</select>
</div>
<button type="button" value="search" class="btn btn-primary"><span
class="glyphicon glyphicon-search" aria-hidden="true"></span></button>
</form>
</div>
</div>
<button type="button" class="btn btn-primary"><span class="glyphicon glyphicon-search"
aria-hidden="true"></span></button>
</div>
</div>
</div>
</div>
</div>
</div>
Your while loop fills a $row variable
<?php while ($row = $statq->fetch()): ?>
But you are using $r to read it:
$r['state']
I have figured this out. It was to do with me changing my SQL statement and reassigning a new SQL statement to a new query. Also, I didn't need to refer to my database name, only the table within the database.
This works now:
<!--This is the search bar-->
<div class="container">
<div class="row">
<div class="col-sm-12">
<!-- http://stackoverflow.com/questions/8476602/appending-get-parameters-to-url-from-form-action-->
<!--If this is a form it messes up the styling-->
<div class="input-group" id="adv-search">
<form method='get' action='listings.php'>
<input type="text" name="q" class="form-control"
placeholder="Search for auctions by name or description" value=""/>
</form>
<div class="input-group-btn">
<div class="btn-group" role="group">
<div class="dropdown dropdown-lg">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
aria-expanded="false"><span class="caret"></span></button>
<div class="dropdown-menu dropdown-menu-right" role="menu">
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="filter">Sort By</label>
<select class="form-control" name="sort" value="by_lowest_time">
<!-- By default by lowest time remaining-->
<option value="by_lowest_time" selected>Lowest Time Remaining
</option>
<option value="by_highest_time">Highest Time Remaining</option>
<option value="by_lowest_price">Lowest Price</option>
<option value="by_highest_price">Highest Price</option>
</select>
</div>
<!-- Item Category -->
<div class="form-group">
<label for="filter">Filter by Category</label>
<select class="form-control" id="item-category" name="cat"
class="form-control">
<option value="" selected disabled hidden>Please Select a Category
</option>
<?php $sql = 'SELECT * FROM Category';
foreach ($db->query($sql) as $row) { ?>
<option
value="<?php echo $row['item_category']; ?>"><?php echo htmlspecialchars($row['item_category']); ?></option>
<?php } ?>
</select>
</div>
<!-- Item State -->
<div class="form-group">
<label for="filter">Filter by State</label>
<select class="form-control" id="item-state" name="state"
class="form-control">
<option value="" selected disabled hidden>Please Select a
Condition
</option>
<?php $sql = 'SELECT * FROM State';
foreach ($db->query($sql) as $row) { ?>
<option
value="<?php echo $row['state']; ?>"><?php echo htmlspecialchars($row['state']); ?></option>
<?php } ?>
</select>
</div>
<button type="submit" action="listings.php" method="get" value="search"
class="btn btn-primary"><span
class="glyphicon glyphicon-search" aria-hidden="true"></span>
</button>
</form>
</div>
</div>
<button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-search"
aria-hidden="true"></span></button>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
include('include/connection.php');
session_start();
$_SESSION['verify_remote_agent']=$_SERVER['HTTP_USER_AGENT'];
$r=session_id();
if(isset($next)) {
$city=$_POST['city'];
$from_city=$_POST['from_city'];
$to_city=$_POST['to_city'];
$query="INSERT INTO user_details values('$r','$city',$from_city,'$to_city')";
mysql_query($query);
}
?>
<div class="container">
<form action="index2.php" method="POST">
<div class="form-group city col-sm-4">
<select class="form-control" name="city">
<option value="choose">Choose City</option>
<option value="option[1]">Delhi/NCR</option>
<option value="others">Other</option>
</select>
</div>
<div class="form-group from_city col-sm-4">
<input type="text" class="form-control" name="from_city" placeholder="From Area">
</div>
<div class="form-group to_city col-sm-4">
<input type="text" class="form-control" name="to_city" placeholder="To Area">
</div>
<p class="text-right">
<input class="btn btn-primary" type="submit" value="Next Step" name="next">
</p>
</form>
</div>
Try this:
$query="INSERT INTO user_details values('".$r."','".$city."','".$from_city."','".$to_city."')";
mysql_query($query);