Dynamic field in php

Alles, was PHP betrifft, kann hier besprochen werden.

Dynamic field in php

Postby pkimran » 09. April 2015 12:16

Hy
below are my code. all is working ok but their are two fields "town" "UC" they are relevant to each other,every town have specific UC numbers, i just want when i select any town name (Iqbal, jinnah, layllpur, or madina) the UC filed automatically filtered with specific union numbers related to town.
the code is below
thanks in advance
[code<html>

<title>Complaint Cell</title>
<head>




<style type="text/css">


table{ width:50px }



body{width:80%;margin:auto;min-width:800px;max-width:2000px}
</style>
<link href="style.css" rel="stylesheet" type="text/css">

<img src="logo.jpg" width="100%">
</head>
<body bgcolor="#66FFCC" >

<div style="background: #096" align="center" id="inner" class="wrap"><font color="#FFFFFF" style="font-size:22px" ><h3 style='background:#096;margin:0px;'> Complaint Cell Management System </h3></div></font>



<div align="center" id="inner" class="wrap">

<?php

//conenction file
include "connection.php";



//cleaning string
function cleanString ($string)
{
$string=htmlspecialchars (trim($string));
return $string;
}
//function for new form
function print_Form() {

$newform = "<form method=\"post\"action=\"{$_SERVER['PHP_SELF']}\">
<table border=5 vspace='10' cellpadding=6 cellspacing=6 bgcolor='#CCCCCC' bordercolor='#009900' >
<tr ><td ><b>Date</b></td>
<td><input type=\"text\"name=\"Date\"></td>

<td><b>Complaint_Number</b></td>
<td><input type=\"number\"name=\"Complaint_Number\"></td></tr>



<tr><td><b>Name</b></td>
<td><input type=\"text\"name=\"Name\"></td>

<td><b> Address</b> </td>
<td><input type=\"text\"name=\"Address\"></td></tr>


<tr><td><b>CNIC</b></td>
<td ><input type=\"text\"name=\"CNIC\"></td>

<td><b> Town </b> </td>
<td >
<select name=\"town\" value='town'>
<option value='Iqbal'>Iqbal</option>
<option value='Jinnah'>Jinnah</option>
<option value='Layllpur'>Layllpur</option>
<option value='Madina'>Madina</option>
</select>
</td></tr>



<tr><td><b>UC</b></td>
<td><input type=\"text\"name=\"UC\">










<td><b> Category </b> </td>
<td >
<select name=\"Category\" value='Category'>
<option value='Sweeping Related'>Sweeping Related</option>
<option value='Open Heap'>Open Heap</option>
<option value='Waste in Open Plot'>Waste in Open Plot</option>
<option value='Container Over Flow'>Container Over Flow</option>
<option value='Other'>Other</option>
</select>
</td></tr>

<tr>
<td><b> Status </b> </td>
<td >
<select name=\"Status\" value='Status'>
<option value='In Process'>In Process</option>
<option value='Delay'>Delay</option>
<option value='Resolved'>Resolved</option>
<option value='ReAssign'>ReAssign</option>
</select>
</td>
<td><b>Mobile</b></td>
<td><input type=\"number\"name=\"Mobile\"></td>


</tr>

<tr><td><b>Remarks</b></td>
<td><input type=\"text\"name=\"Remarks\"></td></tr>

</table>
<input type=\"submit\"value=\"Add Record\">
<input type=\"hidden\"value=\"true\"name=\"post\">

</form>";



return $newform;
}

//search form
function searchForm($action) {
print "<form method='get' action='$action'>
<table border=5 vspace='10' cellpadding=6 cellspacing=6 bgcolor='#CCCCCC' bordercolor='#009900' ><tr><td>
Search by Mobile Number,CNIC or Name:</td><td>
<input type='text' name='search' maxlength='15'></td>
</tr>

</table>

<input type='submit' value='Search'>

</form>";
}

//saving record
function save_Record() {
$Date= cleanString ($_POST['Date']);
$Complaint_Number= (int) cleanString ($_POST['Complaint_Number']);
$Name = cleanString ($_POST['Name']);
$Address = cleanString ($_POST['Address']);
$CNIC = cleanString ($_POST ['CNIC']);
$Town = cleanString($_POST ['town']);
$UC = cleanString ($_POST ['UC']);
$Category = cleanString($_POST ['Category']);
$Status = cleanString ($_POST ['Status']);
$Mobile = cleanString ($_POST ['Mobile']);
$Remarks = cleanString ($_POST['Remarks']);





//checking for empty values
if(empty ($Name) || empty($Address) || empty ($CNIC) || empty($Town) || empty($UC) || empty($Mobile) || empty($Category) || empty($Status) || empty($Remarks ))
{
error_Message ("Cannot insert empty record");
}
//query

$query = "INSERT INTO main(Date,Complaint_Number,Name,Address,CNIC,Mobile,Town,UC,Category,Status,Remarks)
VALUES('$Date',$Complaint_Number,'$Name','$Address',$CNIC,$Mobile,'$Town','$UC','$Category','$Status','$Remarks')";

//execute query
if(mysql_query ($query)) {
print "<div style='background:#FFFFCC;border:dashed 1px #CCCCCC' id='inner' class='wrap'>
Record added successfully </div>";
print print_Form(); //show form again
}else{
error_Message (mysql_error()); //if error in query

}
}
//error message
function error_Message ($error) {
$msg = "<div style='background:#FFFFCC;border:dashed 1px #CCCCCC' id='inner' class='wrap'>;
$error <a href='javascript:history.go (-1) '>Back</a></div>";
die($msg);
}
//function for record listing
function show_Records_List() {
//page name for link, this will same the page, require for pagging
$page_name = $_SERVER ['PHP_SELF'];
//get start value for page

$start =$_GET['start'];
if (!isset($start)) {
$start=0;
}
//records per page
$limit = 5;
//next and previous operation
$back = $start - $limit;
$next = $start + $limit;
//retrive data from table
$main2 = mysql_query ("SELECT * FROM main") or
error_Message (mysql_error());

//get number of records in table

$nume = mysql_num_rows ($main2);
$main = mysql_query ("SELECT * FROM main ORDER BY Complaint_Number DESC LIMIT $start,$limit") or
error_Message (mysql_error());
// if no record exist
if (mysql_num_rows ($main) <=0) {
error_Message ("No record in result table");
}

//table header

print "<table border=5 cellpadding=1 cellspacing=1 bgcolor='#CCCCCC' bordercolor='#009900' >

<tr >
<th >Date</th>
<th>Complaint_Number</th>
<th>Name</th>
<th>CNIC</th>
<th>Mobile</th>
<th >Address</th>
<th>Town</th>
<th>UC</th>
<th>Category</th>
<th>Status</th>
<th>Remarks</th>
<th>Edit Record</th>
<th>Delete</th></tr>";

// loop through record set, create table and show results
while ($Row = mysql_fetch_array ($main)) {
print
"<tr >
<td>" .$Row['Date']."</td>
<td>" .$Row['Complaint_Number']."</td>
<td>" .$Row['Name'] . "</td>
<td>" .$Row['CNIC'] . "</td>
<td>" .$Row['Mobile']."</td>
<td >" .$Row['Address'] . "</td>
<td>" .$Row['Town']."</td>
<td>" .$Row['UC'] . "</td>
<td>" .$Row['Category']."</td>
<td>" .$Row['Status'] . "</td>
<td>" .$Row['Remarks'] . "</td>
<td ><a href='edit.php?do=edit&Complaint_Number=" .$Row['Complaint_Number']."'>Edit</a></td>
<td > <a href='edit.php?do=del&Complaint_Number=" .$Row['Complaint_Number']."'>Delete</a></td></tr>";
}
print "</table>";

print "<br><table border=5 cellpadding=1 cellspacing=1 bgcolor='#CCCCCC' bordercolor='#009900' ><tr>
<td style='background:#EAEAEA;margin:0px; >";
//previous link
if ($back >= 0) {
print "<a href='$page_name?start=$back'>Prev</a>";
}
$j = 1;
//printing page numbers as bar
for ($i = 0; $i < $nume; $i= $i + $limit) {
if ($i <> $start) {
print "<a href='$page_name?start=$i'>$j</a>";
}


else
{
//current page will not displayed as link
print "<span style='font:bold;'>$j</span>" ;
}

$j++;
}
if ($next < $nume) {
print "<a href='$page_name?start=$next' > Next </a>";
}
print "</td></tr></table>";
//end of function
}

/*
$Query = "Select * from main order by Complaint_Number desc";
//executing query
$q_main = mysql_query ($Query) or
error_Message (mysql_error());
if (mysql_num_rows ($q_main) <=0) {
error_Message ("No record found");
}
print "<table border=1 width='50%'> <tr>
<th>Complaint_Number</th>
<th>Name</th>
<th> CNIC </th>
<th> Mobile </th>
<th>Address</th>
<th>Remarks</th>
<th>Edit</th>
<th>Delete</th></tr>";
//getting records and generating table (rows,cols)
while ($Row=mysql_fetch_assoc ($q_main))
{ print "<tr>
<td>" .$Row['Complaint_Number']."</td>
<td>" .$Row['Name']."</td>
<td>" .$Row['CNIC']."</td>
<td>" .$Row['Mobile']."</td>
<td>" .$Row['Address']."</td>
<td>" .$Row['Remarks']."</td>
<td align='center'> <a href='edit.php?do=edit&Complaint_Number=" . $Row['Complaint_Number'] ."'>Edit</a></td>
<td align='center'>
<a href='edit.php?do=del&Complaint_Number=" .$Row['Complaint_Number']."'>Delete</a></td></tr>";
}
{print "</table>";
}
*/

//what to do
if(isset($_POST
['post']) ){
// if form is POSTED
save_Record();
}else{
//first time print the form
print print_Form();
}

//Result listing
print "<h3 style='background:#096;margin:0px;'>
Record Listing</h3>";
searchForm ('search.php');
show_Records_List();


?>
</div>

</body>
</html>][/code]
pkimran
 
