auto submit or auto refresh the dropdown - javascript

I want to auto submit or auto refresh I'm not sure yet because I little bit confused.
I have three dropdown. Which the first two dropdown we select from a database to choose team A and team B from the database and the third dropdown is to display team A and team B - this is where I lost it. How can I view it when I do not submit the form yet?
here the my html code.
<form action="addmatch.php" method="post" >
<div class="match-form" >
<div class="match-row">
<label>
<a>Date</a>
<input type="date" name="matchdate" style="margin-left:-8px;" required>
</label>
</div>
<div class="match-row">
<label>
<a>Time</a>
<input type="time" name="matchtime" style="margin-left:-8px;" required>
</label>
</div>
<div class="match-row">
<label>
<a>Category</a>
<select name="category" size="1" style="margin-left:-30px;" required>
<option>select</option>
<?php
if($stmt=$conn->query("select * from categorymatch"))
{ while($r=$stmt->fetch_array(MYSQLI_ASSOC))
{ ?>
<option value=<?php echo $r['categoryId'] ?>><?php echo $r['categoryName'] ?></option>
<?php } } ?>
</select>
</label>
</div>
<div class="match-row">
<label>
<a>Team A </a>
<select name="teamA" size="1" style="margin-left:-24px;" onchange="submit" required>
<option>select</option>
<?php
if($stm=$conn->query("select TEAMLISTID, TEAMLISTNAME from teamlist"))
{ while($s=$stm->fetch_array(MYSQLI_ASSOC))
{ ?>
<option value=<?php echo $s['TEAMLISTID'] ?>><?php echo $s['TEAMLISTNAME'] ?></option>
<?php } } ?>
</select>
</label>
</div>
<div class="match-row">
<label>
<a>Team B </a>
<select name="teamB" size="1" style="margin-left:-24px;" onchange="submit" required>
<option>select</option>
<?php
if($stm=$conn->query("select TEAMLISTID, TEAMLISTNAME from teamlist"))
{ while($s=$stm->fetch_array(MYSQLI_ASSOC))
{ ?>
<option value=<?php echo $s['TEAMLISTID'] ?>><?php echo $s['TEAMLISTNAME'] ?></option>
<?php } } ?>
</select>
</label>
</div>
<div class="match-row">
<label>
<a>Handicap </a>
<select name="handicap" size="1" style="margin-left:-33px;" required>
<option>select</option>
<option>1:0</option>
<option>3/4:0</option>
<option>1/2:0</option>
<option>1/4:0</option>
<option>0:0</option>
<option>0:1/4</option>
<option>0:1/2</option>
<option>0:3/4</option>
</select>
</label>
</div>
<div class="match-row">
<label>
<a>Status Match </a>
<select name="statusmatch" size="1" style="margin-left:-57px;" required>
<option>select</option>
<?php
if($st=$conn->query("select * from statusmatch"))
{ while($a=$st->fetch_array(MYSQLI_ASSOC))
{ ?>
<option value=<?php echo $a['statusmatchId'] ?>><?php echo $a['statusmatchName'] ?></option>
<?php } } ?>
</select>
</label>
</div>
<div class="match-row">
<label>
<a>Tip Type </a>
<select name="tiptype" size="1" style="margin-left:-30px;" required>
<option>select</option>
<?php
if($stt=$conn->query("select * from tiptype"))
{ while($b=$stt->fetch_array(MYSQLI_ASSOC))
{ ?>
<option value=<?php echo $b['tiptypeId'] ?>><?php echo $b['tiptypeName'] ?></option>
<?php } } ?>
</select>
</label>
</div>
<div class="match-row">
<label>
<a>Tip </a>
<select name="tip" size="1" required>
<option>select</option>
<?php
if($stm=$conn->query("select teamA, teamb from matchlist"))
{ ?>
<option value=<?php ?>><?php echo $s['teamA'] ?></option>
<option value=<?php ?>><?php echo $s['teamb'] ?></option>
<?php } ?>
</select>
</label>
</div>
<div class="match-row">
<label>
<a>Score </a>
<input type="text" name="scoreteam" style="margin-left:-15px;">
</label>
</div>
<div class="match-row">
<label>
<a>Result </a>
<select name="result" size="1" style="margin-left:-19px;">
<option>select</option>
<option>Win</option>
<option>Loss</option>
<option>Draw</option>
</select>
</label>
</div>
<input type="submit" id="someText" value="Submit" style="margin-left:200px; margin-top:30px; margin-bottom:20px; padding:10px;">
</div>
</form>
can you help me solve problem?
Thanks!

Related

Add required attribute to Form after visible hide/show on form

