How to search the match value with php from MySql - php

I have a problem here about how to search an exact value from database. Here i have my codes that are function normally but the problem is, when i search the value for example i search for "T1" and then the result show me for "T1", "T11", "T12", "T13" and some more. I just only the value that match with "T1" only be shown. Here my codes below
<?php
include_once("mysql_connect.php");
$output1 = '';
?>
<?php
if(isset($_POST['select'])) {
$selectq = $_POST['select'];
$query = mysql_query("SELECT * FROM asset_a WHERE Tag_no LIKE '%$selectq%' or
Speciality LIKE '%$selectq%' ") or die("could not search!");
$count = mysql_num_rows($query);
if($count == 0){
$output = 'There was no search results!';
}else{
while($row = mysql_fetch_array($query)) {
$tag = $row['Tag_no'];
$special = $row['Speciality'];
$output1 .= $special;
}
}
}
?>
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Testing</title>
</head>
<body>
<p>
<form name="form1" method="post" action="testq.php" >
<label for="textfield" style="font-family:'Gill Sans', 'Gill Sans MT', 'Myriad Pro',
'DejaVu Sans Condensed', Helvetica, Arial, sans-serif; font-size:20px">
Tag No:</label>
<select name="select" id="select" class="textfields" >
<option value="0">-- Select your tag no --</option>
<?php
$getallAsset_a = mysql_query("SELECT * FROM asset_a ");
while($viewallAsset_a = mysql_fetch_array($getallAsset_a)){
?>
<option id="<?php echo $viewallAsset_a ['Tag_id'];?>"><?php echo
$viewallAsset_a['Tag_no']; ?></option>
<?php } ?>
<input type="image" name="submit" id="submit" src="../Search.png"
formaction="testq.php" >
</p>
</select>
<p>
<label for="textfield">Text Field:</label>
<input type="text" name="special" id="textfield"value="<?php print ("$output1");?>" >
</p>
</form>
</body>
</html>

Related

For loop inserts only 1 MySQL record

I have been working on a form that allows entering a menu item for a cafe establishment, alongside its ingredients (arrays of data). Unfortunately, a problem came up as it only executes 1 query even though 2 or more ingredients were entered in the form (dynamic, jQuery).
Here is the PHP code:
<?php
include("session.php");
if (isset($_POST['submit'])) {
$productname = $_POST['product_name'];
$categoryID = $_POST['categoryID'];
$price = $_POST['srp'];
// ingredients
$ingredients = $_POST['ingredients'];
$qty = $_POST['qty'];
$measure = $_POST['measure'];
if (!empty($productname) && !empty($categoryID) && !empty($price) && !empty($ingredients) && !empty($qty) && !empty($measure)) {
for ($i=0; $i < count($ingredients); $i++) {
if ($ingredients[$i] != "" && $qty[$i] != "" && $measure[$i] != "") {
mysqli_query($db, "insert into individual_ingredients values ('', '$productname', '{$ingredients[$i]}', '{$qty[$i]}', '{$measure[$i]}')");
}
}
mysqli_query($db, "insert into end_products values ('', '$productname', '$price', '', '$categoryID')");
mysqli_query($db, "insert into audit_trail values ('', now(), '{$_SESSION['login_user']}', 'New end product added')");
header("location: end_products.php");
} else {
echo '<font color="red">'."Incomplete data entered".'</font>';
}
}
?>
And here is the HTML form and JQuery:
<html>
<head>
<title><?php echo $login_session; ?> | New End Product Record</title>
<link rel="stylesheet" href="css/main.css" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Bootstrap js library -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//add more fields group
$(".addMore").click(function(){
var fieldHTML = '<div class="form-group fieldGroup">'+$(".fieldGroupCopy").html()+'</div>';
$('body').find('.fieldGroup:last').after(fieldHTML);
});
//remove fields group
$("body").on("click",".remove",function(){
$(this).parents(".fieldGroup").remove();
});
});
</script>
</head>
<body>
HTML form:
<table style="margin: 5% -1% 0 -10%; font-size: 0.9em">
<tr>
<form action="new_end_product_record.php" method="post">
<td>Name</td>
<td><input type="text" name="product_name"></td>
<td>Raw Material/s Used</td>
<td>
<div class="fieldGroup">
<select name="ingredients[]">
<option value="">Ingredient</option>
<?php
$items_sql = "select name from raw_materials where status='Active'";
$get_items = mysqli_query($db, $items_sql);
while ($option = mysqli_fetch_assoc($get_items)) { ?>
<option value="<?php echo $option['name']; ?>"><?php echo $option['name']; ?></option>
<?php } ?>
</select>
<input type="text" name="qty[]" placeholder="Quantity" style="width:60px">
<select name="measure[]">
<option value="">Measure Unit</option>
<?php
$get_units = "select * from raw_material_measures";
$units = mysqli_query($db, $get_units);
while ($unit = mysqli_fetch_assoc($units)) {
?>
<option value="<?php echo $unit['full_name']; ?>"><?php echo $unit['full_name']; ?></option>
<?php } ?>
</select>
ADD
<br /><br />
</div>
<!-- second set -->
<div class="fieldGroupCopy" style="display: none;">
<div class="input-group">
<select name="ingredients[]">
<option value="">Ingredient</option>
<?php
$items_sql = "select name from raw_materials where status='Active'";
$get_items = mysqli_query($db, $items_sql);
while ($option = mysqli_fetch_assoc($get_items)) { ?>
<option value="<?php echo $option['name']; ?>"><?php echo $option['name']; ?></option>
<?php } ?>
</select>
<input type="text" name="qty[]" placeholder="Quantity" style="width:60px">
<select name="measure[]">
<option value="">Measure Unit</option>
<?php
$get_units = "select * from raw_material_measures";
$units = mysqli_query($db, $get_units);
while ($unit = mysqli_fetch_assoc($units)) {
?>
<option value="<?php echo $unit['full_name']; ?>"><?php echo $unit['full_name']; ?></option>
<?php } ?>
</select>
REMOVE
<br /><br />
</div>
</div>
</td>
</tr>
<tr>
<td>SRP</td>
<td><input type="text" name="srp"></td>
</tr>
<tr>
<td>Category</td>
<td>
<select name="categoryID">
<option value="">Select category...</option>
<!--list all categories in the database-->
<?php
$cat_query = "select category_ID, name from end_products_categories";
$get_cats = mysqli_query($db, $cat_query);
while ($option = mysqli_fetch_assoc($get_cats)) { ?>
<option value="<?php echo $option['category_ID']; ?>"><?php echo $option['name']?></option>
<?php } ?>
</select>
</td>
<!-- <td>Expiration</td>
<td><input type="date"></input></td> -->
</tr>
</table><br>
<input type="submit" class="button" name="submit" value="ADD RECORD">
<input type="reset" value="ERASE ALL">
</div></form>
</div>
</body>
</html>
Is there a problem with the loop or with the HTML form that prevents the second to the last set of values from being inserted? Any help would be appreciated.