Posts: 10
Joined: 03. April 2015 14:21
Operating System: windows 7

Re: Dynamic field in php

Postby Nobbie » 09. April 2015 13:43

pkimran wrote:thanks in advance


What for? I cant find a question?!
Nobbie
 
Posts: 8779
Joined: 09. March 2008 13:04

Re: Dynamic field in php

Postby JJ_Tagy » 09. April 2015 14:52

pkimran wrote:all is working ok but their are two fields "town" "UC" they are relevant to each other,every town have specific UC numbers, i just want when i select any town name (Iqbal, jinnah, layllpur, or madina) the UC filed automatically filtered with specific union numbers related to town.


Just remember that PHP is executed SERVER side, not CLIENT side. So if you want PHP to accomplish this, only provide them one field and auto-populate based upon their response. If you want to accomplish this on the CLIENT side before submitting the form, your best bet is to use JavaScript to do the filtering for the user.
JJ_Tagy
 
Posts: 678
Joined: 30. January 2012 13:44
Operating System: Windows 10 Pro x64

Re: Dynamic field in php

Postby Altrea » 09. April 2015 15:49

We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8299
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Dynamic field in php

Postby davidsmith36 » 04. July 2016 14:31

<p>
<input type="button" value="Add Passenger" onClick="addRow('dataTable')" />
<input type="button" value="Remove Passenger" onClick="deleteRow('dataTable')" />
<p>(All acions apply only to entries with check marked check boxes only.)</p>
</p>

<table id="dataTable" class="form" border="1">
<tbody>
<tr>
<p>
<td >
<input type="checkbox" name="chk[]" checked="checked" />
</td>
<td>
<label>Name</label>
<input type="text" name="BX_NAME[]">
</td>
<td>
<label for="BX_age">Age</label>
<input type="text" class="small" name="BX_age[]">
</td>
<td>
<label for="BX_gender">Gender</label>
<select id="BX_gender" name="BX_gender">
<option>....</option>
<option>Male</option>
<option>Female</option>
</select>
</td>
<td>
<label for="BX_birth">Berth Pre</label>
<select id="BX_birth" name="BX_birth">
<option>....</option>
<option>Window</option>
<option>No Choice</option>
</select>
</td>
</p>
</tr>
</tbody>
</table>
User avatar
davidsmith36
 
Posts: 1
Joined: 04. July 2016 13:56
Location: USA
XAMPP version: 1.7.2
Operating System: Ubantu


Return to PHP

Who is online

Users browsing this forum: No registered users and 2 guests