The form has 3 group of fields that users can use to add their education background. The fastdropdown js is used to add more or show the hidden fields and I would like to make it required so long it is open / displayed on the form
<legend>Education:</legend>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Year_of_Degree">Year Of Degree *:</label>
<div class="col-sm-9">
<select name="Year_of_Degree" class="Year_of_Degree form-control fstdropdown-select" id="Year_of_Degree">
<option value="" <?php echo set_select('Year_of_Degree', ''); ?> >-Select-</option>
<?php for($year = 2019; $year >=1970; $year--){ ?>
<option value="<?php echo $year?>" <?php echo set_select('Year_of_Degree', $year); ?>><?php echo $year?></option>
<?php }?>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Class_of_Degree">Class Of Degree *:</label>
<div class="col-sm-9">
<select name="Class_of_Degree"class="Class_of_Degree form-control required" id="Class_of_Degree">
<option value="" <?php echo set_select('Class_of_Degree', ''); ?> >-Select-</option>
<option value="First Class Honours" <?php echo set_select('Class_of_Degree', 'First Class Honours'); ?> >First Class Honours</option>
<option value="Second Class Honours – Upper Division" <?php echo set_select('Class_of_Degree', 'Second Class Honours – Upper Division'); ?> >Second Class Honours – Upper Division</option>
<option value="Second Class Honours – Lower Division" <?php echo set_select('Class_of_Degree', 'Second Class Honours – Lower Division'); ?> >Second Class Honours – Lower Division</option>
<option value="Third Class Honours" <?php echo set_select('Class_of_Degree', 'Third Class Honours'); ?> >Third Class Honours</option>
<option value="Distinction" <?php echo set_select('Class_of_Degree', 'Distinction'); ?> >Distinction</option>
<option value="Upper Credit" <?php echo set_select('Class_of_Degree', 'Upper Credit'); ?> >Upper Credit</option>
<option value="Lower Credit" <?php echo set_select('Class_of_Degree', 'Lower Credit'); ?> >Lower Credit</option>
<option value="Merit" <?php echo set_select('Class_of_Degree', 'Merit'); ?> >Merit</option>
<option value="Pass" <?php echo set_select('Class_of_Degree', 'Pass'); ?> >Pass</option>
<option value="Fail" <?php echo set_select('Class_of_Degree', 'Fail'); ?> >Fail</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Institution">Institution *:</label>
<div class="col-sm-9">
<select name="Institution" class="Institution form-control fstdropdown-select" id="Institution">
<option value="" <?php echo set_select('Institution', ''); ?> >-Select-</option>
<?php if($institution_list){
foreach($institution_list as $institution){ ?>
<option value="<?php echo $institution->idinstitution?>" <?php echo set_select('Institution', $institution->idinstitution); ?>><?php echo $institution->institution?></option>
<?php }
}?>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Degree_Type">Degree Type *:</label>
<div class="col-sm-9">
<select name="Degree_Type"class="Degree_Type form-control required" id="Degree_Type">
<option value="" <?php echo set_select('Degree_Type', ''); ?> >-Select-</option>
<option value="OND" <?php echo set_select('Degree_Type', 'OND'); ?> >OND</option>
<option value="HND" <?php echo set_select('Degree_Type', 'HND'); ?> >HND</option>
<option value="Associate’s Degree" <?php echo set_select('Degree_Type', 'Associate’s Degree'); ?> >Associate’s Degree</option>
<option value="Bachelor’s Degree" <?php echo set_select('Degree_Type', 'Bachelor’s Degree'); ?> >Bachelor’s Degree</option>
<option value="Master’s Degree" <?php echo set_select('Degree_Type', 'Master’s Degree'); ?> >Master’s Degree</option>
<option value="Professional Degree" <?php echo set_select('Degree_Type', 'Professional Degree'); ?> >Professional Degree</option>
<option value="Doctorate Degree" <?php echo set_select('Degree_Type', 'Doctorate Degree'); ?> >Doctorate Degree</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Course_of_Study">Course Of Study *:</label>
<div class="col-sm-9">
<input type="text" name="Course_of_Study" placeholder="Course Of Study..." class="Course_of_Study form-control" id="Course_of_Study" value="<?php echo set_value('Course_of_Study', ''); ?>" >
</div>
</div>
<div id="qualification2" class="row-fluid">
<hr style="border: 1px solid #ccc;" />
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Year_of_Degree1">Year Of Degree :</label>
<div class="col-sm-9">
<select name="Year_of_Degree1" class="Year_of_Degree1 form-control fstdropdown-select" id="Year_of_Degree1">
<option value="" <?php echo set_select('Year_of_Degree1', ''); ?> >-Select-</option>
<?php for($year = 2019; $year >=1970; $year--){ ?>
<option value="<?php echo $year?>" <?php echo set_select('Year_of_Degree1', $year); ?>><?php echo $year?></option>
<?php }?>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Class_of_Degree1">Class Of Degree:</label>
<div class="col-sm-9">
<select name="Class_of_Degree1"class="Class_of_Degree1 form-control required" id="Class_of_Degree1">
<option value="" <?php echo set_select('Class_of_Degree1', ''); ?> >-Select-</option>
<option value="First Class Honours" <?php echo set_select('Class_of_Degree1', 'First Class Honours'); ?> >First Class Honours</option>
<option value="Second Class Honours – Upper Division" <?php echo set_select('Class_of_Degree1', 'Second Class Honours – Upper Division'); ?> >Second Class Honours – Upper Division</option>
<option value="Second Class Honours – Lower Division" <?php echo set_select('Class_of_Degree1', 'Second Class Honours – Lower Division'); ?> >Second Class Honours – Lower Division</option>
<option value="Third Class Honours" <?php echo set_select('Class_of_Degree1', 'Third Class Honours'); ?> >Third Class Honours</option>
<option value="Distinction" <?php echo set_select('Class_of_Degree1', 'Distinction'); ?> >Distinction</option>
<option value="Upper Credit" <?php echo set_select('Class_of_Degree1', 'Upper Credit'); ?> >Upper Credit</option>
<option value="Lower Credit" <?php echo set_select('Class_of_Degree1', 'Lower Credit'); ?> >Lower Credit</option>
<option value="Merit" <?php echo set_select('Class_of_Degree1', 'Merit'); ?> >Merit</option>
<option value="Pass" <?php echo set_select('Class_of_Degree1', 'Pass'); ?> >Pass</option>
<option value="Fail" <?php echo set_select('Class_of_Degree1', 'Fail'); ?> >Fail</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="institution1">Institution:</label>
<div class="col-sm-9">
<select name="institution1" class="institution1 form-control fstdropdown-select" id="institution1">
<option value="" <?php echo set_select('institution1', ''); ?> >-Select-</option>
<?php if($institution_list){
foreach($institution_list as $institution){ ?>
<option value="<?php echo $institution->idinstitution?>" <?php echo set_select('institution1', $institution->idinstitution); ?>><?php echo $institution->institution?></option>
<?php }
}?>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Degree_Type1">Degree Type:</label>
<div class="col-sm-9">
<select name="Degree_Type1"class="Degree_Type1 form-control required" id="Degree_Type1">
<option value="" <?php echo set_select('Degree_Type1', ''); ?> >-Select-</option>
<option value="OND" <?php echo set_select('Degree_Type1', 'OND'); ?> >OND</option>
<option value="HND" <?php echo set_select('Degree_Type1', 'HND'); ?> >HND</option>
<option value="Associate’s Degree" <?php echo set_select('Degree_Type1', 'Associate’s Degree'); ?> >Associate’s Degree</option>
<option value="Bachelor’s Degree" <?php echo set_select('Degree_Type1', 'Bachelor’s Degree'); ?> >Bachelor’s Degree</option>
<option value="Master’s Degree" <?php echo set_select('Degree_Type1', 'Master’s Degree'); ?> >Master’s Degree</option>
<option value="Professional Degree" <?php echo set_select('Degree_Type1', 'Professional Degree'); ?> >Professional Degree</option>
<option value="Doctorate Degree" <?php echo set_select('Degree_Type1', 'Doctorate Degree'); ?> >Doctorate Degree</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Course_of_Study1">Course Of Study:</label>
<div class="col-sm-9">
<input type="text" name="Course_of_Study1" placeholder="Course Of Study..." class="Course_of_Study1 form-control" id="Course_of_Study1" value="<?php echo set_value('Course_of_Study1', ''); ?>" >
</div>
</div>
</div>
<div id="qualification3" class="row-fluid">
<hr style="border: 1px solid #ccc;" />
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Year_of_Degree2">Year Of Degree:</label>
<div class="col-sm-9">
<select name="Year_of_Degree2" class="Year_of_Degree2 form-control fstdropdown-select" id="Year_of_Degree2">
<option value="" <?php echo set_select('Year_of_Degree2', ''); ?> >-Select-</option>
<?php for($year = 2019; $year >=1970; $year--){ ?>
<option value="<?php echo $year?>" <?php echo set_select('Year_of_Degree2', $year); ?>><?php echo $year?></option>
<?php }?>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Class_of_Degree2">Class Of Degree:</label>
<div class="col-sm-9">
<select name="Class_of_Degree2"class="Class_of_Degree2 form-control required" id="Class_of_Degree2">
<option value="" <?php echo set_select('Class_of_Degree2', ''); ?> >-Select-</option>
<option value="First Class Honours" <?php echo set_select('Class_of_Degree2', 'First Class Honours'); ?> >First Class Honours</option>
<option value="Second Class Honours – Upper Division" <?php echo set_select('Class_of_Degree2', 'Second Class Honours – Upper Division'); ?> >Second Class Honours – Upper Division</option>
<option value="Second Class Honours – Lower Division" <?php echo set_select('Class_of_Degree2', 'Second Class Honours – Lower Division'); ?> >Second Class Honours – Lower Division</option>
<option value="Third Class Honours" <?php echo set_select('Class_of_Degree2', 'Third Class Honours'); ?> >Third Class Honours</option>
<option value="Distinction" <?php echo set_select('Class_of_Degree2', 'Distinction'); ?> >Distinction</option>
<option value="Upper Credit" <?php echo set_select('Class_of_Degree2', 'Upper Credit'); ?> >Upper Credit</option>
<option value="Lower Credit" <?php echo set_select('Class_of_Degree2', 'Lower Credit'); ?> >Lower Credit</option>
<option value="Merit" <?php echo set_select('Class_of_Degree2', 'Merit'); ?> >Merit</option>
<option value="Pass" <?php echo set_select('Class_of_Degree2', 'Pass'); ?> >Pass</option>
<option value="Fail" <?php echo set_select('Class_of_Degree2', 'Fail'); ?> >Fail</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="institution2">Institution:</label>
<div class="col-sm-9">
<select name="institution2" class="institution2 form-control fstdropdown-select" id="institution2">
<option value="" <?php echo set_select('institution2', ''); ?> >-Select-</option>
<?php if($institution_list){
foreach($institution_list as $institution){ ?>
<option value="<?php echo $institution->idinstitution?>" <?php echo set_select('institution2', $institution->idinstitution); ?>><?php echo $institution->institution?></option>
<?php }
}?>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Degree_Type2">Degree Type:</label>
<div class="col-sm-9">
<select name="Degree_Type2"class="Degree_Type2 form-control required" id="Degree_Type2">
<option value="" <?php echo set_select('Degree_Type2', ''); ?> >-Select-</option>
<option value="OND" <?php echo set_select('Degree_Type2', 'OND'); ?> >OND</option>
<option value="HND" <?php echo set_select('Degree_Type2', 'HND'); ?> >HND</option>
<option value="Associate’s Degree" <?php echo set_select('Degree_Type2', 'Associate’s Degree'); ?> >Associate’s Degree</option>
<option value="Bachelor’s Degree" <?php echo set_select('Degree_Type2', 'Bachelor’s Degree'); ?> >Bachelor’s Degree</option>
<option value="Master’s Degree" <?php echo set_select('Degree_Type2', 'Master’s Degree'); ?> >Master’s Degree</option>
<option value="Professional Degree" <?php echo set_select('Degree_Type2', 'Professional Degree'); ?> >Professional Degree</option>
<option value="Doctorate Degree" <?php echo set_select('Degree_Type2', 'Doctorate Degree'); ?> >Doctorate Degree</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Course_of_Study2">Course Of Study:</label>
<div class="col-sm-9">
<input type="text" name="Course_of_Study2" placeholder="Course Of Study..." class="Course_of_Study2 form-control" id="Course_of_Study2" value="<?php echo set_value('Course_of_Study2', ''); ?>" >
</div>
</div>
</div>
<div class="row-fluid text-right" id="degreeBtn1">
<input type="button" class="addDegree2" value="+ Add Degree" />
<hr style="border: 1px solid #ccc;" />
</div>
<div class="row-fluid text-right" id="degreeBtn2">
<input type="button" class="addDegree3" value="+ Add Degree" />
<input type="button" class="removeDegree2" value="- Remove Degree" />
<hr style="border: 1px solid #ccc;" />
</div>
<div class="row-fluid text-right" id="degreeBtn3">
<input type="button" class="removeDegree3" value="- Remove Degree" />
<hr style="border: 1px solid #ccc;" />
</div>
i will appreciate if i can get someone that can show me how i can attach the required field attribute to the list of fields the moment it is visible on the form
You need the :required pseudo-class in CSS. For example:
/* style all input elements with a required attribute */
input:required {
box-shadow: 4px 4px 20px rgba(200, 0, 0, 0.85);
}
/**
* style input elements that have a required
* attribute and a focus state
*/
input:required:focus {
border: 1px solid red;
outline: none;
}
/**
* style input elements that have a required
* attribute and a hover state
*/
input:required:hover {
opacity: 1;
}
Taken from here: https://css-tricks.com/almanac/selectors/r/required/
Of course, you can create placeholders and stuff like that to enhance your design.
I interpreted "how i can attach the required field attribute to the list of fields the moment it is visible on the form" as when the element ( input ) gains visibility on screen rather than is just added to or un-hidden so perhaps the following might not be applicable I don't know. Essentially below PHP renders a long form to emulate the large form you have in the question -much of which will be off-screen when the page loads.
Initially the DOM is queried for a nodelist of input elements that do not have the required attribute and, if they are visible, sets the attribute. As the user scrolls the window.scroll event is fired and a new nodelist of elements without that attribute is checked - again, if they have visibility they are marked as required. The use of setTimeout is merely to allow time for actually observe the change from not required to required ( as denoted by the CSS colours )
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8' />
<title>Force "Required" attribute on form elements that have visibility</title>
<style>
body{height:100vh}
form{width:80%;float:none;margin:auto;height:100vh;}
label{width:100%; display:block; padding:3rem auto;}
input,
textarea{ padding:2rem; width:80%; margin:1rem; background:rgba(0,255,0,0.05); box-shadow: 0 0 15px rgba(0, 255, 0, 0.25); border-radius:1rem; }
input:required,
textarea:required{ background:rgba(255,0,0,0.05); box-shadow: 0 0 15px rgba(255, 0, 0, 0.25); border-radius:1rem; }
input:focus
,textarea:focus{outline:none}
</style>
<script>
let d=document;
let w=window;
let i=250;
d.addEventListener('DOMContentLoaded', ()=>{
const isvisible=function( n ){
let r=n.getBoundingClientRect();
let h=Math.max( d.documentElement.clientHeight, w.innerHeight );
return !( r.bottom < 0 || r.top - h >= 0 );
};
const setrequired=function(n){
setTimeout( ()=>{
n.required=true;
}, i );
};
let col=Array.from( d.querySelectorAll('form input:not( [required] ), form textarea:not( [required] )') );
col.forEach( n=>{ /* set initial state if element is visible on page load */
if( isvisible( n ) && !n.hasAttribute( 'required' ) ){
setrequired( n );
}
});
w.addEventListener( 'scroll', function(e){
Array.from( d.querySelectorAll('form input:not( [required] ), form textarea:not( [required] )') );
col.forEach( n=>{ /* check and set on page scroll */
if( isvisible( n ) && !n.hasAttribute( 'required' ) ){
setrequired( n );
}
});
});
});
</script>
</head>
<body>
<form>
<?php
/*
deliberately make tall form that will have many items not initially
visible but which become visible when the user scrolls the page up/down
*/
for( $i=1; $i < 100; $i++ )printf('<label>Field %1$d<input type="text" name="field%1$d" value="%1$d" /></label>', $i );
?>
</form>
</body>
</html>

