I need to make a edit / update function based from searching ticket number. When user type a ticket number he had, would appear a form that contains data from database based on ticket number that he had.I can see name value, ticket number value and date value from database but I can't see a clock time value in select tag.
<?php
$no = $_GET['ticket'];
$st = "SELECT * FROM event WHERE no='$no'";
$check = mysql_query($st,$connection) or die("Failed");
$c = mysql_fetch_array($check);
?>
<form name="form" method="POST" action="">
<table>
<tr>
<td>Reference Number</td>
<td> : </td>
<td>
<input type="text" name="no" value="<?php echo $c['no'] ;?>" disabled>
<input type="hidden" name="no" value="<?php echo $c['no'] ;?>">
</td>
</tr>
<tr>
<td>Name</td>
<td> : </td>
<td>
<input type="text" name="name" value="<?php echo $c['name'] ;?>" disabled>
<input type="text" name="name" value="<?php echo $c['name'] ;?>" disabled>
</td>
</tr>
<tr>
<td>Date</td>
<td> : </td>
<td>
<input type="text" id="date" name="date" value="<?php echo $c['date'] ;?>">
</td>
</tr>
<tr>
<td>Clock Time</td>
<td> : </td>
<td>
<select name="time" value="<?php echo $c['time'] ;?>">
</td>
</tr>
I want to see the clock time value on database in select tag. After that, if user want to make changes on clock time based on the date he chosen, he can do that thing.
Thanks before,
The stucture of drop down in htm is
<select name ="postname">
<option value="postvalue"> display value</option>
more options
.
.
.
.
</select>
use following code in your case
<select name="postname" >
<option value="<?php echo $c['date'] ;?>" > <?php echo $c['date'] ;?> </option>
</select>
select tags must have options. you need to popuate the select tag with options and then check it against your value to set the selected option.
this method is wrong <select name="time" value="<?php echo $c['date'] ;?>">
<select name="time">
<?php foreach($options as $option) { ?>
<?php $sel = ''; if ($option->value = $c['date']) { $sel = 'selected'; } ?>
<option value="<?php echo $option->value; ?>" <?php echo $sel; ?>><?php echo $option->name; ?></option>
<?php } ?>
</select>
put your select like this:-
<select name="time" >
<option value=value="<?php echo $c['date'] ;?>" selected > <?php echo $c['date'] ;?> </option>
</select>
Related
I have a HTML/PHP form that needs validation of each of the entered fields before updating MySQL database. It would be nice if this cold be done as each field is entered...however, I could use the form's action attribute to run a different validation script but then if there are errors I would need to return to the form and re-populate it with previously entered data for correction - not sure how I would do all this but I guess it's possible. However, I've seen a post here that shows how this can be done with a javascript function for the validation but is this possible to do in PHP? I'm just learning PHP so I'd hate to now have to also learn javascript :( Some guidance appreciated.
<?php
if(isset($_POST)) {
echo __LINE__ . " Form has been posted <br>";
echo __LINE__ . $_POST['state_city'];
}
?>
<form action="" method="post">
<table border="0" align="center">
<tr height="29px" width = "220px">
<td>
<label for="student_id"><b>Student-ID</b></label>
</td>
<td>
<input type="text" placeholder="Student ID" name="studentid" value="<?php echo $row['studentid'];?>" required>
</td>
</tr>
<tr height="29px" width = "220px">
<td>
<label for="student_name"><b>Student name</b></label>
</td>
<td>
<input type="text" placeholder="Student name" name="name" value="<?php echo $row['$studentname'];?>" required>
</td>
</tr>
<tr height="29px" width = "220px"><td><label for="start_date"><b>Start Date</b></label></td>
<td><input type="date" placeholder="Enter start date" name="start_date" value="<?php echo $row['startdate'];;?>" required></td>
</tr>
<tr height="29px"><td width = "220px">
<b>Student Grade</b></td>
<td>
<select name="sgrade" id="sgrade">
<option value="1" <?php if ($row['$sgrade'] == '1') echo "selected"; ?>>Grade 1<option>
<option value="2" <?php if ($row['$sgrade'] == '2') echo "selected"; ?>>Grade 2<option>
<option value="3" <?php if ($row['$sgrade'] == '3') echo "selected"; ?>>Grade 3<option>
<option value="4" <?php if ($row['$sgrade'] == '4') echo "selected"; ?>>Grade 4<option>
</select>
</td>
<tr>
// value?
<tr height="29px"><td width = "220px"><b>Country of Birth</b></td>
<td>
<select name="country" id="country">
<?php
$sql = "SELECT * FROM countries";
$result = mysqli_query($con, $sql);
?>
<?php
while ($row = mysqli_fetch_array($result)) {
echo "<option value='" . $row['id'] . "'>" . $row['name'] . "</option>";
}
?>
</select>
<?php
mysqli_free_result($result);
mysqli_close($con);
?>
</td>
</tr>
<tr height="29px" width = "220px">
<td><label for="state_city"><b>State and/or main city</b></label></td>
<td><input type="text" placeholder="Student State and/or Main City" name="state_city" value="<?php echo $row['$state_city'];?>" required></td>
</tr>
<tr height="29px" width = "220px">
<td><label for="healthcheck"><b>Checked?</b></label></td>
<td>
<input type="radio" id="checkyes" name="check" value="1" <?php if ($row['check']) echo "checked";?>>
<label for="checkyes"> Yes</label><br>
<input type="radio" id="checkno" name="check" value="0" <?php if (!$row['check']) echo "checked";?>>
<label for="checkno"> No</label><br><br>
</td>
</tr>
</table>
<button type="submit">Save</button>
<div class="container" style="background-color:#f1f1f1">
<button type="button" onclick="history.back()" value="Go back!" class="cancelbtn">Cancel</button>
</div>
</form>
<script>
function check() {
document.getElementById("checkyes").checked = true;
}
function uncheck() {
document.getElementById(hcheckyes").checked = false;
}
</script>
</body>
</html>
If you want it to be dynamic as the user enters the information you will have to use JavaScript as that would be a front-end solution. With PHP you can do you validation/sanitizing of the data on the server-side as the form is submitted. It is suggested you do both.
For your question of repopulating this is one way
<input type="text" name="name" value="<?php echo htmlspecialchars($_POST['name'] ?? '', ENT_QUOTES); ?>">
For more info : click here
I want to make multiple radio-button on my CodeIgniter webapps, but this value is null after I submit my form.
This is my view on codeigniter apps
<?php $no=0; foreach ($catsub_1_isi as $list2_1a_1a): $no++ ?>
<form role="form" method="post" action="<?php echo base_url('c_QA_roe/simpan_list'); ?>">
<input type="hidden" name="WSDetailID[]" value="<?php echo $kode_detail;?>" class="form-control">
<input type="hidden" name="WSHeaderID[]" value="<?php echo $judul->WSHeaderID;?>" class="form-control">
<input type="hidden" name="AppDate[]" value="<?php $tgl=date('Y-m-d-H-i-s'); echo $tgl; ?>" class="form-control">
<input type="hidden" name="InputDate[]" value="<?php $tgl=date('Y-m-d-H-i-s'); echo $tgl; ?>" class="form-control">
<input type="hidden" name="InputUser[]" value="<?php echo $UserName; ?>" class="form-control">
<input type="hidden" name="WSListID[]" value="<?php echo $list2_1a_1a->WSListID;?>" class="form-control">
<tr>
<td><?php echo $no;?></td>
<td><?php echo $list2_1a_1a->Subject;?></td>
<td><?php echo $list2_1a_1a->Standard;?></td>
<td align="center">
<div class="radio">
<input type="text" name="YesNo[<?php echo $list2_1a_1a->WSListID;?>]" value="0">
<input type="radio" name="YesNo[<?php echo $list2_1a_1a->WSListID;?>]" class="minimal" value="<?php echo $list2_1a_1a->Value;?>" checked>Y
<input type="text" name="YesNo[<?php echo $list2_1a_1a->WSListID;?>]" value="0">
<input type="radio" name="YesNo[<?php echo $list2_1a_1a->WSListID;?>]" class="minimal" value="<?php echo $list2_1a_1a->Value;?>">N
</div>
</td>
<td align="center">
<select name="IsRedudance[]">
<option value="0">-</option>
<option value="<?php echo $list2_1a_1a->Value;?>">Yes</option>
</select>
</td>
<td align="center">
<select name="IsUse[]">
<option value="YES">Yes</option>
<option value="NO">No</option>
</select>
</td>
</tr>
<?php endforeach;?>
This is my controller on codeigniter apps
public function simpan_list()
{
$WSDetailID = $this->input->post('WSDetailID[]');
$WSHeaderID = $this->input->post('WSHeaderID[]');
$WSListID = $this->input->post('WSListID[]');
$IsYes = $this->input->post('IsYes[]');
$IsNo = $this->input->post('IsNo[]');
$IsRedudance = $this->input->post('IsRedudance[]');
$IsUse = $this->input->post('IsUse[]');
$AppDate = $this->input->post('AppDate[]');
$InputDate = $this->input->post('InputDate[]');
$InputUser = $this->input->post('InputUser[]');
$Yes = $this->input->post('YesNo[]');
$No = $this->input->post('YesNo[]');
$data = array();
$index = 0;
foreach($WSDetailID as $datanis)
{
array_push($data, array(
'WSDetailID' =>$datanis,
'WSHeaderID' =>$WSHeaderID[$index],
'WSListID' =>$WSListID[$index],
'IsYes' =>$Yes[$index],
'IsNo' =>$No[$index],
'IsRedudance' =>$IsRedudance[$index],
'IsUse' =>$IsUse[$index],
'AppDate' =>$AppDate[$index],
'InputDate' =>$InputDate[$index],
'InputUser' =>$InputUser[$index],
));
$index++;
var_dump($data['IsYes']);
}
}
on my controller i'am confused about POST data on $YesNo especialy variable for multiple radio-button, so I tried to make post('YesNo[]') Is this true? but the value is still null
there is no checkbox. but if you want to post the value of checkboxes. you can post this way.
//view
<input type="checkbox" name="active" placeholder="Active" checked >
//controller
'field_name' => ($this->input->post('field_name') == "true") ? 1 : 0;
i am trying to update multiple data in both rows and columns in my table where client_id = '5' and invoice_number = '11'
My Table tbl_particulars
My code:
<table class="table table-bordered">
<tr>
<th>Date</th>
<th>Car No.</th>
<th>Particulars</th>
<th>Rate</th>
<th>Amount</th>
</tr>
<?php
$sql = "SELECT * FROM tbl_particulars WHERE client_id = '5' AND invoice_number = '11'";
$query = mysql_query($sql);
while($row = mysql_fetch_assoc($query)) {
?>
<tr>
<td width="200px" nowrap="nowrap"><table>
<tr>
<td>From<br>
<input type="hidden" name="numbers" value="3">
<input type="hidden" name="ids[]" value="<?php echo $row['id'] ?>">
<input type="text" name="date_from[]" value="<?php echo $row['date_from'] ?>" class="form-control" placeholder="DD/MM/YYYY"></td>
<td> </td>
<td>To<br>
<input type="text" name="date_to[]" value="<?php echo $row['date_to'] ?>" class="form-control" placeholder="DD/MM/YYYY"></td>
</tr>
</table></td>
<td width="100px"><input type="text" name="car_no[]" value="<?php echo $row['car_no'] ?>" class="form-control"></td>
<td width="250px"><table>
<tr>
<td><select name="particulars[]" class="form-control">
<option value="">--Please Select ur Duty--</option>
<option value="Local 80 Kms. & 8.00 Hrs. Duty" <?php if($row['particulars']=="Local 80 Kms. & 8.00 Hrs. Duty") echo 'selected="selected"'; ?> >Local 80 Kms. & 8.00 Hrs. Duty</option>
<option value="Upto" <?php if($row['particulars']=="Upto") echo 'selected="selected"'; ?>>Upto</option>
<option value="Extra Kms." <?php if($row['particulars']=="Extra Kms.") echo 'selected="selected"'; ?>>Extra Kms.</option>
<option value="Extra Hrs." <?php if($row['particulars']=="Extra Hrs.") echo 'selected="selected"'; ?> >Extra Hrs.</option>
<option value="Local Nights" <?php if($row['particulars']=="Local Nights") echo 'selected="selected"'; ?> >Local Nights</option>
<option value="Parking Toll Tax" <?php if($row['particulars']=="Parking Toll Tax") echo 'selected="selected"'; ?> >Parking Toll Tax</option>
<option value="Out Station" <?php if($row['particulars']=="Out Station") echo 'selected="selected"'; ?> >Out Station</option>
</select></td>
<td style="vertical-align:text-top !important"> # </td>
<td width="100px"><input type="text" value="<?php echo $row['quantity'] ?>" name="quantity[]" class="form-control"></td>
</tr>
</table></td>
<td width="80px"><input type="text" name="rate[]" class="form-control" value="<?php echo $row['rate'] ?>" onChange="CalcGST()"></td>
<td width="80px"><input type="text" name="amount[]" class="form-control" value="<?php echo $row['amount'] ?>" onChange="CalcGST()"></td>
</tr>
<?php } ?>
<tr>
<td colspan="5"><button type="submit" name="update_invoicee" class="btn btn-info">Save & Continue</button></td>
</tr>
</table>
</div>
</form>
My Php Script:
<?php if(isset($_POST['update_invoicee'])){
$s = "UPDATE `tbl_particulars` SET";
for($i=0;$i<$_REQUEST['numbers'];$i++)
{
$s .="(
date_from='".$_REQUEST['date_from'][$i]."',
date_to='".$_REQUEST['date_to'][$i]."',
car_no='".$_REQUEST['car_no'][$i]."',
particulars='".$_REQUEST['particulars'][$i]."',
quantity='".$_REQUEST['quantity'][$i]."',
rate='".$_REQUEST['rate'][$i]."',
amount='".$_REQUEST['amount'][$i]."' WHERE id='".$_REQUEST['ids'][$i]."'),";
}
$s = rtrim($s,",");
if(!mysql_query($s))
echo mysql_error();
else
echo "<script>alert('Records Updated')</script>";
} ?>
now script does not work gives below error:
Erreur de syntaxe pr�s de '( date_from='newvalue', date_to='newvalue', car_no='newvalue' � la ligne 1
The syntax error you received is due to "(" symbol after the SET keyword. It does not allow set multiple statements with more than one SET or WHERE in one query (MySQL Reference).
It is possible to put conditional expressions to every field and concatenate query string for all received ids (some example). But it will be really too much - one additional loop for every field and complex code to format this query (think about writing, debugging, reviewing and supporting it in future).
My Selectbox Items from aircraft table
<select name="selectaircraft">
<option id="0">-- Select Aircraft -- </option>
<?php
require("dbc.php");
$getallaircraft = mysql_query("SELECT * FROM aircrafttable");
while($viewallaircraft = mysql_fetch_array($getallaircraft)){
?>
<option id="<?php echo $viewallaircraft['ID']; ?>">
<?php echo $viewallaircraft['aircraft'] ?> </option>
<?php } ?>
</select>
hi guys im trying to use the the value of selectaircraft to search and display the result to textbox.. here is my code so far
<?php
require("dbc.php");
$getallconfig = mysql_query("SELECT * FROM aircrafttable WHERE aircraft LIKE 'PR200'");
while($viewallconfig= mysql_fetch_array($getallconfig)){
?>
<input type="text" name="aconfig "value="<?php echo $viewallconfig['config']; ?>" />
<?php } ?>
As you can see, I only put PR200 to search, my question is how can i use the select value instead? I also want the search query to happen everytime i click the select box.
guys can some1 help me? i know how to code this in VB6 it will be like this
assume : select name or in VB6 combobox = selectbox
Private Sub Combo3_Click()
adodc1.recorsource ="Select * from aircrafttable where aircraft = " & selectbox & "'"
adodc1.refresh
Text1.Text = Adodc1.Recordset("aircraft")
everytime i click combo/selectbox the query will perform and give different answer to textbox.
i dont know how to do this in PHP pls help!
Edited Added all codes
<form action="addrecord.php" method="post" >
<table border=1>
<tr><td bgcolor="#999999">
<strong>Area:</strong> </td>
<td>
<input type="text" required="required" name="aarea" size=10 /><br /></td></tr>
<tr><td bgcolor="#999999">
<strong>Aircraft:</strong></td>
<td>
<form method="post" action="aircraft.php">
<select name="selectaircraft" onchange="this.form.submit();">
<option id="0">Aircraft</option>
<?php
require("dbc.php");
$getallaircraft = mysql_query("SELECT * FROM aircrafttable");
while($viewallaircraft = mysql_fetch_array($getallaircraft)){
?>
<option id="<?php echo $viewallaircraft['ID']; ?>">
<?php
echo $viewallaircraft['aircraft'] ?> </option>
<?php } ?>
</select>
<?php
require("dbc.php");
if(isset($_POST)){
$takeaircraft = mysql_real_escape_string($_POST['selectaircraft']);
{
?>
<input type="text" name="aaircraft" size=3 value="<?php echo $takeaircraft; ?>" />
<?php }
}?>
</form>
</td></tr>
<tr><td bgcolor="#999999">
<strong>Flight:</strong> </td>
<td><input type="text" name="aflight" size=10 /><br /></td></tr>
<tr><td bgcolor="#999999">
<strong>Configuration:</strong> </td>
<td>
<?php
require("dbc.php");
if(isset($_POST)){
$selectaircraft = mysql_real_escape_string($_POST['selectaircraft']);
$getallconfig = mysql_query("SELECT * FROM aircrafttable WHERE aircraft LIKE '".$selectaircraft."'");
while($viewallconfig= mysql_fetch_array($getallconfig)){
?>
<input type="text" name="aconfig" value="<?php echo $viewallconfig['config']; ?>" />
<?php }
}?>
<br /></td></tr>
<tr><td bgcolor="#999999">
<strong>Month:</strong> </td>
<td>
<select name="amonth">
<option value="na">Month</option>
<option value="January">January</option>
</select>
</td></tr>
<tr><td bgcolor="#999999">
<strong>Frequency:</strong> </td>
<td><span style="font-size:11px; font-weight:bolder" >
Mon<input type="checkbox" id='check1' onClick='checkmon()'>
<input type="hidden" id="txt1" name="hiddenmon" value="n/a">
Tue<input type="checkbox" id='check2' onClick='checktue()'>
<input type="hidden" id="txt2" name="hiddentue" value="n/a">
Wed<input type="checkbox" id='check3' onClick='checkwed()'>
<input type="hidden" id="txt3" name="hiddenwed" value="n/a">
Thu<input type="checkbox" id='check4' onClick='checkthu()'>
<input type="hidden" id="txt4" name="hiddenthu" value="n/a">
Fri<input type="checkbox" id='check5' onClick='checkfri()'>
<input type="hidden" id="txt5" name="hiddenfri" value="n/a">
Sat<input type="checkbox" id='check6' onClick='checksat()'>
<input type="hidden" id="txt6" name="hiddensat" value="n/a">
Sun<input type="checkbox" id='check7' onClick='checksun()'>
<input type="hidden" id="txt7" name="hiddensun" value="n/a">
</span>
<br /></td></tr>
<tr><td bgcolor="#999999">
<strong>Menu:</strong> </td>
<td><input type="text" name="amenu" size=10 /><br /></td></tr>
<tr><td bgcolor="#999999">
<strong>Cycle:</strong> </td>
<td>
<select name="acycle">
<option value="na">Cycle</option>
<option value="Cycle 1">Cycle 1</option>
</select>
<tr><td bgcolor="#999999">
<strong>Items:</strong> </td>
<td>
<select name="aitem">
<option value="na">Items</option>
</select>
<tr><td bgcolor="#999999">
<strong>STD Time:</strong> </td>
<td><input type="text" name="astdtime" size=5 /><br /></td></tr>
<tr><td bgcolor="#999999">
<strong>Quantity:</strong> </td>
<td><input type="text" name="aqty" size=5 /><br /></td></tr>
<tr>
<td colspan="2" align="right" bgcolor="#999999">
<input type='submit' name="add" value="Add Records" />
</td>
</tr>
</table>
</form>
trigger submit on change of select box as below
<form action="path/to/your/query/file.php" method="post"> //if query in same page leave your action blank
<select name="selectaircraft" onchange="this.form.submi();">
<option id="0">-- Select Aircraft -- </option>
<?php
require("dbc.php");
$selected_aircraft=isset($_POST['selectaircraft'])?$_POST['selectaircraft']:"";
$getallaircraft = mysql_query("SELECT * FROM aircrafttable");
while($viewallaircraft = mysql_fetch_array($getallaircraft)){
$selectstr="";
if($selected_aircraft==$viewallaircraft['aircraft'] ){
$selectstr="selected='selected'";
}
?>
<option id="<?php echo $viewallaircraft['ID']; ?>" <?php echo $selectstr ?> >
<?php
echo $viewallaircraft['aircraft'] ?> </option>
<?php } ?>
</select>
</form>
and change you query as below:
<?php
require("dbc.php");
if(isset($_POST)){
$selectaircraft = mysql_real_escape_string($_POST['selectaircraft']);
$getallconfig = mysql_query("SELECT * FROM aircrafttable WHERE aircraft LIKE '{ $selectaircraft}'");
while($viewallconfig= mysql_fetch_array($getallconfig)){
?>
<input type="text" name="aconfig "value="<?php echo $viewallconfig['config']; ?>" />
<?php }
}?>
Update updated code to maintain state of select box.
Try like this;
$aircraft = mysql_real_escape_string($_POST['selectaircraft']); //or $_GET
$getallconfig = mysql_query("SELECT * FROM aircrafttable WHERE aircraft LIKE '".$aircraft."'");
You can keep the select box(1st) inside a form , on change submit the form to the next page .
And get the POST/GET value , and use it for select query for searching.
I have the following code to create a drop-down list:
<body>
<form method="post">
<table>
<tr>
<td>Firm Name:</td>
<td><input type="text"class="input_text_long" name="name" value="<?php echo $name ?>"/></td>
</tr>
<tr>
<td>Hub Name:</td>
<select>
<option value="">---Select---</option>
<?php
$list=mysql_query("SELECT * FROM hub");
while($row = mysql_fetch_assoc($list)) {
?>
<option value=<?php echo $row_list['name'];?>
</option>
<?php } ?>
</select>
</tr>
<td> </td>
<td><input type="submit" name="save" value="Save" /></td>
</tr>
</table>
</form>
</body>
This, however, does not display any dropdown list. It only displays a text box. Can anyone tell me what I am doing wrong, please? Or how to create a dropdown box in a form.
Your option tag is wrong.
Right syntax <option value="VALUE">OPTION NAME</option>
<select>
<option value="">---Select---</option>
<?php
$list = mysql_query("SELECT * FROM hub");
while ($row = mysql_fetch_assoc($list)) {
$name = $row['name'];
?>
<option value="<?php echo $name; ?>"><?php echo $name; ?></option>
<?php
}
?>
</select>
Change this line
<option value=<?php echo $row_list['name'];?></option>
to
<option value="<?php echo $row['name'];?>"><?php echo $row['name'];?></option>
I think the issue is with this line:
<?php echo $row_list['name'];?>
It should be:
<?php echo $row['name'];?>
Also, your opening <option> tag does not have a closing >
<option value=<?php echo $row['name'];?>></option>