Even though I put the the php code in the the form to retrieve the value from the database, it didn't display the value in the dropdown list and the textbox. The code works fine and can update the value but it didn't display the value after I refreshed the page. It looks fine but can't seem to find the mistake I made.
<?php
require("config.php");
$id = $_GET['id'];
$sql = "SELECT * FROM contracts WHERE id= '$id'";
$result = $con->query($sql);
while ($row = $result->fetch_assoc())
{
$client_type = $row['client_type'];
?>
<html>
<head>
<title> Submit a Contract </title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form method="post" action="" enctype="multipart/form-data">
ID: <?php echo $id; ?><br>
<input type="hidden" name="id" value="<?php echo $id; ?>" />
Division:
<select name="client_details" />
<option value="Choose" <?php $row['client_details'] == 'Choose' ? print "selected" : ""; ?> />Choose Division...</option>
<option value="Distribution" <?php $row['client_details'] == 'Distribution' ? print "selected" : ""; ?> />Distribution</option>
<option value="Transmission" <?php $row['client_details'] == 'Transmission' ? print "selected" : ""; ?> />Transmission</option>
<option value="Generation" <?php $row['client_details'] == 'Generation' ? print "selected" : ""; ?> />Generation</option>
<option value="Procument" <?php $row['client_details'] == 'Procument' ? print "selected" : ""; ?> />Procument</option>
<option value="Other" <?php $row['client_details'] == 'Other' ? print "selected" : ""; ?> />Others</option>
</select>
<br><br>
Others:
<input type="text" name="client_details" value="<?php $row['client_details']; ?>">
<input type="submit" name="submit" value="Submit"/>
</form>
</body>
</html>
<?php
}
if(isset($_POST['submit']))
{
$client_details = isset($_POST ['client_details']) ? $_POST['client_details'] :null;
if($client_details == 'Other'){
$client_details = isset($_POST ['client_details']) ? $_POST['client_details'] :null;
}
$query = "UPDATE contracts set `client_details` = '$client_details' WHERE `id` = '$id'";
if ($con->query($query) === TRUE)
{
echo "<br><br> Updated successfully <br>";
echo $query;
}
else {
echo "Error: " . $query . "<br>" . $con->error;
}
$con->close();
}
?>
<option value="Choose" <?php echo $row['client_details'] == 'Choose' ? print "selected" : ""; ?> />Choose Division...</option>
your code is fine just add echo before will work
You directly close your select element;
<select ... />
Note the /. As in html specs it will consider the <option> tags as not being part of the <select>.
And as #ParthGoswami said; don't forget to echo the values
Here is fixed, clean code.
Few suggestions for future: Always try to follow best practices like don't use while/loop if you are getting only one record from database. Don't use inside while loop, always keep SQL injection in mind when interacting with DB and how to tackle it, follow Code Formatting Pattern etc etc.
<?php
require("config.php");
$id = filter_input(INPUT_GET, 'id');
?>
<html>
<head>
<title> Submit a Contract </title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form method="post" action="" enctype="multipart/form-data">
ID: <?php echo $id; ?><br>
<input type="hidden" name="id" value="<?php echo $id; ?>" />
<?php
$sql = "SELECT * FROM contracts WHERE id = $id";
$result = $con->query($sql);
$row = $result->fetch_assoc();
$client_type = $row['client_type'];
?>
Division:
<select name="client_details">
<option value="Choose" <?php $row['client_details'] == 'Choose' ? echo "selected" : ""; ?> />Choose Division...</option>
<option value="Distribution" <?php $row['client_details'] == 'Distribution' ? echo "selected" : ""; ?> />Distribution</option>
<option value="Transmission" <?php $row['client_details'] == 'Transmission' ? echo "selected" : ""; ?> />Transmission</option>
<option value="Generation" <?php $row['client_details'] == 'Generation' ? echo "selected" : ""; ?> />Generation</option>
<option value="Procument" <?php $row['client_details'] == 'Procument' ? echo "selected" : ""; ?> />Procument</option>
<option value="Other" <?php $row['client_details'] == 'Other' ? echo "selected" : ""; ?> />Others</option>
</select>
<br><br>
Others:<input type="text" name="client_details" value="<?php $row['client_details']; ?>">
<input type="submit" name="submit" value="Submit"/>
</form>
</body>
</html>
<?php
if(isset($_POST['submit'])) {
$client_details = isset($_POST ['client_details']) ? $_POST['client_details'] :null;
if($client_details == 'Other') {
$client_details = isset($_POST ['client_details']) ? $_POST['client_details'] :null;
}
$query = "UPDATE contracts set `client_details` = '$client_details' WHERE `id` = '$id'";
if ($con->query($query) === TRUE) {
echo "<br><br> Updated successfully <br>";
echo $query;
} else {
echo "Error: " . $query . "<br>" . $con->error;
}
$con->close();
}
?>
And use echo because according to w3schools, echo is marginally faster than print.
Related
Something very strange is happening here.
This code below (automatic input values after dropdown selection) does not get saved in the database with 1 click on submit but after 2 clicks. Is there a simple fix for this or do I need an different approach here?
<?php $id = (ISSET($_GET['client'])) ? intval($_GET['client']):0; ?>
<?php while ($row = $result->fetch_assoc()) {?>
<form class="edit" action="" method="post">
<?php
$a = $row['costs'];
$b = $row['deposit'];
$c = $a-$b;
$auto6 = $a*1.06;
$auto21 = $a*1.21;
?>
<select id="btw" name="btw" class="input-xlarge">
<option value="Verlegd"<?=$row['btw'] == 'Verlegd' ? ' selected="selected"' : '';?>>Verlegd</option>
<option value="6%"<?=$row['btw'] == '6%' ? ' selected="selected"' : '';?>>6%</option>
<option value="21%"<?=$row['btw'] == '21%' ? ' selected="selected"' : '';?>>21%</option>
</select>
<strong>Total excl BTW:</strong><input id="btw0" class="special <?=$row['btw'] != 'Verlegd' ? 'disabled' : 'enabled';?>" type="text" name="exclbtw" value="<?=$row['btw'] == 'Verlegd' ? $a : '';?>">
<strong>Total incl BTW 21%:</strong><input id="btw21" class="special <?=$row['btw'] != '21%' ? 'disabled' : 'enabled';?>" type="text" name="btw21" value="<?=$row['btw'] == '21%' ? $auto21 : '';?>">
<strong>Total incl BTW 6%:</strong><input id="btw6" class="special <?=$row['btw'] != '6%' ? 'disabled' : 'enabled';?>" type="text" name="btw6" value="<?=$row['btw'] == '6%' ? $auto6 : '';?>">
<INPUT TYPE="Submit" VALUE="Save" NAME="Submit">
</form>
<?php } ?>
<?php
if(isset($_POST['Submit'])){
$btw = $_POST['btw'];
$exclbtw = $_POST['exclbtw'];
$btw21 = $_POST['btw21'];
$btw6 = $_POST['btw6'];
$update = "UPDATE
invoice
SET
btw = '$btw',
exclbtw = '$exclbtw',
btw21 = '$btw21',
btw6 = '$btw6'
WHERE
id = $id";
$conn->query($update) or die("Cannot update");
}
?>
<?php
if($update){//if the update worked
echo("<script>window.location = 'http://example.com/invoice/edit.php?client=$id';</script>");
} else {
"Error";
}
?>
So, I have made a code to edit radio buttons, drop down lists and text boxes.
The Division->(dropdown list and Other: textbox) and External->(textbox) are under the same "client_details".
This is the example of the edit form.
This is the code I made.
<?php
require("config.php");
$id = filter_input(INPUT_GET, 'id');
?>
<html>
<head>
<title> Edit a Contract </title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form method="post" action="" enctype="multipart/form-data">
ID: <input type="hidden" name="id" value="<?php echo $id; ?>" />
<?php
$sql = "SELECT * FROM contracts WHERE `id` = $id";
$result = $con->query($sql);
$row = $result->fetch_assoc();
$client_type = $row['client_type'];
?>
<label for = "client1">
<input type="radio" name="client_type" id = "client1" value="Division" <?php echo ($client_type == 'Division')? "checked" : "" ?> onclick="toggleDivision()"/> Division
</label>
                                     