3 dynamic combobox use php and jquery

Need help...
How if I want to make 3 select options use jquery,
Parent
Child
Grandchild
Can anyone help?
I will appreciate your help...
This is my code:
<?php
$parentQuery = $db->query("SELECT * FROM kategori WHERE parent = 0 ORDER BY nama_kategori");
$kategori = ((isset($_POST['parent']) && !empty($_POST['parent']))?sanitize($_POST['parent']):'');
?>
<div class="form-group col-md-3">
<label for="parent">Kategori 1:</label>
<select class="form-control" id="parent" name="parent">
<option value="" <?php echo (($kategori =='')?'selected':''); ?>> Select</option>
<?php while($p = mysqli_fetch_assoc($parentQuery)): ?>
<option value="<?php echo $p['id_kategori'];?>" <?php echo (($kategori == $p['id_kategori'])?'selected=':''); ?>>
<?php echo $p['nama_kategori'];?>
</option>
<?php endwhile; ?>
</select>
</div>
<div class="form-group col-md-3">
<label for="child">Kategori 2:</label>
<select class="form-control" name="child" id="child"></select>
</div>
<div class="form-group col-md-3">
<label for="child">Kategori 3:</label>
<select class="form-control" name="grandchild" id="grandchild"></select>
</div>

Show error alert when the data was exist

