linked data selection option with ajax & php - php

I am trying to populate Material Description from the Material Number. Bot hte values are stored in same SQL tasble. So what I want when I select Material Maiterial Description shpul auto populate.
Fileds in table are Material & MaterialDescripotion
Below is code in in main file where data is fetched
<?php
include_once "dbConnect.php";
$sql = "SELECT * FROM DRLINK";
$result2 = mysqli_query($conn, $sql);
if (!$result2) {
printf("Error: %s\n", mysqli_error($conn));
exit();
}
$options = "";
while($row2 = mysqli_fetch_array($result2))
{
$options = $options."<option>$row2[1]</option>";
}
?>
<html>
<!DOCTYPE html>
<head>
<title>Dropdown Ajax</title>
</head>
<body>
<form action ="DSSTRsubmit.php" method="POST">
<table border="1">
<tr>
<td>Select Retailer</td>
</tr>
<tr>
<td>
<?php
echo "<select>";
echo $options;
echo "</select>";
?>
</td>
</tr>
</table>
<br/>
<br/>
<br/>
<table border="1">
<tr>
<td>Material</td>
<td>Material Description</td>
<td>Quantity</td>
<td>Unit of Measure</td>
</tr>
<tr>
<td>
<div class="Material">
<select name="Material" onchange="getId(this.value);">
<option value="">Select Country</option>
<?php
$query ="SELECT * FROM MATERIALLIST";
$results = mysqli_query($conn, $query);
foreach($results as $MATERIALLIST) {
?>
<option value="<?php echo $MATERIALLIST["Material"];?>"><?php echo $MATERIALLIST["Material"];?></option>
<?php
}
?>
</select>
</div>
</td>
<td>
<div class="MaterialDescription">
<select name="MaterialDescription" id="DesList">
<option value=""></option>
</select>
</div>
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script>
function getId(val){
$.ajax({
type:"POST",
url:"getdata1.php",
data:"Material="+val,
success: function(data){
$("#DesList").html(data);
}
});
}
</script>
</td>
<td><input type="text" name="dquantity_name" /> </td>
<td><input type="text" name="duom_name" /> </td>
</tr>
</table>
<legend> </legend>
<p> <button type="submit" class="pure-button pure-button-primary">Send Stock</button>
<br>
<br>
<?php
echo "Distributor Page";
?>
</body>
</html>
below is the getdata1.php
<?php
include_once "dbConnect.php";
if(!empty($_POST["Material"])){
$Material= $_POST["Material"];
$query = "SELECT * FROM MATERIALLIST WHERE Material = $Material";
$results = mysqli_query($conn,$query);
foreach($results as $MaterialDescription){
?>
<option value="<?php echo $Des["Material"];?>"><?php echo $materialDescription ["MaterialDescription"];?></option>
<?php
}
}
?>
Iam able to select the material but on selection of material no material description auto populates.
Thanks for the help

PHP is case sensitive. Be careful about naming variables.
foreach contains upper case variable, while echo - lowercase. Also in echo you have space after variable and before opening bracket.
$MaterialDescription
$materialDescription_["MaterialDescription"]

Related

how to refresh tabs data when update table?

