i want to ask why my combobox not indexed?
here is a code
<form method="post" action="../php/proses-list-maintenance.php">
<p style="font-size:15px; font-family:Coda; color:black;">Pilih Aplikasi :</p>
<select name="comboapp" class="form-control">
<?php foreach ($list_app as $app) : ?>
<option value="<?php echo $app['application_id'] ?>"><?php echo $app['application_name'] ?></option>
<?php endforeach ?>
</select>
<button type="submit" class="btn btn-success">Pilih</button>
</form>
and here is action code
include '../koneksi.php';
$id = $_POST['comboapp'];
$query = "select * from application where application_id = '$id'";
$hasil = mysqli_query($db, $query);
$data_app = mysqli_fetch_assoc($hasil);
$query2 = "SELECT * FROM maintenance where maintenance_id = '$id'";
$hasil2 = mysqli_query($db, $query2);
if ($hasil == true && $hasil2 == true) {
echo "<script>location.href='../admin/list-maintenance.php?aaa='+$id</script>";
$data_app = array();
while ($row = mysqli_fetch_assoc($hasil)) {
$data_app[] = $row;
}
$data_man = array();
while ($row = mysqli_fetch_assoc($hasil2)) {
$data_man[] = $row;
}
}
and when I run, I got this notice
undefined index: comboapp
when the combo box is selected and the button is clicked. I want the data id's in the combo box enter the data into $id
Related
PHP code
<?php
include("connect.php")
$activityid = "select activity.activity_name,activity.activity_id
from activity
join serviceactivitymap on activity.activity_id = serviceactivitymap.activity_id
where serviceactivitymap.service_id = 1";
$activityvalue = $conn->query($activityid) or die ($conn>error.__LINE__);
$activities = [];
while ($row = $activityvalue->fetch_assoc()) {
$activities[] = $row;
}
$serviceid = "select * from service";
$servicevalue = $conn->query($serviceid) or die ($conn->error.__LINE__);
$services = [];
while ($row = $servicevalue->fetch_assoc()) {
$services[] = $row;
}
foreach ($services as $service):
?>
<form action = "index.php method = "post">
<input name='serviceone[]' data-toggle="modal" data-target="#myModal" type='checkbox' data-id='Incometax' value="<?php echo $service['service_id']?>"/><?php echo $service['service_name']?>
<br>
<?php foreach ($activities as $activity):?>
<input name='activityone[]' data-toggle="modal" data-target="#myModal" type='checkbox' data-id='Incometax' value="<?php echo $activity['activity_id']?>"/><?php echo $activity['activity_name']?>
<br>
<?php endforeach ?>
<?php endforeach ?>
</form>
Output of the code is :
Incometax
Revised filling
Return filling
Gst
Revised filling
Return filling
Tds
Revised filling
Return filling
I have 3 tables services, activity, serviceactivitymap
where I store service_id, service_name in services and activity_id, activity_name in activity and service_id and related activity_id inserviceactivitymapbut i dont know how to display related activities under services.
serviceactivitymap` table structure is
Incometax
Revised filling
Return filling
Gst
Tax Payment
Statutory Audit
Tds
Internal Audit
Stock Audit
Can I display it like this?
<?php include("connect.php")?>
<?php
$activityid = "select activity.activity_name,activity.activity_id
from activity
join serviceactivitymap on activity.activity_id = serviceactivitymap.activity_id
where serviceactivitymap.service_id = 1";
$activityvalue = $conn->query($activityid) or die ($conn>error.__LINE__);
$activities = [];
while ($row = $activityvalue->fetch_assoc()) {
$activities[] = $row;
}
$serviceid = "select * from service";
$servicevalue = $conn->query($serviceid) or die ($conn->error.__LINE__);
$services = [];
while ($row = $servicevalue->fetch_assoc()) {
$services[] = $row;
}
foreach ($services as $service):
?>
<form action = "index.php" method = "post">
<input name='serviceone[]' data-toggle="modal" data-target="#myModal" type='checkbox' data-id='Incometax' value="<?php echo $service['service_id']?>"/><?php echo $service['service_name']?>
<br>
<?php foreach ($activities as $activity):?>
<input name='activityone[]' data-toggle="modal" data-target="#myModal" type='checkbox' data-id='Incometax' value="<?php echo $activity['activity_id']?>"/><?php echo $activity['activity_name']?>
<br>
<?php endforeach ?>
<?php endforeach ?>
</form>
There you go. You are missing a closing quotation mark at form action
I want to retain the value that I selected after form submission.
<select name="student[]" class="selectpicker" multiple title="Click here.." data-width="auto" data-live-search="true" required>
<?php
if (isset($_POST['submit'])){
$selected = $_POST['studname'];
$qry = "Select studtbl.stud_id,concat(studtbl.fname,' ',
substring(studtbl.mname, 1,1),'. ',studtbl.lname) as Name from studtbl";
$result = mysqli_query($conn, $qry);
while($row = mysqli_fetch_array($result))
{
extract($row);
echo '<option value="'.$stud_id.'" '.(($stud_id ==
$selected)? 'selected="selected"':"" >'.$Name.'</option>';
}
}else{
$qry = "Select studtbl.stud_id,concat(studtbl.fname,' ',
substring(studtbl.mname, 1,1),'. ',studtbl.lname) as Name from studtbl";
$result = mysqli_query($conn, $qry);
while($row = mysqli_fetch_array($result))
{
extract($row);
echo '<option value="'.$stud_id.'" >'.$Name.'</option>';
}
}
?>
</select>
<input type='submit' class="btn btn-primary" name='submit' value='Create
Account' />
My problem is it is not retaining after submitting
<select name="student[]" class="selectpicker" multiple title="Click here.." data-width="auto" data-live-search="true" required>
<?php
if (isset($_POST['submit'])){
$selected = $_POST['student']; // <---- multi-selects come in as Array
$qry = "Select studtbl.stud_id,concat(studtbl.fname,' ',
substring(studtbl.mname, 1,1),'. ',studtbl.lname) as Name from studtbl";
$result = mysqli_query($conn, $qry);
while($row = mysqli_fetch_array($result))
{
extract($row);
// if the current ID is inside the POST-ed Array - mark as SELECTED
echo '<option value="'.$stud_id.'" '.(in_array($stud_id, $selected) ? 'selected="selected"': "").'>'.$Name.'</option>';
}
}else{
$qry = "Select studtbl.stud_id,concat(studtbl.fname,' ',
substring(studtbl.mname, 1,1),'. ',studtbl.lname) as Name from studtbl";
$result = mysqli_query($conn, $qry);
while($row = mysqli_fetch_array($result))
{
extract($row);
echo '<option value="'.$stud_id.'" >'.$Name.'</option>';
}
}
?>
</select>
<input type='submit' class="btn btn-primary" name='submit' value='Create
Account' />
In my database I have 2 tables:
To insert data, I have a form that populates dropdown options from the table formulation. This is what the insert form for formulation dropdown looks like:
<?php
$formulation = '';
$query = "SELECT * FROM formulation";
$result = mysqli_query($connect, $query);
while ($row = mysqli_fetch_array($result)) {
$formulation .= '<option value="' . $row["formulationID"] . '">' . $row["formulation_name"] . '</option>';
}
?>
<select>
<option value="">Select formulation</option>
<?php echo $formulation; ?>
</select>
Now I am working on the ‘Update’ form. But my question is how can I populate the ‘Formulation’ field dropdown with the data from the formulation table (like as the insert form) but pre-selected with the existing formulation value for the name from the items table? Like this image below:
I am having problem with how I should build the form. How should I proceed with this form?
<?php
$output = array('data' => array());
$sql = "SELECT * FROM items";
$query = $connect->query($sql);
while ($row = $query->fetch_assoc()) {
$output['data'][] = array(
$row['name'],
);
}
echo json_encode($output);
?>
<form action=" " method="POST">
<div>
<label>Name</label>
<input type="text"><br>
<label>Formulation</label>
<select >
<!--What should be the codes here? -->
</select>
</div>
<button type = "submit">Save changes</button>
</form>
Thanks in advance for your suggestion.
Note: I'm not a user of mysqli so maybe there will be some error, but you will get the idea. This will not tackle the update part, just the populate part
Since you are editing a certain item, I will assume that you have something to get the item's itemID.
<?php
$sql = "SELECT * FROM items WHERE itemID = ?";
$query = $connect->prepare($sql);
$query->bind_param("s", $yourItemID);
$query->execute();
$result = $query->fetch_assoc();
$itemName = $result['name'];
$itemFormulation = $result['formulation_fk'];
//now you have the name and the formulation of that certain item
?>
<form action=" " method="POST">
<div>
<label>Name</label>
<input type="text" value="<?php echo $itemName; ?>"><br>
<label>Formulation</label>
<select >
<?php
$query = "SELECT * FROM formulation";
$result = mysqli_query($connect, $query);
while ($row = mysqli_fetch_array($result)) {
?>
<option value="<?php echo $row['formulationID']; ?>" <?php echo ($row['formulationID'] == $itemFormulation) ? 'selected' : ''; ?>>
<?php echo $row['formulation_name']; ?>
</option>
<?php
}
?>
</select>
</div>
<button type = "submit">Save changes</button>
</form>
I changed the code to better suit the problem, there may be typos, just comment for clarification
If I have understand Your question... You have to put Your result into a string. For example:
<?php
$output = array('data' => array());
$sql = "SELECT * FROM items";
$query = $connect->query($sql);
$option = '';
while ($row = $query->fetch_assoc()) {
$name=$row['name'],
$option.='<option value="$name">$name</option>'
}
echo json_encode($output);
?>
<form action=" " method="POST">
<div>
<label>Name</label>
<input type="text"><br>
<label>Formulation</label>
<select >
<?=$option?>
</select>
</div>
<button type = "submit">Save changes</button>
</form>
I hope to be of help
This should do the trick:
<?php
$itemsSql = "SELECT * FROM items WHERE itemId = 5";
$itemQuery = $connect->query($sql);
$item = $itemQuery->fetch_assoc();
$formulationsSql = "SELECT * FROM formulation";
$formulationsQuery = $connect->query($sql);
$formulations = $itemQuery->fetch_assoc();
?>
<form action="updateItem" method="POST">
<div>
<label>Item Name</label>
<input type="text" value="<?= $item[0]['name']; ?>"><br>
<label>Formulation</label>
<select>
<?php foreach($formulations as $formulation){
echo '<option value="'. $formulation['formulationId'].'">' .
$formulation['formulation_name'] . '</option>';
} ?>
</select>
</div>
<button type = "submit">Save changes</button>
</form>
I have a table with id, header, etc. Would like to make a give a name from header column to dropdown list to each value. Now its only shows value, which is very uncomfortable :
<form method="POST" enctype="multipart/form-data" action ="uploadext.php">
<?php require_once('uploadext.php'); ?>
<div class="col-md-6"><input type="file" name="fileToUploadgp"></div>
<div class="col-md-6"><input type="file" name="fileToUploadpro"><br>
<?php
$dbc = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
$query = "SELECT id, header FROM done_add";
$query1="SELECT header FROM done_add";
$data = mysqli_query($dbc, $query);
$data1=mysqli_query($dbc, $query1);
$array=[];
while ($row = mysqli_fetch_array($data)) {
$arrayid[] = $row['id'];
$arrayhead[]=$row['header'];
}
?>
<select name="selectlink">
<?php foreach ($arrayid as $arr) {?>
<option value = "<?php print($arr)?>"
} ?><?php print($arr) ?></option>
<?php } ?>
</select>
<input type="submit" value="Отправить файлы" name="submita">
</div>
</form>
(sorry for bad english)
change the way you store your data in $array:
while ($row = mysqli_fetch_array($data)) {
$option = [];
$option['id'] = $row['id'];
$option['header'] = $row['header']
$array[] = $option;
}
every $option in $array will have and id and a header, then you can simply:
<select name="selectlink">
<?php foreach ($array as $option) {?>
<option value = "<?php echo $option['id'];?>"
} ?><?php echo $option['header'];?></option>
<?php } ?>
</select>
I'm trying to do a select from a table based on the post value of an HTML select box. I'm getting no results at all, I'm echoing out the post value no problem. The statement works on it's own but won't when I use the select form to populate it. This is just my test I will be adding other options to the dropdown box.
<?php
if(isset($_POST['value'])) {
if($_POST['value'] == 'Militaria') {
$query = "SELECT * FROM listings WHERE category1=Militaria";
}
else {
// query to get all records
$query = "SELECT * FROM listings";
}
}
$sql = mysql_query($query);
while ($row = mysql_fetch_array($query)){
echo 'Description:' . $row['description'];
}
mysql_close($con);
?>
Here is the html form I'm using, can anyone tell me where I'm going wrong, should I do it a different way etc, I'm new to php? Thanks!!
<form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post' name='form_filter' >
<select name="value">
<option value="all">All</option>
<option value="Militaria">Militaria</option>
</select>
<br />
<input type='submit' value = 'Filter'>
</form>
mysql_fetch_array() should receive resorce as a parameter. Try mysql_fetch_array($sql).
Quote around 'Militaria' and mysql_fetch_array($sql)
<?php
if(isset($_POST['value'])) {
if($_POST['value'] == 'Militaria') {
$query = "SELECT * FROM listings WHERE category1='Militaria'";
}
else {
// query to get all records
$query = "SELECT * FROM listings";
}
$sql = mysql_query($sql);
while ($row = mysql_fetch_array($sql)){
echo 'Description:' . $row['description'];
}
mysql_close($con);
}
?>
<form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post' name='form_filter' >
<select name="value">
<option value="all">All</option>
<option value="Militaria">Militaria</option>
</select>
<br />
<input type='submit' value = 'Filter'>
</form>
You have two mistakes in your php code.
1st : quote around Militaria. The query should be, $query = "SELECT * FROM listings WHERE category1='Militaria'";
2nd : mysql_fetch_array accepts executed query's result as parameter. It should be, $row = mysql_fetch_array($sql)
Final code:
<?php
if(isset($_POST['value'])) {
if($_POST['value'] == 'Militaria') {
$query = "SELECT * FROM listings WHERE category1 = 'Militaria'";
}
else {
// query to get all records
$query = "SELECT * FROM listings";
}
}
$sql = mysql_query($query);
while ($row = mysql_fetch_array($sql)){
echo 'Description:' . $row['description'];
}
mysql_close($con);
?>