Can anybody help me to create the code for ..
I'm really a beginner for code.
This is the registration form. When I select noinduk then I select level it shows the error alert if the level of noinduk primary is exist. Like a unique level but it is based on 'noinduk'.
Thank you for help
This is my view
<select id="nis" name="nis" class="form-control" data-toggle="tooltip" data-trigger="hover" data-placement="top" data-title="NIS" value="<?php echo set_value("nis"); ?>">
<option value="none" selected="" disabled="">-- NIS --</option>
<?php
if ($nisnya) {
foreach($nisnya as $row) {
?>
<option value="<?php echo $row->kode; ?>"><?php echo $row->kode; ?></option>
<?php
}
}
?>
</select>
<div class="form-group col-md-3 mb-2">
<label for="projectinput3">Paket <span class="required">*</span></label>
<select id="issueinput5" name="level" class="form-control" data-toggle="tooltip" data-trigger="hover" data-placement="top" data-title="Level" value="<?php echo set_value("level"); ?>">
<option value="0" selected="" disabled="">-- Paket --</option>
<?php
if ($paketnya) {
foreach($paketnya as $row) {
?>
<option value="<?php echo $row->kode; ?>"><?php echo $row->nama; ?></option>
<?php
}
}
?>
</select>
</div>
this is my table