index.php
<div class="tab">
<button class="tablinks" onclick="openCity(event, 'Engineering')">Engineering</button>
<button class="tablinks" onclick="openCity(event, 'LAW')">LAW</button>
</div>
<div id="Engineering" class="tabcontent">
<table class="items">
<tr>
<th>State</th>
<th>College Name</th>
</tr>
<?php
$query = "select * from college where field = 'engineering'";
$show = mysqli_query($link,$query);
while ($fetch = mysqli_fetch_array($show))
{
?>
<tr>
<td><?php echo $fetch['state']?></td>
<td><?php echo $fetch['college_name']?></td>
<td>
edit
</td>
</tr>
<?php
}
?>
</table>
</div>
<div id="Law" class="tabcontent">
<table class="items">
<tr>
<th>State</th>
<th>College Name</th>
</tr>
<?php
$query = "select * from college where field = 'law'";
$show = mysqli_query($link,$query);
while ($fetch = mysqli_fetch_array($show))
{
?>
<tr>
<td><?php echo $fetch['state']?></td>
<td><?php echo $fetch['college_name']?></td>
<td>
edit
</td>
</tr>
<?php
}
?>
</table>
</div>
edit.php
<?php
if(isset($_POST['update']))
{
$college_name = $_POST['colleges'];
$state = $_POST['state'];
$sqli = "update college set college_name = '$college_name', state = '$state' where id = '$id'";
$results = mysqli_query($link,$sqli);
if($result == true)
{
$msg .= "<p style='color:green;'>Your data update successfully</p>";
}
else
{
$msg .= "<p style='color:red;'>Errror!</p>";
}
}
?>
<form method="POST" enctype="multipart/form-data" >
<select name="state" id="state">
<option value="<?php echo $stateid; ?>"><?php echo $statename; ?></option>
<option value="">Select State</option>
<?php
$sql = "select * from statemaster";
$result = mysqli_query($link,$sql);
while($row = mysqli_fetch_array($result))
{
echo "<option value=".$row['stateid'].">".$row['statename']."</option>";
}
?>
</select>
<select name="colleges" id="colleges">
<option value="<?php echo $college_name; ?>"><?php echo $college_name; ?></option>
<option value="">Select College</option>
</select>
<button type="submit" name='update' id='update'>update</button>
</form>
In this code when I click on edit button then it will go to edit.php page where I get id from url and run update query after updating table college the data will update but when I move from edit page to index.php page the data will remain same but in database update data will be there. So, How can I fix this issue ?
Thank You
Check for caching. It could be that the browser is not going to the server in order to get the contents of index.php, as it thinks it has it.
Try calling index.php with a variable, like:
Home

how can I display the following code in php according to DateOfHearing (ascending order)in a html table

i have the following tables that i want to display case number, defendant name,accussed name, judge name, date of hearing and type of hearing
<?php while($row=mysqli_fetch_array($search_result)):?>
<tr>
<td> <?php echo $row['CaseNO'];?></td>
<td> <?php echo $row['DefendantName'];?></td>
<td> <?php echo $row['AccussedName'];?></td>
<td> <?php echo $row['JudgeName'];?></td>
<td> <?php echo $row['DateOfHearing'];?></td>
<td> <?php echo $row['TypeOfHearing'];?></td>
</tr>
<?php endwhile;?>
THIS IS MY WHOLE CODE
<?php
if(isset($_POST['search']))
{
$valueToSearch=$_POST['valueToSearch'];
$query="SELECT * FROM `cases` WHERE CONCAT (`CaseNO`, `JudgeName`, `DefendantName`, `AccussedName`, `DateOfHearing`, `TypeOfHearing`) LIKE '%".$valueToSearch. "%'";
$search_result=filterTable($query);
}
else
{
$query="SELECT `CaseNO`,`DefendantName`,`AccussedName`,`JudgeName`,`DateOfHearing`,`TypeOfHearing`
FROM cases";
$search_result=filterTable($query);
}
function filterTable($query)
{
$connect=mysqli_connect("localhost","root","","mlc");
$filter_Results=mysqli_query($connect, $query);
return $filter_Results;
}
?>
<html>
<head>
<title> CAUSE LIST</title>
<style>
table,tr,th,td
{
}
</style>
</head>
<BODY>
<form action="tables.php" method="post">
<input type="text" name="valueToSearch" placeholder="value to search"> <br><br>
<input type="submit" name="search" value="filter" ><br><br>
<table>
<tr>
<th>Case number</th>
<th>Defendant Name</th>
<th>Accussed Name</th>
<th>Judge name</th>
<th>Date of Hearing</th>
<th>Type of Hearing</th>
</tr>
<?php while($row=mysqli_fetch_array($search_result)):?>
<tr>
<td> <?php echo $row['CaseNO'];?></td>
<td> <?php echo $row['DefendantName'];?></td>
<td> <?php echo $row['AccussedName'];?></td>
<td> <?php echo $row['JudgeName'];?></td>
<td> <?php echo $row['DateOfHearing'];?></td>
<td> <?php echo $row['TypeOfHearing'];?></td>
</tr>
<?php endwhile;?>
</table>
</form>
</BODY>
</html>
In select query you just give asscending order
SELECT CaseNO,DefendantName,AccussedName,JudgeName,DATE(DateOfHearing) AS DateOfHearing,TypeOfHearing
FROM tblname
ORDER BY DateOfHearing
Or use jquery datatable https://www.datatables.net/
You can sort the the records according to the date of hearing in your query. And simply put it in echo.
Here is a snippet :
<?php
$connect=new mysqli("localhost","root","");
mysqli_select_db($connect,'database');
$query=mysqli_query($connect,"SELECT * FROM table_name");
echo"<table><tr>";
while($row=mysqli_fetch_array($query))
echo '<td>Case Number: '.$row['case_number'].'</td><td>Defendant Name: '.$row['defendant_name'].'</td><td>Accused name: '.$row['accused_name'].'</td><td>judge name: '.$row['judge_name'].'</td><td>Date of HEaring: '.$row['date_of_hearing'].'</td><td>type of hearing: '.$row['type_of_hearing'].'</td>';
echo "</tr></table>";
?>
According to my comments
You can directly give ASC or DESC command in query. Like:
SELECT column_name, column_name FROM table_name ORDER BY column_name ASC|DESC, column_name ASC|DESC;