Request Dropdown list

I have a dropdown list with 5 elements (Volleyball, Handball, Rugby, Basketball, Autres)
I wish for example to select the element "Rugby" in my form, then confirm.
My problem is when I wish to change my old choice in my form (edit); the element "Rugby" is not the element which has been save previously.
By default I always have the element "VolleyBall".
[![<td>Type de Club:</td><td>
<select name="type_club" style="width:144px">
<option>Volley-Ball</option>
<option>Hand-Ball</option>
<option>Rugby</option>
<option>Basket-Ball</option>
<option>Autres</option>
</select>][1]][1]
[1]: https://i.stack.imgur.com/xQ83B.png
Here is my code.
<?php
// including the database connection file
include_once("config_bd.php");
if(isset($_POST['update']))
{
$pk_club = mysqli_real_escape_string($mysqli, $_POST['pk_club']);
$nom_club = mysqli_real_escape_string($mysqli, $_POST['nom_club']);
$type_club = mysqli_real_escape_string($mysqli, $_POST['type_club']);
// checking empty fields
if(empty($nom_club) || empty($type_club)) {
if(empty($nom_club)) {
echo "<font color='red'>Le nom du club est vide.</font><br/>";
}
if(empty($type_club)) {
echo "<font color='red'>Le type du club est vide.</font><br/>";
}
} else {
//updating the table
$result = mysqli_query($mysqli, "UPDATE clubs SET nom_club='$nom_club',type_club='$type_club' WHERE pk_club=$pk_club");
//redirectig to the display page. In our case, it is index.php
header("Location: vue_club.php");
}
}
//getting id from url
$pk_club = $_GET['pk_club'];
//selecting data associated with this particular id
$result = mysqli_query($mysqli, "SELECT * FROM clubs WHERE pk_club=$pk_club");
while($res = mysqli_fetch_array($result))
{
$nom_club = $res['nom_club'];
$type_club = $res['type_club'];
}
?>
<html>
<head>
</head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Palais des Sports</title>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="style/style1.css">
<body>
<div class="bandeau-bleu">
<h2>Palais des Sports</h2>
<i class="material-icons"></i>
<i class="material-icons"></i>
</div>
<div class="form_encodage">
<h3>Cliquez ici pour afficher les enregistrements</h3>
<br />
<h4> Editer un enregistrement</h4><br />
<form name="form1" method="post" action="edit_club.php">
<table border="0">
<tr>
<td>Nom du Club:</td>
<td><input type="text" name="nom_club" value="<?php echo $nom_club;?>"></td>
</tr>
<tr>
<td>Type de Club:</td><td>
<select name="type_club" style="width:144px">
<option>Volley-Ball</option>
<option>Hand-Ball</option>
<option>Rugby</option>
<option>Basket-Ball</option>
<option>Autres</option>
</select>
</td></tr>
<td><input type="submit" name="update" class="bouton_bleu" value="Update"></td>
<td><input type="hidden" name="pk_club" value=<?php echo $_GET['pk_club'];?>></td>
</tr>
</table>
</form>
</div>
</body>
</html>
You can use selected property with options.
Below is updated code for dropdown you have put thin td.
Try this:
<td>Type de Club:</td><td>
<select name="type_club" style="width:144px">
<option <?php if(isset($type_club) and $type_club=='Volley-Ball'){ echo 'selected'; }?>>Volley-Ball</option>
<option <?php if(isset($type_club) and $type_club=='Hand-Ball'){ echo 'selected'; }?>>Hand-Ball</option>
<option <?php if(isset($type_club) and $type_club=='Rugby'){ echo 'selected'; }?>>Rugby</option>
<option <?php if(isset($type_club) and $type_club=='Basket-Ball'){ echo 'selected'; }?>>Basket-Ball</option>
<option <?php if(isset($type_club) and $type_club=='Autres'){ echo 'selected'; }?>>Autres</option>
</select>
</td>
Complete updated code:
<?php
// including the database connection file
include_once("config_bd.php");
if(isset($_POST['update']))
{
$pk_club = mysqli_real_escape_string($mysqli, $_POST['pk_club']);
$nom_club = mysqli_real_escape_string($mysqli, $_POST['nom_club']);
$type_club = mysqli_real_escape_string($mysqli, $_POST['type_club']);
// checking empty fields
if(empty($nom_club) || empty($type_club)) {
if(empty($nom_club)) {
echo "<font color='red'>Le nom du club est vide.</font><br/>";
}
if(empty($type_club)) {
echo "<font color='red'>Le type du club est vide.</font><br/>";
}
} else {
//updating the table
$result = mysqli_query($mysqli, "UPDATE clubs SET nom_club='$nom_club',type_club='$type_club' WHERE pk_club=$pk_club");
//redirectig to the display page. In our case, it is index.php
header("Location: vue_club.php");
}
}
//getting id from url
$pk_club = $_GET['pk_club'];
//selecting data associated with this particular id
$result = mysqli_query($mysqli, "SELECT * FROM clubs WHERE pk_club=$pk_club");
while($res = mysqli_fetch_array($result))
{
$nom_club = $res['nom_club'];
$type_club = $res['type_club'];
}
?>
<html>
<head>
</head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Palais des Sports</title>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="style/style1.css">
<body>
<div class="bandeau-bleu">
<h2>Palais des Sports</h2>
<i class="material-icons"></i>
<i class="material-icons"></i>
</div>
<div class="form_encodage">
<h3>Cliquez ici pour afficher les enregistrements</h3>
<br />
<h4> Editer un enregistrement</h4><br />
<form name="form1" method="post" action="edit_club.php">
<table border="0">
<tr>
<td>Nom du Club:</td>
<td><input type="text" name="nom_club" value="<?php echo $nom_club;?>"></td>
</tr>
<tr>
<td>Type de Club:</td><td>
<select name="type_club" style="width:144px">
<option <?php if(isset($type_club) and $type_club=='Volley-Ball'){ echo 'selected'; } ?>>Volley-Ball</option>
<option <?php if(isset($type_club) and $type_club=='Hand-Ball'){ echo 'selected'; } ?>>Hand-Ball</option>
<option <?php if(isset($type_club) and $type_club=='Rugby'){ echo 'selected'; } ?>>Rugby</option>
<option <?php if(isset($type_club) and $type_club=='Basket-Ball'){ echo 'selected'; } ?>>Basket-Ball</option>
<option <?php if(isset($type_club) and $type_club=='Autres'){ echo 'selected'; }?>>Autres</option>
</select>
</td></tr>
<td><input type="submit" name="update" class="bouton_bleu" value="Update"></td>
<td><input type="hidden" name="pk_club" value=<?php echo $_GET['pk_club'];?>></td>
</tr>
</table>
</form>
</div>
</body>
</html>
You will need to query your database before loading your select form to get the previous save then build your list
$sqla= "SELECT * FROM `save_table` WHERE `id` = $id ";
$result = $conn->query($sqla);
if ($result->num_rows > 0) {
$save = $row['save'];
$select= ('<td>Type de Club:</td><td>
<select name="type_club" style="width:144px">
<option>');
$select.='$save';
$select.='</option> <option>Volley-Ball</option>
<option>Hand-Ball</option>
<option>Rugby</option>
<option>Basket-Ball</option>
<option>Autres</option>
</select>';
echo $select;
You can also use if statements to remove the second $save variable from the list before you build it so there is no repeat option in the list.

Display database values on option

I am trying to display the saved data in the database on select before a user can update other choice. I am not really sure how to code it. Can anyone come out with possible solution? Had tried many ways but unable to do so.
Update: I have found out the problem why the options does not show.
This is my code:
`
$consentId = $_GET['consent_id'];
$retrieveConsent = "SELECT * FROM consent, leavetype WHERE consent.type_of_leave = leavetype.type_of_leave";
$retrieveResult = mysqli_query($link, $retrieveConsent) or die("Retrieve Error" . mysqli_error($link));
$queryleavetype = "SELECT * FROM leavetype";
$queryleaveresult = mysqli_query($link, $queryleavetype) or die("Leave Retrieve Error " . mysqli_error($link));
$row = mysqli_fetch_array($retrieveResult);
mysqli_close($link);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Edit Consent </title>
</head>
<body>
<div class="ui-content">
<h3><b>Edit Leave</b></h3>
<form action="doEditConsent.php" method="post" data-ajax="false">
<input type="hidden" name="cId" value="<?php echo $row['consent_id']; ?>"/>
<label for="dateFrom" ><b>Date From:</b></label>
<input type="date" id="dateFrom" name="newDateFrom" value="<?php echo $row['consent_date_from']; ?>" required>
<br>
<label for="dateTo" ><b>Date To:</b></label>
<input type="date" id="dateTo" name="newDateTo" value="<?php echo $row['consent_date_to']; ?>" required>
<br>
<label for="reason" ><b>Leave Type:</b></label>
<select name="leaveType" id="leaveType" data-mini="true">
<?php
while ($rowleave = mysqli_fetch_array($queryleaveresult)) {
?>
<option value="<?php echo $rowleave['type_of_leave']; ?>">
<?php echo $rowleave['leave_type']; ?>
</option>
<?php
};
?>
</select>
<br>
<button class="ui-btn ui-corner-all" type="submit" >Submit</button>
</form>
</div>
<?php
}
}
?>
</body>
</html>`
Try this, hopefully it will help you:
<select name="leaveType" id="leaveType" data-mini="true">
<option value=""></option>
<?php
$previous_selected_value = 'previous_selected_value';//get the previous value and assign it to this variable
while ($rowleave = mysqli_fetch_array($queryleaveresult)) {
$selected = ($rowleave['type_of_leave'] == $previous_selected_value) ? " selected='selected'" : "";
echo '<option value="'.$rowleave['type_of_leave'].'"'.$selected.'>'.$rowleave['leave_type'].'</option>';
}
?>
</select>

Having a hard time with displaying information from my database

I'm just learning PHP and I followed the book to the last detail and when I go to the localhost web page that I created to pull information from the database nothing shows on the webpage. I've troubleshooted all night I've Google and read the book over and over to see what I missed. I'm posting the code that I wrote to see if someone can lead me in the right area to fix my problem.
<html>
<head>
<title>Pay Scale</title>
<style type="text/css">
table {
background-color: #FCF;
}
th {
width:150px;
text-align: left;
}
</style>
</head>
<body>
<h1>Pay Scale</h1>
<form method= "post" action= "Payscale.php"
<input type="hidden" name="submitted" value="true" />
<label> Search Category:
<select name="category">
<option value="Id">ID</option>
<option value="First Name">First Name</option>
<option value="Last_Name">Last_Name</option>
</select>
</label> <label>Search Criteria:
<input type="text" name="criteria" />
</label>
<input type="submit" />
</form>
<?php
if (isset($_POST['submitted'])){
include('payconnect.php');
$category = $_POST['category'];
$criteria = $_POST['criteria'];
$query = "SELECT * FROM employee pay range WHERE $category = '$criteria'";
$result = mysqli_query($dbcon, $query) or die('error getting data');
echo "<table>";
echo "<tr> <th>ID</th> <th>First Name</th> <th>Last_Name</th> <th>Pay_Range</th> </tr>";
While($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo "<tr><td>";
echo $row['ID'];
echo "</td><td>";
echo $row['First Name'];
echo "</td><td>";
echo $row['Last_Name'];
echo "</td><td>";
echo $row['Pay_Range'];
echo "</td><tr>";
}
echo "<table>";
}
?>
</body>
</html>
There are a couple of problems with the html code for the page. The most obvious is that there is no closing > on your form tag, so the browser slurps up the next line, thinking that it is part of the form tag. Since that line sets the $_POST['submitted'] variable that your PHP script is looking for, the value doesn't get set and the script never runs.
To correct the problem, just add a > to your form declaration:
<form method="post" action="Payscale.php">
There are also a few other problems in the HTML that could be fixed at the same time:
At the top of the page:
<html>
<head>
A document should start with a DOCTYPE declaration so that the browser knows how to interpret the page. For HTML5, this is as simple as adding a line to the start of your file:
<!DOCTYPE html>
<html>
<head>
There is also an error in the table creation code:
echo $row['Last_Name'];
echo "</td><td>";
echo $row['Pay_Range'];
echo "</td><tr>"; # A
}
echo "<table>"; # B
The lines marked A, and B create new elements--a table row, and a new table respectively. You should be closing the elements--i.e. using </tr> and </table>.
It appears that your opening tag is not closed (a minor syntactical error).
Try changing it from this:
<form method= "post" action= "Payscale.php"
to this:
<form method="post" action="Payscale.php">
and see if that solves the problem.
Try this it's working :
<html>
<head>
<title>Pay Scale</title>
<style type="text/css">
table {
background-color: #FCF;
}
th {
width:150px;
text-align: left;
}
</style>
</head>
<body>
<h1>Pay Scale</h1>
<form method= "post" action="Payscale.php">
<input type="hidden" name="submit" value="true"/>
<label> Search Category:
<select name="category">
<option value="Id">ID</option>
<option value="First Name">First Name</option>
<option value="Last_Name">Last_Name</option>
</select>
</label> <label>Search Criteria:
<input type="text" name="criteria" />
</label>
<input type="submit" value="submit" name="submitted"/>
</form>
</body>
</html>
Payscale.php
<?php
if (isset($_POST['submitted'])){
include('payconnect.php');
$category = $_POST['category'];
$criteria = $_POST['criteria'];
$query = "SELECT * FROM employee pay range WHERE $category = '$criteria'";
$result = mysqli_query($dbcon, $query) or die('error getting data');
echo "<table>";
echo "<tr> <th>ID</th> <th>First Name</th> <th>Last_Name</th> <th>Pay_Range</th> </tr>";
While($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo "<tr><td>";
echo $row['ID'];
echo "</td><td>";
echo $row['First Name'];
echo "</td><td>";
echo $row['Last_Name'];
echo "</td><td>";
echo $row['Pay_Range'];
echo "</td><tr>";
}
echo "<table>";
}
?>

insert option in a listbox loaded from mysql

Hi guys i have made a listbox with data from a mysql database and now i want to give the user the possibility to insert an option that don't exists. Can anyone tell me how to do that? I want to create a form or another thing that allows the user to introduce a value for a new option and then it appears in listbox and forward get the value to save in mysql database.
Best regards.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="keywords" content="jquery,ui,easy,easyui,web">
<meta name="description" content="easyui help you build your web page easily!">
<link rel="stylesheet" type="text/css" href="jeasyui_src/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="jeasyui_src/themes/icon.css">
<link rel="stylesheet" type="text/css" href="jeasyui_src/demo/demo.css">
<script type="text/javascript" src="jeasyui_src/jquery.min.js"></script>
<script type="text/javascript" src="jeasyui_src/jquery.easyui.min.js"></script>
</head>
<body>
<script language='Javascript' type='text/javascript'>
function edit_file()
{
$("#button_file").css("visibility" , "hidden");
$("#file_new").css("visibility" , "visible");
}
</script>
<h3>Coloque aqui a sua revisao tecnica:</h3></br>
<?php
include_once 'acess_db.php';
$query = "select * from faqs_treeview where level=1 order by category_title";
$result = mysql_query($query);
?>
<table border='0'>
<tr>
<td>
<form method="POST" name="form1" id="t1" style="visibility: visible;">
<select name="cat_1" style="visibility: visible;">
<option>Selecione a categoria</option>
<?php
while($row = mysql_fetch_array($result))
{
$id = $row["id_category"];
$name = $row["category_title"];
echo "<option value='$id'>".$name."</option>";
}
?>
</select>
<input type="submit" name="submit1" onclick="open2();">
</form>
<?php
if(isset($_POST["cat_1"]))
{
// echo $_POST["cat_1"];
$id2 = $_POST["cat_1"];
$query1 = "select * from faqs_treeview where high_level=$id2";
$result1 = mysql_query($query1);
$form_visible = "visible";
}
else
{
$form_visible = "hidden";
}
?>
</td>
<td>
<form method="POST" name="myform2" id="t2" style="visibility: <?= $form_visible ?>">
<select name="cat_2" >
<option>Selecione a sub-categoria</option>
<?php
while($row1 = mysql_fetch_array($result1))
{
$id = $row1["id_category"];
$name = $row1["category_title"];
echo "<option value='$id'>".$name."</option>";
}
?>
</select>
<input type="submit" name="submit2" onclick="open3();">
<input type="hidden" name="cat_1" value="<?= $_POST["cat_1"]?>">
</form>
</td>
<?php
//echo $_POST["cat_2"];
if(isset($_POST["cat_2"]) )
{
$id3 = $_POST["cat_2"];
$query2 = "select * from faqs_treeview where high_level=$id3";
$result2 = mysql_query($query2);
$form_visible = "visible";
}
else
{
$form_visible = "hidden";
}
?>
<td>
<form method="POST" name="myform3" id="t3" style="visibility: <?= $form_visible ?>">
<select name="cat_3" >
<option>Selecione a sub-sub-categoria</option>
<?php
while($row2 = mysql_fetch_array($result2))
{
$id = $row2["id_category"];
$name = $row2["category_title"];
echo "<option value='$id'>".$name."</option>";
}
?>
</select>
<input type="submit" name="submit3" onclick="closeall();">
<input type="hidden" name="cat_1" value="<?= $_POST["cat_1"]?>">
<input type="hidden" name="cat_2" value="<?= $_POST["cat_2"]?>">
</form>
</td>
</tr>
</table>
You could use AJAX for it. I see you use jQuery, so a simple get or post-request should do the trick.
Here: jQuery .get you will find some examples on how to do this. After the item has been added to the database you can use jQuery to add it to your select-box.

Categories