Dropdown list set put selected value from database

I am trying to create a drop down menu that will select a value that is stored in the database. Right now the code creates a dropdown with the first option selected. I have read through several tutorials, and tried to apply them, but I cannot get this working. I hope someone can help.
<div class="form-group">
<label>Up-to-Date</label>
<select class="form-control" name="uptodate"/>
<option value="Ja">Ja</option>
<option value="Nee">Nee</option>
</select>
</div>
Whole code :
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
include("../includes/connect.php");
if (isset($_SESSION['logged_in'])) {
if(isset($_POST['btnSlaOp'])) {
$id=$_POST['id'];
$uitgeleend=$_POST['uitgeleend'];
$nr=$_POST['nr'];
$model=$_POST['model'];
$serienummer=$_POST['serienummer'];
$capaciteit=$_POST['capaciteit'];
$uptodate=$_POST['uptodate'];
$persoon=$_POST['persoon'];
$datumuitgeleend=$_POST['datumuitgeleend'];
$datumretour=$_POST['datumretour'];
$opmerking=$_POST['opmerking'];
$sql="UPDATE ipads SET uitgeleend='$uitgeleend', nr='$nr', model='$model', serienummer='$serienummer', capaciteit='$capaciteit', uptodate='$uptodate', persoon='$persoon', datumuitgeleend='$datumuitgeleend', datumretour='$datumretour', opmerking='$opmerking' WHERE id='$id'";
$result=$db->query($sql);
header("location:overzicht-ipads.php");
} else if (isset($_POST['btnSlaOpInGs'])) {
$id=$_POST['id'];
$uitgeleend=$_POST['uitgeleend'];
$nr=$_POST['nr'];
$model=$_POST['model'];
$serienummer=$_POST['serienummer'];
$capaciteit=$_POST['capaciteit'];
$uptodate=$_POST['uptodate'];
$persoon=$_POST['persoon'];
$datumuitgeleend=$_POST['datumuitgeleend'];
$datumretour=$_POST['datumretour'];
$opmerking=$_POST['opmerking'];
$sql ="UPDATE ipads SET nr='$nr', model='$model', serienummer='$serienummer', capaciteit='$capaciteit', uptodate='$uptodate', persoon='$persoon', datumuitgeleend='$datumuitgeleend', datumretour='$datumretour', opmerking='$opmerking' WHERE id='$id'";
$sql .="INSERT INTO geschiedenis (SELECT * FROM ipads WHERE id='$id')";
$sql .="UPDATE ipads SET uitgeleend='Nee', persoon='', datumuitgeleend='', datumretour='', opmerking='' WHERE id='$id'";
$result=mysqli_multi_query($db, $sql);
header("location:overzicht-ipads.php");
}
if(isset($_GET['id'])) {
$id=$_GET['id'];
$sql="SELECT id, uitgeleend, nr, model, serienummer, capaciteit, uptodate, persoon, datumuitgeleend, datumretour, opmerking FROM ipads WHERE id='$id'";
$result=$db->query($sql);
$rij=$result->fetch_assoc();
$uitgeleend=$rij['uitgeleend'];
$nr=$rij['nr'];
$model=$rij['model'];
$serienummer=$rij['serienummer'];
$capaciteit=$rij['capaciteit'];
$uptodate=$rij['uptodate'];
$persoon=$rij['persoon'];
$datumuitgeleend=$rij['datumuitgeleend'];
$datumretour=$rij['datumretour'];
$opmerking=$rij['opmerking'];
include("../includes/get_header_wn.php");
?>
<h1 class="page-title">Wijzigen</h1>
<ul class="breadcrumb">
<li>Home </li>
<li class="active">Leen iPad <?php echo $nr ?></li>
</ul>
</div>
<form id="gegevensForm" class="col-xs-4" form method="POST" action="overzicht-ipads-edit.php">
<input type="hidden" name="id" value="<?php echo $id?>">
<div class="form-group">
<label>Uitgeleend</label>
<input type="text" class="form-control" name="uitgeleend" value="<?php echo $uitgeleend ?>" />
</div>
<div class="form-group">
<label>Nr</label>
<input type="text" class="form-control" name="nr" value="<?php echo $nr ?>" />
</div>
<div class="form-group">
<label>Model</label>
<input type="text" class="form-control" name="model" value="<?php echo $model ?>" />
</div>
<div class="form-group">
<label>Serienummer</label>
<input type="text" class="form-control" name="serienummer" value="<?php echo $serienummer ?>" />
</div>
<div class="form-group">
<label>Capaciteit</label>
<input type="text" class="form-control" name="capaciteit" value="<?php echo $capaciteit ?>" />
</div>
<div class="form-group">
<label>Up-to-Date</label>
<select class="form-control" name="uptodate"/>
<option value="Ja">Ja</option>
<option value="Nee">Nee</option>
</select>
</div>
<div class="form-group">
<label>Persoon</label>
<input type="text" class="form-control" name="persoon" value="<?php echo $persoon ?>" />
</div>
<div class="form-group">
<label>Datum uitgeleend</label>
<input type="text" id="datepicker" class="form-control" name="datumuitgeleend" value="<?php echo $datumuitgeleend ?>" />
</div>
<div class="form-group">
<label>Datum retour</label>
<input type="text" id="datepicker1" class="form-control" name="datumretour" value="<?php echo $datumretour ?>" />
</div>
<div class="form-group">
<label for="comment">Opmerking</label>
<textarea class="form-control" rows="5" id="comment" name="opmerking" /><?php echo $opmerking ?></textarea>
</div>
<button class="btn btn-primary pull-right" name="btnSlaOp" input type="submit"><i class="fa fa-save"></i> Opslaan</button>
<input type="button" name="btnCancel" value="Annuleer" class="btn btn-primary pull-left">
<button class="btn btn-primary pull-middle" name="btnSlaOpInGs" type="submit"><i class="fa fa-save"></i> Opslaan & Archiveren</button>
<?php
include('../includes/get_footer.php');
?>
</form>
<?php
}
} else {
header("location:overzicht-ipads.php");
}
?>
php: if($selectedVal == "yourVal") echo "selected";
e.g.:
<div class="form-group">
<label>Up-to-Date</label>
<select class="form-control" name="uptodate"/>
<option value="Ja" <?php if($selectedVal == "Ja") echo "selected";?>>Ja</option>
<option value="Nee" <?php if($selectedVal == "Nee") echo "selected";?>>Nee</option>
</select>
</div>
edit: in your case, replace $selectedVal with $uptodate