<label for ="client2">
<input type="radio" name="client_type" id = "client2" value="External" <?php echo ($client_type == 'External')? "checked" : "" ?> onclick="toggleExternal()"/> External
</label>
 
<input type="text" id="extText" name="client_details2" value="<?php echo $row['client_details']; ?>" disabled />
<br><br>
<div id="division">
Division:
<select id="mySelect" name="client_details" onclick="enableTextbox()" disabled>
<option value="Choose" <?php echo $row['client_details'] == 'Choose' ? "selected" : ""; ?> />Choose Division...</option>
<option value="Distribution" <?php echo $row['client_details'] == 'Distribution' ? "selected" : ""; ?> />Distribution</option>
<option value="Transmission" <?php echo $row['client_details'] == 'Transmission' ? "selected" : ""; ?> />Transmission</option>
<option value="Generation" <?php echo $row['client_details'] == 'Generation' ? "selected" : ""; ?> />Generation</option>
<option value="Procument" <?php echo $row['client_details'] == 'Procument' ? "selected" : ""; ?> />Procument</option>
<option value="Other" <?php echo $row['client_details'] == 'Other' ? "selected" : ""; ?> />Others</option>
</select>
<br><br>
Others:<input type="text" id="otherTxt" name="client_details1" value="<?php echo $row['client_details']; ?>" disabled />
<br>
</div>
<br>
<input type="submit" name="submit" value="Submit"/>
</form>
<script type="text/javascript">
function toggleExternal() {
document.getElementById("extText").disabled = false;
var divis_el = document.getElementById("division");
for (var i = 0; i < divis_el.children.length; i++) {
divis_el.children[i].disabled = true;
}
}
function toggleDivision() {
document.getElementById("extText").disabled = true;
var val = document.getElementById("mySelect").selectedIndex;
var divis_el = document.getElementById("division");
for (var i = 0; i < divis_el.children.length; i++) {
divis_el.children[i].disabled = false;
divis_el.children[5].disabled = true;
}
}
function enableTextbox() {
var val = document.getElementById("mySelect").selectedIndex;
if (val == 0 || val == 1 ||val == 2 ||val == 3 ||val == 4) { document.getElementById("otherTxt").disabled = true}
if (val == 5) { document.getElementById("otherTxt").disabled = false; }
}
</script>
</body>
<?php
if(isset($_POST['submit'])) {
$client_type = isset($_POST ['client_type']) ? $_POST['client_type'] :null;
$client_details = isset($_POST ['client_details']) ? $_POST['client_details'] :null;
if($client_type == 'Division'){
$client_details = isset($_POST ['client_details1']) ? $_POST['client_details1'] :null;
$client_details = isset($_POST ['client_details']) ? $_POST['client_details'] :null; // both variables under if statement are needed to successfully update the data avoiding blank values.
} else {
$client_details = isset($_POST ['client_details2']) ? $_POST['client_details2'] :null;
}
if($client_details == 'Other') {
$client_details = isset($_POST ['client_details1']) ? $_POST['client_details1'] :null;
}
$query = "UPDATE contracts set `client_type`=?, `client_details`=? WHERE `id`= ?";
$stmt = $con->prepare($query);
$stmt->bind_param("ssi", $client_type, $client_details, $id);
$stmt->execute();
if ($stmt->errno){
echo "FAILURE!!! " . $stmt->error;
} else {
echo "<br>Updated";
}
$stmt->close();
$con->close();
}
?>
EDIT: What I meant is this.
As you can see the example picture from the link, the "Generation" values is displayed in all the textboxes under both Division and External after I updated the data because The value was taken from the drop down list.
The "Other" textbox is under division but it will only enabled to be entered after the selecting the value "Other" from the drop down list under Division.
I only wanted the the Division values displayed in the textbox only under Division and not the under External when Division radio button is chosen. And if I choose External and input data in the textbox, I only wanted the value displayed in the textbox under External only after updated.
When I select the values and not "Other" value, the value should not displayed in the text box under Division. When I select "Other" value, then the value should be displayed in 'Other' textbox but I don't want the value to also displayed in the text box under External.
The question I'm trying ask is how to make the textbox values display values separately. I don't want the same values displaying in all the dropdown list and textboxes? How do I do that? Sorry for poor explaination as English is my second language
Well it's no wonder why both are displaying the samething, their values are both just <?php echo $row['client_details']; ?>
You already have a checking variable, just not sure why you didn't use it here.
E.g.
<?php $extText = ($client_type == 'External') ? $row['client_details'] : "" ?>
<?php $divText = ($client_type == 'Division') ? $row['client_details'] : "" ?>
<input type="text" id="extText" name="client_details2" value="<?php echo extText; ?>" disabled />
Others:<input type="text" id="otherTxt" name="client_details1" value="<?php echo $divText; ?>" disabled />
this code run but when test it .. the data not correct i select data from database and i make it in array ad show it id by select tag but when select any id and submit .. example i select 5 and click on submit the record will delete is 2 not 5
<?php
require_once "config.php";
$qid="select id from info_user";
$arrayid=array();
$result=mysql_query($qid);
while($res=mysql_fetch_array($result)){
$arrayid[]=$res['id'];
}
var_dump($arrayid);
if(isset($_POST['sub'])){
$id=$_POST['id'];
$q="delete from info_user where id=$id ";
$qq=mysql_query($q);
if($qq){
echo "you delete record ";
}
else{
echo "error in deleting";
}}
?>
<html>
<head>
<title>delete</title>
</head>
<form action="delete.php" method="post">
<select name="id"><?php for($i=0;$i<count($arrayid);$i++){?>
<option value="<?php echo $i;?>"><?php echo $arrayid[$i];} ?></option></select> <br />
<input type="submit" name="sub" />
</form>
</html>
I think that problem is in value for the options.
Try changing option line to
<option value="<?php echo $arrayid[$i];?>"><?php echo $arrayid[$i];} ?></option></select> <br />
Your <option> markup is wrong. Make your markup like this;
<select name="id">
<?php for ($i = 0; $i < count($arrayid); $i++) { ?>
<option value="<?php echo $i; ?>"><?php echo $arrayid[$i]; ?></option>
} ?>
</select>
Tip: You'll find debugging easier if you indent your code. IDE's generally have this option. NetBeans is my favourite.
Instead of sending the ids, you're sending an array key associated to the id.
For instance, assume that: $arrayid = array(10, 11, 12);.
This is equivalent to: $arrayid = array(0 => 10, 1 => 11, 2 => 12);.
You'll see the options 10, 11 and 12, but you'll send either 0, 11 or 12, because that's what you're setting to the options values:
<select name="id">
<option value="0">10</option>
<option value="1">11</option>
<option value="2">12</option>
</select>
If you select the option "11", the SQL statement to delete an entry will be:
delete from info_user where id=1
I did not test this code and I'm assuming the ids are integers, but try it:
<?php
require_once "config.php";
$qid = "select id from info_user";
$arrayid = array();
$result = mysql_query($qid);
while( $res = mysql_fetch_array($result) ){
$arrayid[] = $res['id'];
}
if( isset($_POST['sub']) ){
$id = (int)$_POST['id']; // make sure it's an integer to avoid SQL injections
$q = "delete from info_user where id=$id";
$qq = mysql_query($q);
if( $qq ) {
$error = "you delete record ";
} else {
$error = "error in deleting";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>delete</title>
</head>
<body>
<?php
if( isset($error) ) :
echo '<p>', htmlspecialchars($error), '</p>';
elseif( !empty($arrayid) ) :
var_dump($arrayid);
endif;
?>
<form action="delete.php" method="post">
<select name="id">
<?php foreach($arrayid as $id): ?>
<option value="<?php echo (int)$id;?>">
<?php echo (int)$id; ?>
<?php endforeach; ?>
</option>
</select>
<br />
<input type="submit" name="sub" />
</form>
</body>
</html>
I'm writing a php form and I can't get the drop down boxes and check boxes to stick as in when I fill in my details but don't click something it will keep everything else filled but that one part that wasn't filled out. I can do it for the input text and radio buttons but I can't get it done for drop downs and checkboxes
<!DOCTYPE html>
<style>
#import url(stickyTextInput.css);
</style>
<?php
if(isset($_REQUEST["left"]))
{
process_form();
}
else
{
display_form_page('');
}
?>
<?php
function display_form_page($error)
{
$self =$_SERVER['PHP_SELF'];
$first_name = isset($_REQUEST['name']) ? $_REQUEST['name']:'';
$last_name = isset($_REQUEST['lastname']) ? $_REQUEST['lastname']:'';
$age = isset($_REQUEST['age']) ? $_REQUEST['age']:'';
$gender = isset($_REQUEST['gender']) ? $_REQUEST['gender']:'';
$color = isset($_REQUEST['color']) ? $_REQUEST['color']: '';
$food = isset($_REQUEST['food']) ? $_REQUEST['food']:'';
?>
<html>
<head>
<title>
Forms Sticky input
</title>
<style>
#import url(stickyTextInput.css);
</style>
<style type="text/css">
.error
{
color:#ff0000
}
</style>
</head>
<body>
<?php
if($error)
{
echo "<p>$error</p>\n";
}
?>
<form action= "<?php echo $self?>" method = "post">
<h1>Forms-Sticky Input</h1>
<label>First Name:</label>
<input type="text" size="10" maxlength="40" name="name" value = "<?php echo $first_name?>">
<br>
<label>Last Name:</label>
<input type="text" size="10" maxlength="40" name="lastname" value = "<?php echo $last_name?>">
<br>
<label>Age:</label>
<input type="text" name="age" size="10" value="<?php echo $age?>">
<br>
<label>Gender</label>
<input type="radio" name="gender" value="male" <?php check($gender, "male")?>>Male
<input type="radio" name="gender" value="female" <?php check ($gender, "female")?>>Female
<br>
<label>Select favourite Colour</label>
<select name= "color">
<option <?php checkradio($color, "Red")?>>Red
<option <?php checkradio($color, "Blue")?>>Blue
<option <?php checkradio($color, "Green")?>>Green
<option <?php checkradio($color, "Pink")?>>Pink
<option selected="selected" disabled="disabled">
</select>
<br>
<label>Food</label>
<input type="checkbox" name="food[]" value="beans" <?php checkbox ($food, "beans")?>>Beans
<input type="checkbox" name="food[]" value="crisps" <?php checkbox ($food, "crisps")?>>Crisps
<input type="checkbox" name="food[]" value="lemons" <?php checkbox ($food, "lemons")?>>Lemons
<br>
<div id="buttons">
<input type="submit" name="left" id="left" value="Submit" >
<input type="reset" name="right" id="right" value="Reset" >
</div>
</form>
</body>
</html>
<?php
}
?>
<?php
// If $group has the value $val then select this list item
function check($group, $val)
{
if ($group === $val)
{
echo 'checked = "checked"';
}
}
?>
<?php
function checkradio($group, $val)
{
if ($group === $val)
{
echo 'selected = "selected"';
}
}
?>
<?php
// If $group has the value $val then select this list item
function checkbox($group, $val)
{
if ($group === $val)
{
echo 'checked = "checked"';
}
}
?>
<?php
function process_form()
{
$error = validate_form();
if($error)
{
display_form_page($error);
}
else
{
display_output_page();
}
}
?>
<?php
function validate_form()
{
$first_name = trim($_REQUEST['name']);
$last_name = trim($_REQUEST['lastname']);
$age = trim($_REQUEST['age']);
$gender = isset($_REQUEST['gender']) ? $_REQUEST['gender']:'';
$color = isset($_REQUEST['color']) ? $_REQUEST['color']:'';
$food = isset($_REQUEST['food']) ? $_REQUEST['food']:'';
$error = '';
$reg_exp = '/^[a-zA-Z\-\']+$/';
$reg_exp1 = '[0-9]{3}';
if(!preg_match($reg_exp, $first_name))
{
$error .= "<span class=\"error\">First Name is invalid (letters, hyphens, ', only)</span><br>";
}
if (!preg_match($reg_exp, $last_name))
{
$error .= "<span class=\"error\">Last Name is invalid (letters, hyphens, ', only)</span><br>";
}
if (!is_numeric($age))
{
$error .= "<span class=\"error\">Age is invalid (numbers only)</span><br>";
}
if (strlen($gender) == 0)
{
$error .= "<span class=\"error\">Select Male/Female</span><br>";
}
if (strlen($color) == 0)
{
$error .= "<span class=\"error\">Select one color</span><br>";
}
if (! is_array($food))
{
$error .= "<span class=\"error\">You must select one food</span><br>";
}
return $error;
}
?>
<?php
function display_output_page()
{
$first_name = trim($_REQUEST['name']);
$last_name = trim($_REQUEST['lastname']);
$age = trim($_REQUEST['age']);
$gender = isset($_REQUEST['gender']) ? $_REQUEST['gender']:'';
$color = isset($_REQUEST['color']) ? $_REQUEST['color']:'';
$food = isset($_REQUEST['food']) ? $_REQUEST['food']:'';
?>
<html>
<head><title>Form Results</title></head>
<body>
<h1>Form Results</h1>
<?php
echo " First Name: $first_name<br/>\n";
echo " Last Name: $last_name<br/>\n";
echo " Age: $age<br/>\n";
echo " Gender: $gender<br/>\n";
echo " Favourite Color: $color<br/>\n";
echo "<ul>";
if (is_array($food))
{
echo "Favourite Food is:";
foreach($food as $selection)
{
echo "<li>$selection</li>";
}
}
echo "</ul>";
?>
</body>
</html>
<?php
}
?>
Possibly a browser issue, however most browsers only require 'checked' at the end of the html input element for checkboxes. However you appear to be outputting checked = "checked" This is possibly the problem. Have a look at the sample below:
<?php
$name = isset($_GET['name']) ? $_GET['name'] : '';
$agree = isset($_GET['agree']) ? 'checked' : '';
$title = isset($_GET['title']) ? $_GET['title'] : '';
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="">
<input type="text" name="name" id="name" value="<?=$name;?>">
<input type="checkbox" name="agree" id="agree" <?=$agree;?>>
<select name="title" id="title">
<option value="Mr" <?=$title == 'Mr' ? 'selected' : ''?>>Mr</option>
<option value="Mrs" <?=$title == 'Mrs' ? 'selected' : ''?>>Mrs</option>
<option value="Miss" <?=$title == 'Miss' ? 'selected' : ''?>>Miss</option>
</select>
<button type="submit">submit</button>
</form>
</body>
</html>
After processing the values the output html should be as follows:
<form action="">
<input type="text" name="name" id="name" value="test">
<input type="checkbox" name="agree" id="agree" checked>
<select name="title" id="title">
<option value="Mr">Mr</option>
<option value="Mrs">Mrs</option>
<option value="Miss" selected>Miss</option>
</select>
<button type="submit">submit</button>
</form>
I am developing user edit form where users can edit their info. I wants only that date come in combo box which was user add in table as Date of Birth. In following code I successfully pull Month into Combo box which user added in table.
IN FOLLOWING LINE I RUN SELECT QUERY TO FETCH DATA FROM DB INCLUDING YEAR, MONTH AND DAY:
<?php
$cnic_selected=$_POST['all_cnic'];
if(isset($cnic_selected))
{
$query = mysql_query("SELECT refer_id, emp_name, emp_father, emp_cnic, YEAR(emp_dob) AS byear, MONTH(emp_dob) AS bmonth, DAY(emp_dob) AS bday FROM staff_users WHERE emp_cnic = '$cnic_selected'");
$count = mysql_num_rows($query);
while($row = mysql_fetch_object($query))
{
$ref = $row->refer_id;
$name = $row->emp_name;
$fname = $row->emp_father;
$cnic = $row->emp_cnic;
$byear = $row->byear;
$bmonth = $row->bmonth;
$bday = $row->bday;
}
?>
<html>
<head>
</head>
<body>
<table width="95%">
<form name="edituserform" action="" method="Post" onSubmit="return validateform(this);">
<tr><td width="125px"><b>Referral Code</b></td>
<td><?php echo $ref; ?></td></tr>
<tr><td><b>Full Name</b></td>
<td><input type="text" name="emp_name" id="emp_name" value="<?php echo $name; ?>" />
</td></tr>
<tr><td><b>Father's Name</b></td>
<td><input type="text" name="emp_father" id="emp_father" value="<?php echo $fname; ?>" />
</td></tr>
<tr><td><b>CNIC Number</b></td>
<td><?php echo $cnic; ?></td></tr>
<tr><td><b>Date of Birth</b></td>
<td>
/* Run Loop to generate 31 days of the month */
<select name="dt">
<option value='--'>--</option>
<?php
for ($d=1; $d<32; $d++)
{
"<option value='$d'>$d</option>";
}
?>
</select>
/* Here I manually type months list. Use "Selected" to fetch that month which user select in DB */
<select name="month">
<option value="--">--</option>
<option value='01' <?php echo ($bmonth == 1) ? 'selected="selected"': ''; ?>>
Jan</option>
<option value='02' <?php echo ($bmonth == 2) ? 'selected="selected"': ''; ?>>
Feb</option>
<option value='03' <?php echo ($bmonth == 3) ? 'selected="selected"': ''; ?>>
Mar</option>
<option value='04' <?php echo ($bmonth == 4) ? 'selected="selected"': ''; ?>>
Apr</option>
<option value='05' <?php echo ($bmonth == 5) ? 'selected="selected"': ''; ?>>
May</option>
<option value='06' <?php echo ($bmonth == 6) ? 'selected="selected"': ''; ?>>
Jun</option>
<option value='07' <?php echo ($bmonth == 7) ? 'selected="selected"': ''; ?>>
Jul</option>
<option value='08' <?php echo ($bmonth == 8) ? 'selected="selected"': ''; ?>>
Aug</option>
<option value='09' <?php echo ($bmonth == 9) ? 'selected="selected"': ''; ?>>
Sep</option>
<option value='10' <?php echo ($bmonth == 10) ? 'selected="selected"': ''; ?>>
Oct</option>
<option value='11' <?php echo ($bmonth == 11) ? 'selected="selected"': ''; ?>>
Nov</option>
<option value='12' <?php echo ($bmonth == 12) ? 'selected="selected"': ''; ?>>
Dec</option>
</select>
<select name="year">
<option value='--'>--</option>
<?php
for ($y=2000; $y>1950; $y--)
{
echo "<option value='$y'>$y</option>";
}
?>
</select>
</td></tr>
</table>
</body>
</html>
Now my question is Please tell how to pull Year and Day from table into combo box which user was added while I am using Loop to generate years and days!??
Regards,
MAT
For days you are missing an echo and a check as to which day is selected
<?php
for ($d=1; $d<32; $d++)
{
"<option value='$d'>$d</option>";
}
?>
Should be
<?php
for ($d=1; $d<32; $d++)
{
if($d==$bday)
{
echo "<option value='$d' selected='selected'>$d</option>";
}
else
{
echo "<option value='$d'>$d</option>";
}
}
?>
Same for year
for ($y=2000; $y>1950; $y--)
{
if($y==$byear)
{
echo "<option value='$y' selected='selected'>$y</option>";
}
else
{
echo "<option value='$y'>$y</option>";
}
}