Can't display data from database

I have 3 tables in my database (standards, courses, students). I want to display Fname and gender from students table enrolled in selected 'standard' and 'course' from dropdown - but the "submit" button doesn't seem to work. The code is as shown below. I am sure it is connected to the database as the dropdowns for 'courses' and 'standards' work:
<html>
<head>
<title>Courses</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div id="container">
<div id="wrapper">
<h1> Students</h1>
<div id="data">
<form action="index.php" method="POST">
<select name="standards">
<option>Standard</option>
<?php
include 'includes/dbconnect.php';
$query1 = "SELECT * FROM standards";
$result1 = mysql_query($query1);
while($rows1 = mysql_fetch_array($result1)){
$standardID = $rows1['id'];
$rowsData1 = $rows1['standardName'];
?>
<option value="<?php echo $standardID; ?>">
<?php
echo $rowsData1; ?></option>
<?php
}
?>
</select>
</div>
<div id="data2">
<select name="courses">
<option>Courses</option>
<?php
$query2 = "SELECT * FROM courses";
$result2 = mysql_query($query2);
while($rows2 = mysql_fetch_array($result2)){
$coursesID = $rows2['id'];
$rowsData2 = $rows2['courseName'];
?>
<option value="<?php echo $courseID;?>">
<?php echo $rowsData2; ?></option> <?php }?>
</select>
</div>
<div id="submit">
<input type="submit" name="submit" id="submit" value="submit"/>
<table border="1" id="table1">
<tr>
<th>Student Name</th>
<th>Gender</th>
</tr>
<?php
if(isset($_POST['submit'])){
$standardName = $_POST['standards'];
$courseName = $_POST['courses'];
$query3 = "SELECT students.Fname, students.gender
FROM students
WHERE students.standardID = '$standardName'
AND students.courseID = '$courseName'";
$result3 = mysql_query($query3);
while($rows3 = mysql_fetch_array($result3)){
//$dataID = $rows3['id'];
$studentName = $rows3['FName'];
$gender = $rows3['gender'];
?>
<tr>
<td><?php echo $studentName; ?></td>
<td><?php echo $gender; ?></td>
<tr>
<?php
}
}
?>
</table>
</div>
</div>
</body>
</html>
Inscribe the input elements within a form tag with post as method. Input elements with type submit are used for submission of forms.
You only do anything with the submitted form data if that data includes a submit field.
if(isset($_POST['submit'])){
However you have:
<input type="submit" name="submit" id="submit"/>
Your submit button don't have a value, so nothing will be included in the form data for it.

some combobox reset each other after selected

I have some combobox with onchange event, and they're reset each other when selected the orther one of them, does any suggest how to retain the value on the page? this my script :
<form method="POST" name="form1" action="<?php $_SERVER['PHP_SELF'];?>">
<table border="0">
<tr>
<td colspan="6"></td>
</tr>
<tr>
<td>
<select name="select_petugas1" style="width:18px;" onchange="this.form.submit('select_petugas1');"> //first combobox
<option></option>
<?php include 'dbconn.php';
$sql_peg1="SELECT * FROM users"; $result_peg1=$conn->query($sql_peg1);
while( $row_peg1=$result_peg1->fetch_assoc() ){
echo "<option>".$row_peg1['nama']."</option>";
}
?>
</select>
</td>
<td>
<?php
if(isset($_POST['select_petugas1'])){
$select_petugas1=$_POST['select_petugas1'];
echo "<input type='text' name='select_petugas1' value='".$select_petugas1."'>"; // Throw 1st result into the text box
$sql_NIP1="SELECT NIP FROM users WHERE nama='$select_petugas1'";
$result_NIP1=$conn->query($sql_NIP1);
$row_NIP1=$result_NIP1->fetch_assoc();
$NIP1=$row_NIP1['NIP'];
?>
</td>
<td> NIP</td>
<td>:</td>
<td><input type="text" name='NIP1' value="<?php echo $NIP1; ?>"></td>
</tr> <!-- child of first result -->
<tr>
<td colspan="5" bgcolor="blue"></td>
</tr>
<tr>
<td>
<select name="peg_2" style="width:18px;" onchange="submit(this)"><!--2nd combobox-->
<option></option>
<?php
$sql_peg2="SELECT nama FROM users";
$result_peg2=$conn->query( $sql_peg2 );
while ($row_peg2=$result_peg2->fetch_assoc()){
echo "<option value='".$row_peg2['nama']."'>".$row_peg2['nama']."</option>";
}
?>
</select>
</td>
<td>
<?php
if( isset($_POST['peg_2']) ){
$peg_2=$_POST['peg_2'];
echo "<input type='text' name='peg2' value='".$peg_2."'>"; // 2nd result throw into 2nd texbox
$sql_NIP2="SELECT NIP FROM users WHERE nama='$peg_2'";
$result_NIP2=$conn->query($sql_NIP2);
$row_NIP2=$result_NIP2->fetch_assoc();
?>
</td>
<td> NIP</td>
<td>:</td>
<td><input type='text' name='NIP2' value="<?php echo $row_NIP2['NIP'];?>"> <!--2nd child of result-->
<?php
}
}
if(isset($_POST['NIP2'])){
$NIP2=$_POST['NIP2'];
echo "<br /> NIP2 :".$NIP2."<br />";
}
mysqli_close($conn);
?>
</td>
</tr>
</table>
</form>
<form method="POST" name="wilayah" id="wilayah" action="<?php $_SERVER['PHP_SELF'];?>">
<table border="1">
<tr>
<td>
<select name="select_provinsi" onchange="submit(this)" style="width:18;">
<option selected>PROVINSI</option>
<?php
include 'dbconn.php';
$sql_prov="SELECT * FROM wilayah GROUP BY provinsi";
$result_prov=$conn->query($sql_prov);
echo "";
while($row_prov=$result_prov->fetch_assoc()){
$provinsi=$row_prov['provinsi'];
echo "<option value='".$provinsi."'>".$provinsi."</option>";
}
?>
</select>
<?php
if(isset($_POST['select_provinsi'])){
$select_provinsi=$_POST['select_provinsi'];
echo "
<input type='text' name='select_provinsi' value='".$select_provinsi."' placeholder='PROVINSI'>
</td>
</tr>";
$sql_kabkota="SELECT * FROM wilayah WHERE provinsi='$select_provinsi' GROUP BY kab_kota";
$result_kabkota=$conn->query($sql_kabkota);
?>
<tr>
<td>
<select name="select_kabkota" style="width:18px;" onchange="submit(this)"><option>KAB/KOTA</option>
<?php
while($row_kabkota=$result_kabkota->fetch_assoc()){
echo "<option>".$row_kabkota['kab_kota']."</option>";
}
?>
</select>
<?php
}
if(isset($_POST['select_kabkota'])){
$select_kabkota=$_POST['select_kabkota'];
?>
<input type="text" name="kab_kota" value="<?php echo $select_kabkota;?>">
<?php
}
mysqli_close($conn);
?>
</td>
</tr>
</table>
</form>
hope any suggestion for resolved of my problem with them,,
onchange="submit(this)" means that you want to submit the form when the value of the combobox changes. So, when the form is sent, the page reloads and you get the default value of your form.
To restore the chosen value, I would do something like :
<select name="select_kabkota" style="width:18px;" onchange="submit(this)">
<option>KAB/KOTA</option>
<?php
if(isset($_POST['select_kabkota']))
$select_kabkota=$_POST['select_kabkota'];
while($row_kabkota=$result_kabkota->fetch_assoc())
{
$selected = $select_kabkota == $row_kabkota['kab_kota'] ? 'selected="selected"' : '';
echo "<option ".$selected." >".$row_kabkota['kab_kota']."</option>";
}
?>
</select>

Populating dropdown - PHP Ajax MySQL

I have 2 dropdowns on my HTML page : The first drop down contains the database column names based on which the the second dropdown would be populated i.e.
I have a single table with fields: <Student Name, Degree, City> and following would be the entries;
1. "A", "BS", "New York"
2. "B", "BS", "Chicago"
3. "C", "MS", "Boston"
4. "D", "MS", "New York"
So my first dropdown would contain the column names i.e. "Degree" and "City".
If I select "Degree", the 2nd dropdown should populate "BS" and "MS" and if I select "City", the 2nd dropdown should select "New York", "Boston" and "Chicago".
How can I go about with the implementation?
[Adding my code]:
the changeSecond(first) method remains exactly the same as you suggested
<body>
<form method="POST" action="" name="mainForm">
<table>
<tr>
<td> Filter by: </td>
<td>
<div id="first">
<select onChange="changeSecond(this.value)">
<option value="1">All</option>
<option value="2">Degree</option>
<option value="3">City</option>
</select>
</td>
</tr>
<tr>
<td>&nbsp</td>
<td>
<div id="second">
<select name="val">
<option value=""></option>
</select>
</div>
</td>
</tr>
</table>
</form>
</body>
And this is the second_script.php as you suggested:
<?
$link = mysql_connect("localhost", "root", "");
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
if (mysql_select_db("myDatabase", $link))
{
$first=mysql_real_escape_string($_REQUEST["first"]);
$query="SELECT ".$first." FROM myTable GROUP BY ".$first;
$data=mysql_query($query);
echo "<select id=\"second\">";
while($row=mysql_fetch_row($data))
{
echo "<option value=\"".$row[0]."\">".$row[0]."</option>";
}
echo "</select>";
}
echo mysql_error();
?>
code for the main file in which you want to populate drop down based on other
in below example i show localities in child dropdown for that city that is selected in parent drop down
<script type="text/javascript">
function city_locality(val)
{
// alert (val);
url="<?php echo $this->baseurl ?>/components/com_ezportal/includes/query.php";
data="stid="+val;
$.post(url,data,function(data){
$("#locid").html(data);
});
}
</script>
<select name="filter_1state" id="filter_1state" onChange="city_locality(this.value)">
<option value="0">-- Select City --</option>
<option value="1">Lahore</option>
<option value="2">Karachi</option>
<option value="3">Islamabad</option>
<option value="4">Quetta</option>
<option value="5">Multan</option>
</select>
code for the file query.php
<?php
$link = mysql_connect('localhost', 'root', '');
mysql_select_db('mydatabase');
if (isset($_POST['stid']))
{
$stid = $_POST['stid'];
$query= mysql_query("SELECT id,ezcity FROM tbl_locality WHERE stateid = '".$stid."' GROUP BY ezcity");
?>
<option value="0">-- Select Locality --</option>
<?php
while($row = mysql_fetch_array($query))
{
?>
<option value="<?php echo $row['id']?>"><?php echo $row['ezcity']?> </option>
<?php
}
}
?>
If you want a more dynamic solution (that will accommodate changes to the background DB) you can do something like this on your page:
<script>
function changeSecond(first){
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var res=xmlhttp.responseText;
document.getElementById("second").innerHTML=res;
}
}
xmlhttp.open("GET","second_script.php?first="+first,true);
xmlhttp.send();
}
</script>
...
<select onChange="changeSecond(this.value)">
<option value="Degree">Degree</option>
<option value="City">City</option>
</select>
<div id="second"><select><option value=""></option></select></div>
and then a script similar to:
<?php
//database connection
$first=mysql_real_escape_string($_REQUEST["first"]);
$query="SELECT ".$first." FROM tablename GROUP BY ".$first;
$data=mysql_query($query);
echo "<select>";
while($row=mysql_fetch_row($data)){
echo "<option value=\"".$row[0]."\">".$row[0]."</option>";
}
echo "</select>";
?>
I guess for real flexibility you'd also want to dynamically populate that first one using mysql_field_name in another script similar to above
You could either have all the dropdown needed preloaded and hidden, and show them when the 'change' event is triggered in the first dropdown, or have two dropdowns and empty it on that same 'change' event.
If you choose the second approach you should buffer the data to insert in the dropdown list, partially or totally
You can use ajax for this purpose
eg1.html
<html>
<head><title></title>
</head>
<body>
<form method="POST" action="" name="mainForm">
<table>
<tr>
<td> Filter by: </td>
<td>
<div id="first">
<select id="first_dropdown">
<option value="All">All</option>
<option value="Degree">Degree</option>
<option value="City">City</option>
</select>
</td>
</tr>
<tr>
<td>&nbsp</td>
<td>
<div id="second">
<select id="second_dropdown">
</select>
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
<script src = "https://code.jquery.com/jquery-3.1.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#first_dropdown').change(function(){
$.ajax({
'type' : 'post',
'url' : 'getDropdownOptions.php',
'data': 'first=' + $(this).val(),
'success' : function(data) {
$('#second_dropdown').html(data);
}
});
});
});
</script>
getDropdownOptions.php
<?php
$link = mysql_connect("localhost", "root", "");
if (!$link) {
die('Could not connect: ' . mysql_error());
}
if (mysql_select_db("myDatabase", $link)) {
$first = mysql_real_escape_string($_REQUEST["first"]);
$query = "SELECT " . $first . " FROM myTable GROUP BY " . $first;
$data = mysql_query($query);
$rtn_data = '';
while ($row = mysql_fetch_row($data)) {
$rtn_data .= "<option value=\"" . $row[0] . "\">" . $row[0] . " </option>";
}
echo $rtn_data;
exit;
}
echo mysql_error();
?>
Divyesh here, your answer is
==============================
edit.php
==============================
<!-- edit.php -->
<?php
include("config.php");
$id=$_REQUEST['id'];
echo $id;
$query=mysqli_query($con,"SELECT * FROM register r
INNER JOIN country c ON r.cuid = c.cuid
INNER JOIN state s ON r.sid = s.sid
INNER JOIN city ct ON r.cid = ct.cid where id='$id'");
while($r=mysqli_fetch_array($query))
{
$fn=$r['firstname'];
$add=$r['address'];
$gn=$r['gender'];
$hobby=$r['hobby'];
$h=explode(',',$hobby);
$q=array('reading','traveling','cricket','drawing');
$country=$r['cuid'];
$state=$r['sid'];
$city=$r['cid'];
echo $gn;
$edu= $r['education'];
$email=$r['email'];
$pass=$r['password'];
$conpass=$r['conpassword'];
$phno=$r['phoneno'];
}
?>
<html>
<head>
<script src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#country').on('change',function(){
var countryID = $(this).val();
if(countryID){
$.ajax({
type:'POST',
url:'ajaxData.php',
data:'cuid='+countryID,
success:function(html){
$('#state').html(html);
$('#city').html(html);
}
});
}else{
$('#state').html(html);
$('#city').html(html);
}
});
$('#state').on('change',function(){
var stateID = $(this).val();
if(stateID){
$.ajax({
type:'POST',
url:'ajaxData.php',
data:'sid='+stateID,
success:function(html){
$('#city').html(html);
}
});
}else{
$('#city').html(html);
}
});
});
</script>
</head>
<body>
<form method="post" action="update.php">
<table border="1" align="center">
<caption>Edit user data</caption>
<tr>
<td>First name</td>
<td><input type="text" name="fn" value="<?php echo $fn;?>"></td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" name="add" value="<?php echo $add;?>"></td>
</tr>
<tr>
<td>Gender</td>
<td><input type="radio" name="gn" value="male" <?php echo ($gn=='male')?'checked':'' ; ?> size="17">Male
<input type="radio" name="gn" value="female" <?php echo ($gn=='female')?'checked':'' ; ?> size="17">Female
</td>
</tr>
<tr>
<td>Hobby</td>
<td><input type="checkbox" name="hobby[]" value="reading" <?php if(in_array('reading',$h)){echo ("checked:'checked'");}?> >reading
<input type="checkbox" name="hobby[]" value="traveling" <?php if(in_array('traveling',$h)){echo ("checked:'checked'");}?> >traveling
<input type="checkbox" name="hobby[]" value="cricket" <?php if(in_array('cricket',$h)){echo ("checked:'checked'");}?> >cricket
<input type="checkbox" name="hobby[]" value="drawing" <?php if(in_array('drawing',$h)){echo ("checked:'checked'");}?> >drawing</td>
</tr>
<?php
$query = mysqli_query($con,"SELECT * FROM country");
//Count total number of rows
$rowCount = mysqli_num_rows($query);
?>
<td>Country</td>
<td><select name="country" id="country">
<option value="<?php echo $country;?>"><?php echo $country;?></option>
<?php
if($rowCount > 0)
{
while($row = mysqli_fetch_array($query))
{
echo '<option value="'.$row['cuid'].'">'.$row['country'].'</option>';
}
}
else
{
echo '<option value="">Country not available</option>';
}
?>
</select>
</td></tr>
<tr>
<td>State</td>
<td>
<select name="state" id="state">
<option value="<?php echo $state;?>"><?php echo $state;?></option>
</select>
</td></tr>
<tr>
<td>City</td>
<td>
<select name="city" id="city">
<option value="<?php echo $city;?>"><?php echo $city;?></option>
</select>
</td>
</tr>
<tr>
<td>Education</td>
<td><input type="text" name="edu" value="<?php echo $edu;?>"></td>
</tr>
<td>Email</td>
<td><input type="text" name="email" value="<?php echo $email;?>"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="text" name="pass" value="<?php echo $pass;?>"></td>
</tr>
<tr>
<td>Confirm password</td>
<td><input type="text" name="conpass" value="<?php echo $conpass;?>"></td>
</tr>
<tr>
<td>Phone no</td>
<td><input type="text" name="phno" value="<?php echo $phno;?>"></td>
</tr>
<tr>
<td><input type="hidden" name="id" value="<?php echo $id;?>">
<input type="submit" name="update" value="update"></td>
</tr>
</table>
</form>
</body>
</html>
================
<h3>ajaxData.php</h3>
================
<!--ajaxData.php-->
<?php
//Include database configuration file
include("config.php");
if(isset($_POST["cuid"]) && !empty($_POST["cuid"]))
{
//Get all state data
$query = mysqli_query($con,"SELECT * FROM state WHERE cuid = ".$_POST['cuid']."");
//Count total number of rows
$rowCount = mysqli_num_rows($query);
//Display states list
if($rowCount > 0)
{
echo '<option value="">Select state</option>';
while($row = mysqli_fetch_array($query))
{
echo '<option value="'.$row['sid'].'">'.$row['state'].'</option>';
}
}
else
{
echo '<option value="">State not available</option>';
}
}
if(isset($_POST["sid"]) && !empty($_POST["sid"]))
{
//Get all city data
$query = mysqli_query($con,"SELECT * FROM city WHERE sid =".$_POST['sid']."");
//Count total number of rows
$rowCount = mysqli_num_rows($query);
//Display cities list
if($rowCount > 0)
{
echo '<option value="">Select city</option>';
while($row = mysqli_fetch_array($query))
{
echo '<option value="'.$row['cid'].'">'.$row['city'].'</option>';
}
}
else
{
echo '<option value="">City not available</option>';
}
}
?>

Categories