How to pass a variable from a page to other in php

I have a page *book_order*,which is used to add orders into a table *order_management*, where order_id is auto incremented in that table. once after submit this page i want the order_id to be passed to other page *book_order2* to add products under same order_id. For that i have created seperete *order_management2* table in which order_id is not auto-incremented.
My requirement is that i want to pass order_id from book_order page to book_order2 page and that variable is to be remembered till i do keep on adding....if i want to add new order, i will go to book_order page, else i will use book_order2 page.
book_order.php
<div class="grid_4">
<div class="da-panel">
<div class="da-panel-header">
<span class="da-panel-title">
<img src="images/icons/color/wand.png" alt="" />
<font face="Cambria" size="7" color="#009900"><b>Book Order</b></font>
</span>
</div>
<div class="da-panel-toolbar top">
<ul>
<li><div class="da-button blue large">View all Orders</div></li>
</ul>
</div>
<div class="da-panel-content">
<?php
if(isset($_POST['submit']))
{
extract($_POST);
$order_date=date("Y-m-d");
$sql=mysql_query("select sku,quantity_in_stock,sold_quantity,crdate from stock_info where product_name = '$prod'");
$array=mysql_fetch_array($sql);
$sku = $array[0];
$qis = $array[1];
$sold_quan = $array[2];
$crdate = $array[3];
$sql2=mysql_query("INSERT INTO order_management(order_date,brand,product,price,customer_name,phone_number,email,address,quantity,channel,courier,order_status,sku)
VALUES
('$order_date','$brand','$prod','$pri','$customername','$phonenumber', '$email','$address','$quantity','$channel','$courier','booked','$sku')");
if($sql2)
{
echo "<div class='da-message success'>Successfully Booked Your Order</div>";
?>
<script>
var r = confirm("want to add more products?");
if (r == true)
{
//x="You pressed OK!";
window.location = "main.php?page=book_order2";
}
else
{
//x="You pressed Cancel!";
window.location = "main.php";
}
</script>
<?php
}
else
{
die(mysql_error());
}
$quantity_left = $qis - $quantity;
$sold_quan = $sold_quan + $quantity;
$diff_in_days = (strtotime($order_date) - strtotime($crdate))/(60 * 60 * 24);
$expctd_stock=round((7*$quantity_left)/$diff_in_days);
//echo $expctd_stock;
$sql3 =mysql_query("UPDATE stock_info SET quantity_in_stock = '$quantity_left',last_sold_date='$order_date', sold_quantity='$sold_quan', expected_stock='$expctd_stock' WHERE sku='$sku'");
/*$sql3 = mysql_query("update order_management set sku='$sku' where order_date=''");*/
$sql4 =mysql_query("select order_id from order_management where sku='$sku'");
$idarray=mysql_fetch_array($sql4);
$id = $idarray[0];
//$_SESSION['id'] = $id;
}
?>
<form id="da-ex-validate1" class="da-form" method="post" action="">
<div class="da-form-row">
<label>Brand<span class="required">*</span></label>
<div class="da-form-item small">
<!--<input type="text" name="brand" id="brand" class="required" value=""/>-->
<select name="brand" id="brand" onChange="retrievedata(this.value)">
<option value="">--- select brand ---</option>
<?php
$ord=mysql_query("select * from brand_info");
while($ord1=mysql_fetch_array($ord))
{
?>
<option value="<?php echo $ord1['brand'];?>"><?php echo $ord1['brand'];?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="da-form-row">
<label>Product<span class="required">*</span></label>
<div class="da-form-item small">
<select name="prod" id="prod" onChange="retrievequantity(this.value)">
<option value="">--- select product ---</option>
</select>
</div>
</div>
<div class="da-form-row">
<label>Customer name<span class="required">*</span></label>
<div class="da-form-item small">
<input type="text" name="customername" id="customername" class="required char" value=""/>
</div>
</div>
<div class="da-form-row">
<label>Phone Number<span class="required">*</span></label>
<div class="da-form-item small">
<input type="text" name="phonenumber" id="phonenumber" class="required number" value=""/>
</div>
</div>
<div class="da-form-row">
<label>Email<span class="required">*</span></label>
<div class="da-form-item small">
<input type="text" name="email" id="email" class="required email" value=""/>
</div>
</div>
<div class="da-form-row">
<label>Address<span class="required">*</span></label>
<div class="da-form-item small">
<textarea name="address" id="address" class="required"></textarea>
</div>
</div>
<div class="da-form-row">
<label>Quantity<span class="required">*</span></label>
<div class="da-form-item small">
<select name="quantity" id="quantity">
<option value=""> --- select Quantity--- </option>
</select>
</div>
</div>
<div class="da-form-row">
<label>Total Price<span class="required">*</span></label>
<div class="da-form-item small">
<input type="text" name="pri" id="pri" class="required number" value=""/>
</div>
</div>
<div class="da-form-row">
<label>Courier<span class="required"></span></label>
<div class="da-form-item small">
<!--<input type="text" name="courier" id="courier" class="required" value=""/>-->
<select name="courier" id="courier">
<option value=""> ---select courier --- </option>
<?php
$ord=mysql_query("select courier_name from courier_info");
while($ord1=mysql_fetch_array($ord))
{
?>
<option value="<?php echo $ord1['courier_name'];?>"><?php echo $ord1['courier_name'];?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="da-form-row">
<label>Channel<span class="required"></span></label>
<div class="da-form-item small">
<!--<input type="text" name="channel" id="channel" class="required" value=""/>-->
<select name="channel" id="channel">
<option value=""> --- select channel ---</option>
<?php
$ord=mysql_query("select channel from channel_info");
while($ord1=mysql_fetch_array($ord))
{
?>
<option value="<?php echo $ord1['channel'];?>"><?php echo $ord1['channel'];?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="da-button-row">
<input type="submit" name="submit" value="submit" class="da-button grey" />
</div>
</fieldset>
</form>
</div>
<!-- End of .grid_4 --> </div>
</div>
<script>
function retrievedata(data)
{
var option_html = "";
<?php
$sql=mysql_query("SELECT distinct brand,product_name FROM stock_info");
while($ord1=mysql_fetch_array($sql))
{
?>
if(data == '<?php echo $ord1['brand']; ?>')
{
option_html += "<option><?php echo $ord1['product_name']; ?></option>";
/*alert(option_html);*/
}
<?php
}
?>
var par = document.getElementById("prod");
par.innerHTML = "<option>--- select product ---</option>"+option_html;
}
function retrievequantity(product)
{
var option_quantity_html = "";
<?php
$sql=mysql_query("SELECT product_name, quantity_in_stock FROM stock_info");
while($ord2=mysql_fetch_array($sql))
{
$i=1;
?>
if(product == '<?php echo $ord2['product_name']; ?>')
{
<?php
while($i<=intval($ord2['quantity_in_stock'])){?>
option_quantity_html += "<option><?php echo $i++; ?></option>";
<?php }?>
}
<?php
}
?>
var par = document.getElementById("quantity");
par.innerHTML = option_quantity_html;
}
</script>
book_order2.php
<?php /*?><?php
$id = $_SESSION['id'];
echo $id;
?><?php */?>
<?php
include("includes/db.php");
?>
<div class="grid_4">
<div class="da-panel">
<div class="da-panel-header">
<span class="da-panel-title">
<img src="images/icons/color/wand.png" alt="" />
<font face="Cambria" size="7" color="#009900"><b>Book Order</b></font>
</span>
</div>
<div class="da-panel-toolbar top">
<ul>
<li><div class="da-button blue large">View all Orders</div></li>
</ul>
</div>
<div class="da-panel-content">
<?php
if(isset($_POST['submit']))
{
extract($_POST);
$order_date=date("Y-m-d");
$sql=mysql_query("select sku,quantity_in_stock,sold_quantity,crdate from stock_info where product_name = '$prod'");
$array=mysql_fetch_array($sql);
$sku = $array[0];
$qis = $array[1];
$sold_quan = $array[2];
$crdate = $array[3];
$sql2=mysql_query("INSERT INTO order_management2(order_id,order_date,brand,product,price,customer_name,phone_number,email,address,quantity,channel,courier,order_status,sku)
VALUES
('$id','$order_date','$brand','$prod','$pri','$customername','$phonenumber', '$email','$address','$quantity','$channel','$courier','booked','$sku')");
if($sql2)
{
echo "<div class='da-message success'>Successfully Booked Your Order</div>";
?>
<script>
var r = confirm("want to add more products?");
if (r == true)
{
//x="You pressed OK!";
window.location = "main.php?page=book_order2";
}
else
{
//x="You pressed Cancel!";
window.location = "main.php";
}
</script>
<?php
}
else
{
die(mysql_error());
}
$quantity_left = $qis - $quantity;
$sold_quan = $sold_quan + $quantity;
$diff_in_days = (strtotime($order_date) - strtotime($crdate))/(60 * 60 * 24);
$expctd_stock=round((7*$quantity_left)/$diff_in_days);
//echo $expctd_stock;
$sql3 =mysql_query("UPDATE stock_info SET quantity_in_stock = '$quantity_left',last_sold_date='$order_date', sold_quantity='$sold_quan', expected_stock='$expctd_stock' WHERE sku='$sku'");
/*$sql3 = mysql_query("update order_management set sku='$sku' where order_date=''");*/
//$sql4 =mysql_query("select order_id from order_management where sku='$sku'");
//$idarray=mysql_fetch_array($sql4);
}
?>
<form id="da-ex-validate1" class="da-form" method="post" action="">
<div class="da-form-row">
<label>Brand<span class="required">*</span></label>
<div class="da-form-item small">
<!--<input type="text" name="brand" id="brand" class="required" value=""/>-->
<select name="brand" id="brand" onChange="retrievedata(this.value)">
<option value="">--- select brand ---</option>
<?php
$ord=mysql_query("select * from brand_info");
while($ord1=mysql_fetch_array($ord))
{
?>
<option value="<?php echo $ord1['brand'];?>"><?php echo $ord1['brand'];?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="da-form-row">
<label>Product<span class="required">*</span></label>
<div class="da-form-item small">
<select name="prod" id="prod" onChange="retrievequantity(this.value)">
<option value="">--- select product ---</option>
</select>
</div>
</div>
<div class="da-form-row">
<label>Customer name<span class="required">*</span></label>
<div class="da-form-item small">
<input type="text" name="customername" id="customername" class="required char" value=""/>
</div>
</div>
<div class="da-form-row">
<label>Phone Number<span class="required">*</span></label>
<div class="da-form-item small">
<input type="text" name="phonenumber" id="phonenumber" class="required number" value=""/>
</div>
</div>
<div class="da-form-row">
<label>Email<span class="required">*</span></label>
<div class="da-form-item small">
<input type="text" name="email" id="email" class="required email" value=""/>
</div>
</div>
<div class="da-form-row">
<label>Address<span class="required">*</span></label>
<div class="da-form-item small">
<textarea name="address" id="address" class="required"></textarea>
</div>
</div>
<div class="da-form-row">
<label>Quantity<span class="required">*</span></label>
<div class="da-form-item small">
<select name="quantity" id="quantity">
<option value=""> --- select Quantity--- </option>
</select>
</div>
</div>
<div class="da-form-row">
<label>Total Price<span class="required">*</span></label>
<div class="da-form-item small">
<input type="text" name="pri" id="pri" class="required number" value=""/>
</div>
</div>
<div class="da-form-row">
<label>Courier<span class="required"></span></label>
<div class="da-form-item small">
<!--<input type="text" name="courier" id="courier" class="required" value=""/>-->
<select name="courier" id="courier">
<option value=""> ---select courier --- </option>
<?php
$ord=mysql_query("select courier_name from courier_info");
while($ord1=mysql_fetch_array($ord))
{
?>
<option value="<?php echo $ord1['courier_name'];?>"><?php echo $ord1['courier_name'];?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="da-form-row">
<label>Channel<span class="required"></span></label>
<div class="da-form-item small">
<!--<input type="text" name="channel" id="channel" class="required" value=""/>-->
<select name="channel" id="channel">
<option value=""> --- select channel ---</option>
<?php
$ord=mysql_query("select channel from channel_info");
while($ord1=mysql_fetch_array($ord))
{
?>
<option value="<?php echo $ord1['channel'];?>"><?php echo $ord1['channel'];?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="da-button-row">
<input type="submit" name="submit" value="submit" class="da-button grey" />
<?php /*?><a href="book_order2.php?&id=<?php echo $id; ?>" name="submit" value="submit" class="da-button grey">Book Order</a<?php */?>
</div>
</fieldset>
</form>
</div>
<!-- End of .grid_4 --> </div>
</div>
<script>
function retrievedata(data)
{
var option_html = "";
<?php
$sql=mysql_query("SELECT distinct brand,product_name FROM stock_info");
while($ord1=mysql_fetch_array($sql))
{
?>
if(data == '<?php echo $ord1['brand']; ?>')
{
option_html += "<option><?php echo $ord1['product_name']; ?></option>";
/*alert(option_html);*/
}
<?php
}
?>
var par = document.getElementById("prod");
par.innerHTML = "<option>--- select product ---</option>"+option_html;
}
function retrievequantity(product)
{
var option_quantity_html = "";
<?php
$sql=mysql_query("SELECT product_name, quantity_in_stock FROM stock_info");
while($ord2=mysql_fetch_array($sql))
{
$i=1;
?>
if(product == '<?php echo $ord2['product_name']; ?>')
{
<?php
while($i<=intval($ord2['quantity_in_stock'])){?>
option_quantity_html += "<option><?php echo $i++; ?></option>";
<?php }?>
}
<?php
}
?>
var par = document.getElementById("quantity");
par.innerHTML = option_quantity_html;
}
</script>
You can store the order number in the session. This way, it will be protected and persisted across pages.
When you insert the order in book_order.php, store it in the session:
$sql2=mysql_query(....); // inserting
if($sql2){
$_SESSION['order_id'] = mysql_insert_id();
}
Now, in book_order2.php you can retrieve the order ID before you do the insert of the product:
$id = $_SESSION['order_id'];
// insert product with order_id = $id
In order to use PHP sessions, you must calll session_start() at the beginning of any script that makes use of the session. If you have a global/header include then you can do it there.
Side notes:
mysql_* is deprecated. Consider upgrading to PDO or MySQLi. This is a good PDO tutorial, especially if you're upgrading from mysql_*.
Use a Prepared Statement with bound parameters instead of concatenating variables into SQL.
I would use ajax. For example:
$(document).ready(function()
{
$("form").on('submit',function(event)
{
event.preventDefault();
data = "var=data";
$.ajax
({
type: "GET",
url: "parser.php",
data: data
}).done(function(msg)
{
alert(msg);
});
});
});
It will send GET into parser.php. And the data field would be data in $_GET['var']

Categories

Resources