I'm currently making a shopping website and I need to be able to pass two variables to the next page, the code may be badly written because I'm new to this, but I'm trying to pass the number from the drop-down menu and the "row['pid']" to another page. As shown below I have attempted to use a form button but it can only transfer the number from the dropdown. There is database connected so if you try to load it up, it may not load anything. This issue is specifically focussing on the button which the form is linked to at the end. Thank you for your time.
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://kit.fontawesome.com/9114d9acc8.js" crossorigin="anonymous">
</script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="includes/navbar/navbar.css">
<link rel="stylesheet" href="css/style.css">
<title>Document</title>
</head>
<body>
<?php include "includes/navbar/navbar.php"; ?>
<div id="arranging">
<?php
require 'includes/dbh.php';
$query = sprintf('SELECT * FROM produce');
$result = mysqli_query($conn, $query);
//$var_value = 'hello';
//$_SESSION['varname'] = $var_value;
while ($row = mysqli_fetch_assoc($result)) {
if ($row['Quantity'] == 0) {
}
else {
?>
<div class="itemTemplate">
<a id="title" onclick="ContentPage(<?php echo $row['pid']; ?>)"><?php echo $row['Name'] ?></a>
<a onclick="ContentPage(<?php echo $row['pid']; ?>)" id="myid"><img src="<?php echo $row['img'] ?>"
alt="<?php echo $row['Name'] ?>"></a>
<span>Price: £<?php echo $row['Price'] ?></span>
<form action="includes/quickBasket.php" method="POST">
<div class="flex-b">
<label for="">Quantity:</label>
<select name="quantity">
<?php
if ($row['Quantity'] > 8) {
for ($x = 1; $x <= 8; $x++) {
echo "<option value='$x'>$x</option>";
}
}
else {
for ($x = 1; $x <= $row['Quantity']; $x++) {
echo "<option value='$x'>$x</option>";
}
}
?>
</select>
<button id="button" type="submit" name="cart" class="fas fa-shopping-basket"></button>
</div>
</form>
</div>
<?php
}
}
?>
</div>
<script>
function ContentPage(elem) {
location.href = "Product.php" + "?id=" + elem;
};
</script>
</body>
</html>
If you want to transfer the PID when the form is submitted then you need a field for it within the form, e.g. a hidden field like this:
<input type="hidden" name="pid" value="<?php echo $row['pid']; ?>"/>
Then when you submit the form, it will be accessible as $_POST["pid"] (just like the value from the dropdown is accessible as $_POST["quantity"]).
This applies to any value - if you want it to be submitted with the form, then there needs to be a proper field for it within the form (or least associated with the form via the necessary attribute).
Related
I was creating a page which will create a number of html forms in it's body using a php for loop and each form will submit the response to the page itself. But after creating it the webpage is looking fine, but none of the forms are working. Here is a picture of the page.
Webpage is looking completely fine.
And the code is here.
<?php
session_start();
date_default_timezone_set("Asia/Dhaka");
if(!isset($_SESSION["user"])||$_SESSION["user"]!="shihan04"){
echo "<script> location.href=\"https://sgtcmc.000webhostapp.com/contests/index.php\";</script>";
}
if($_SERVER["REQUEST_METHOD"] == "POST"){
$pp = $_POST["pp"];
$rep = test_input($_POST["rep"]);
$dn = test_input($_POST["dn"]);
$dir=getcwd()."/clarifications/";
$fa=fopen($dir.$dn,"r");
$unm=fgets($fa);$ppb=fgets($fa);$tm=fgets($fa);$sub=fgets($fa);$qs=fgets($fa);$repb=fgets ($fa);
fclose($fa);
$fa=fopen($dir.$dn,"w");
fwrite($fa,$unm.$pp."\n".$tm.$sub.$qs.$rep);
fclose($fa);
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Clarification Response</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="styles.css">
<script>MathJax = {tex: {inlineMath: [['$', '$'], ['\\(', '\\)']]},svg: {fontCache: 'global'}};</script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax#3/es5/tex-svg.js"></script>
</head>
<body>
<?php
$ad=getcwd()."/clarifications/";
$af=scandir($ad,1);
$ac=count($af)-2;
for($i=0;$i<$ac;$i++){
$fa=fopen($ad.$af[$i],"r");
$unm=fgets($fa);$pp=fgets($fa);$tm=fgets($fa);$sub=fgets($fa);$qs=fgets($fa);$rep=fgets($fa);
fclose($fa);
echo "<table class=\"table-sm table-bordered\">
<tr><th>Username</th><td>".$unm."</td></tr>
<tr><th>Time</th><td>".$tm."</td></tr>
<tr><th>Subject</th><td>".$sub."</td></tr>
<tr><th>Question</th><td>".$qs."</td></tr>
</table>";
echo "<div class=\"container-sm\">
<form method=\"post\" action=\"".htmlspecialchars($_SERVER["PHP_SELF"])."\">
<div class=\"form-group\">";
if($pp=="1\n"){
echo "<select class=\"form-control\" id=\"pp\" name=\"pp\">
<option value=\"1\">Public</option>
<option value=\"0\">Private</option>";
}
else{
echo "<select class=\"form-control\" id=\"pp\" name=\"pp\">
<option value=\"0\">Private</option>
<option value=\"1\">Public</option>";
}
echo "</select>
</div>";
echo "<div class=\"form-group\">
<input type=\"text\" class=\"form-control\" name=\"dn\" value=\"".$af[$i]."\" disabled>
</div>
<div class=\"form-group\">
<input type=\"text\" class=\"form-control\" placeholder=\"Reply\" name=\"rep\" value=\"".$rep."\">
</div>
<input type=\"submit\" name=\"submit\" value=\"Submit\" class=\"btn btn-outline-primary\">
</form></div><br>";
}
?>
</body>
I can't find the solution for this and I need to fix this in next 2-3 days. I'm a complete noob. So please help me with this.
I have this code
<html>
<head>
<meta charset="UTF-8">
<title> Game Library</title>
<link href="css/style.css" type="text/css" rel="stylesheet">
</head>
<body>
<div id="wrapper">
<div id="search">
<img id="del" src="img/delete.jpg" alt="Error">
<a class="A" href="index.php"><img class="AR" src="img/src.jpg" title="Search library"></a>
<a class="A" href="insert.php"><img class="AR" src="img/add.png" title="Add game"></a>
<div id="results">
<?php
require("inc/connection.php");
$query = "SELECT * FROM Library";
$result = mysqli_query($conn,$query);
if(mysqli_num_rows($result)>0){
while($row = mysqli_fetch_assoc($result)){
?><div id="results">
<form action="inc/delete.php" method="GET">
<input type="checkbox" name="checkbox[]" value="<?php echo $row['ID'] ?>">
<p id="p1">Name: <?php echo $row['Name']?>;</p>
<p>Genre: <?php echo $row['Genre']?></p>
<p>Release date: <?php echo $row['Release_date']?></p>
<p>Publisher: <?php echo $row['Publisher']?>:</p>
<p>Platforms: <?php echo $row['Platforms']?></p>
</div>
<?php
}?>
<input type="submit" name = "submit" value = "Submit"></form>
<?php
}else{
echo "No results!";
}
</div>
</div>
</div>
</body>
</html>
And I am supposed to create action="inc/delete.php" script which will allow me to delete multiple rows using checkbox and submit button. Can someone help me out with this please ? I honestly have no clue on how to complete this ....
<?php
if(isset($_POST['submit']))
{
if(!empty($_POST['checkbox']))
{
foreach ($_POST['checkbox'] as $key => $check)
{
// delete query
}
}
}
?>
NOTE: You failed to close PHP at line no. 40. Please make sure your PHP tag is closed or not.
Need to first set form method to `POST'
So, modify
<form action="inc/delete.php" method="GET">
To:
<form action="inc/delete.php" method="post">
And in inc/delete.php,
if (isset($_POST['submit'])){ // Check if form is submitted.
if (! empty($_POST['checkbox'])){ // Check if Checkbox is checked.
// Loop over the checkbox and get selected ids.
foreach($_POST['checkbox'] as $checkbox_id){
echo $checkbox_id."<br/>";
// Add your delete query here.
}
}
}
So the resolution is that you get at your delete script array of ids. You can parse that array and execute DELETE query for each id:
if(isset($_POST['checkbox']))
{
foreach($_POST['checkbox'] as $val)
{
$stmt = $conn->prepare("DELETE FROM Library WHERE id = ?");
$stmt->bind_param('i', $val);
$stmt->execute();
}
}
inc/delete.php
<?php
if(isset($_POST['submit'])){//to run PHP script on submit
if(!empty($_POST['checkbox'])){
// Loop to store and display values of individual checked checkbox.
foreach($_POST['checkbox'] as $row_id){
echo $row_id."</br>";
// DELETE QUERY HERE
}
}
}
?>
I am creating a quiz builder using SQL, HTML and PHP, whereby the user can insert their question and four answer choices for that question (A, B, C or D).
In the same form they can then choose what choice will be the correct answer from a dropdown. This should then assign the 'is correct' boolean value of that certain answer row to 1 in the database.
[my database structure and what my form should look like is attached]
<?php
include ("nav.php");
include("connect.php");
$quiz_id = htmlentities($_GET["quizid"]);
$quiz = "SELECT * FROM `q_quiz` WHERE q_quiz.id ='$quiz_id'";
$quizresult= $conn->query($quiz);
if(!$quizresult){
echo $conn->error;
}
?>
<html>
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="ui/styles.css">
<!-- UIkit CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.3/css/uikit.min.css" />
<!-- UIkit JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.3/js/uikit.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.3/js/uikit-icons.min.js"></script>
</head>
<body>
<div class ='uk-container'>
<?php
if (isset($_POST['submit'])) {
include("connect.php");
$newquest = $conn->real_escape_string($_POST['question']);
$insertquest = "INSERT INTO q_questions(quiz_id, question)
VALUES ('$quiz_id', '$newquest')";
$resultquest = $conn->query($insertquest);
$quest_id = $conn -> insert_id;
if (!$resultquest) {
echo $conn->error;
}
foreach ($_POST['ans'] as $ans) {
$answers = $conn->real_escape_string($ans);
$insertans = "INSERT INTO q_answers (question_id, answer) VALUES ('$quest_id', '$answers')";
$resultans = $conn ->query($insertans);
if (!$resultans) {
echo $conn->error;
} else {
header("Location: managequiz.php?quizid=$quiz_id");
}
} //END OF FOREACH LOOP
}
?>
<?php
while ($row = $quizresult->fetch_assoc()) {
$titledata = $row["title"];
}
?>
<div uk-grid>
<form class="uk-form-horizontal" method='POST' action='#'>
<input type='hidden' name='questionid' value=''>
<fieldset class="uk-fieldset">
<legend class="uk-legend">New question for quiz: <?php echo $titledata?></legend>
<div class="uk-margin">
<label class="uk-form-label">Question</label>
<div class="uk-form-controls">
<textarea class="uk-textarea" rows="5" placeholder="Enter your question here..." name='question' required></textarea>
</div>
</div>
<div class="uk-margin">
<div class="uk-form-label">A</div>
<div class="uk-form-controls uk-form-controls-text">
<input class="uk-input" id="form-horizontal-text" type="text" name='ans[]'>
</div>
<div class="uk-form-label">B</div>
<div class="uk-form-controls uk-form-controls-text">
<input class="uk-input" id="form-horizontal-text" type="text" name='ans[]'>
</div>
<div class="uk-form-label">C</div>
<div class="uk-form-controls uk-form-controls-text">
<input class="uk-input" id="form-horizontal-text" type="text" name='ans[]'>
</div>
<div class="uk-form-label">D</div>
<div class="uk-form-controls uk-form-controls-text">
<input class="uk-input" id="form-horizontal-text" type="text" name='ans[]'>
</div>
<div class="uk-form-label">Correct Answer:</div>
<div class="uk-form-controls">
<select class="uk-select" id="form-stacked-select">
<option value=''>A</option>
<option value=''>B</option>
<option value=''>C</option>
<option value=''>D</option>
</select>
</div>
<div uk-form-custom>
<input class="uk-button uk-button-default" type="submit" name='submit' tabindex="-1" value='Save & Continue'>
</div>
</div>
</fieldset>
</form>
</div>
</body>
</html>
as kiks73 mentioned, you can assign values to the option of the Select and POST the selected one to your database as correct answer ID.
<html>
<select class="uk-select" id="form-stacked-select" name="correctAnswer">
<option value='1'>A</option>
<option value='2'>B</option>
<option value='3'>C</option>
<option value='4'>D</option>
</select>
</html>
If you select A, the value "1" would be sent to your database as correct answer (as long as you correct the SQL part in your php.
EDIT:
I got your question a bit late, sorry.
you need to POST the select aswell in order to get the nessecary information about the correct answer. You could try something like that:
<?php
//just a counter
$i = 1;
//correct boolean 1 or 0
$bool = 0;
if (isset($_POST['submit'])) {
include("connect.php");
$newquest = $conn->real_escape_string($_POST['question']);
$insertquest = "INSERT INTO q_questions(quiz_id, question)
VALUES ('$quiz_id', '$newquest')";
$resultquest = $conn->query($insertquest);
$quest_id = $conn -> insert_id;
if (!$resultquest) {
echo $conn->error;
}
foreach ($_POST['ans'] as $ans) {
//get the value of the selected answer
$correctAnswer = $_POST['correctAnswer'];
//check if the selected one matches with our counter
if($i == $correctAnswer)
{
$bool = 1;
}
else
{
$bool = 0;
}
$answers = $conn->real_escape_string($ans);
$insertans = "INSERT INTO q_answers (question_id, answer, correct) VALUES ('$quest_id', '$answers', $bool)";
$resultans = $conn ->query($insertans);
if (!$resultans) {
echo $conn->error;
} else {
header("Location: managequiz.php?quizid=$quiz_id");
}
$i ++;
} //END OF FOREACH LOOP
}
?>
If you POST the whole form, you can use anything in it. i made an ugly loop, which checks each time you instert an answer to your SQL DB, if this one is selected.
I have this piece of code that i cant get the submit button to work properly
please help me. I have prepared 3 buttons which i havent worked on the action yet. But the button doesnt work even when i Just want to echo something
<?php
require_once '../dbinfo.inc.php';
session_start();
// CHECK IF THE USER IS LOGGED ON ACCORDING
// TO THE APPLICATION AUTHENTICATION
if(!isset($_SESSION['username'])){
echo <<< EOD
<h1>You are UNAUTHORIZED !</h1>
<p>INVALID usernames/passwords<p>
<p>LOGIN PAGE<p>
EOD;
exit;
}
// GENERATE THE APPLICATION PAGE
$conn = oci_pconnect(ORA_CON_UN, ORA_CON_PW, ORA_CON_DB);
// 1. SET THE CLIENT IDENTIFIER AFTER EVERY CALL
// 2. USING UNIQUE VALUE FOR BACK END USER
oci_set_client_identifier($conn, $_SESSION['username']);
$username = htmlentities($_SESSION['username'], ENT_QUOTES);
if (isset($_POST["ajax"]) && $_POST["ajax"] == 1){
$sql = "SELECT QTY FROM FABRICATION WHERE HEAD_MARK = '{$_POST["hm"]}'";
$cutting_sql = "SELECT CUTTING FROM FABRICATION WHERE HEAD_MARK = '{$_POST["hm"]}'";
$assembly_sql = "SELECT ASSEMBLY FROM FABRICATION WHERE HEAD_MARK = '{$_POST["hm"]}'";
$welding_sql = "SELECT WELDING FROM FABRICATION WHERE HEAD_MARK = '{$_POST["hm"]}'";
$drilling_sql = "SELECT DRILLING FROM FABRICATION WHERE HEAD_MARK = '{$_POST["hm"]}'";
$finishing_sql = "SELECT FINISHING FROM FABRICATION WHERE HEAD_MARK = '{$_POST["hm"]}'";
$stid = oci_parse($conn, $sql);
$stid_cutting = oci_parse($conn, $cutting_sql);
$stid_assembly = oci_parse($conn, $assembly_sql);
$stid_welding = oci_parse($conn, $welding_sql);
$stid_drilling = oci_parse($conn, $drilling_sql);
$stid_finishing = oci_parse($conn, $finishing_sql);
// The defines MUST be done before executing
oci_define_by_name($stid, 'QTY', $qty);
oci_execute($stid);
oci_define_by_name($stid_cutting, 'CUTTING', $cutting);
oci_execute($stid_cutting);
oci_define_by_name($stid_assembly, 'ASSEMBLY', $assembly);
oci_execute($stid_assembly);
oci_define_by_name($stid_welding, 'WELDING', $welding);
oci_execute($stid_welding);
oci_define_by_name($stid_drilling, 'DRILLING', $drilling);
oci_execute($stid_drilling);
oci_define_by_name($stid_finishing, 'FINISHING', $finishing);
oci_execute($stid_finishing);
// Each fetch populates the previously defined variables with the next row's data
oci_fetch($stid);
oci_fetch($stid_cutting);
oci_fetch($stid_assembly);
oci_fetch($stid_welding);
oci_fetch($stid_drilling);
oci_fetch($stid_finishing);
//echo quantity to the screen
echo "<b><font size='10'>".$qty."</font></b></br>";
if ($cutting == $qty){
echo "<p><b><font color='#FF8566' size='5'>CUTTING COMPLETED</font></b></p>";
} else {
$maxcutting = $qty - $cutting;
echo "<input id='cutting' name='cutting' type='number' min = '0' max = '$maxcutting' placeholder='CUTTING PROGRESS TODAY' class='input'/>";
}
if ($assembly == $qty){
echo "<p><b><font color='#FF8566' size='5'>ASSEMBLY COMPLETED</font></b></p>";
} else {
$maxassembly = $qty - $assembly;
echo "<input id='assembly' name='assembly' type='number' min = '0' max = '$maxassembly' placeholder='ASSEMBLY PROGRESS TODAY' class='input'/>";
}
if ($welding == $qty){
echo "<p><b><font color='#FF8566' size='5'>WELDING COMPLETED</font></b></p>";
} else {
$maxwelding = $qty - $welding;
echo "<input id='welding' name='welding' type='number' min = '0' max = '$maxwelding' placeholder='WELDING PROGRESS TODAY' class='input'/>";
}
if ($drilling == $qty){
echo "<p><b><font color='#FF8566' size='5'>DRILLING COMPLETED</font></b></p>";
} else {
$maxdrilling = $qty - $drilling;
echo "<input id='drilling' name='drilling' type='number' min = '0' max = '$maxdrilling' placeholder='DRILLING PROGRESS TODAY' class='input'/>";
}
if ($finishing == $qty){
echo "<p><b><font color='#FF8566' size='5'>FINISHING COMPLETED</font></b></p>";
} else {
$maxfinishing = $qty - $finishing;
echo "<input id='finishing' name='finishing' type='number' min = '0' max = '$maxfinishing' placeholder='FINISHING PROGRESS TODAY' class='input'/>";
}
echo '<section></br></br></br>';
echo ' <input type="submit" value="SUBMIT PROGRESS" class="button red" />';
echo ' <input type="reset" value="RESET FIELDS" class="button" /></br>';
echo ' <input type="submit" value="GO TO PAINTING" name="paint" class="button green" /></section>';
die;}
if (isset($_POST['submit'])){
echo $cutting;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title> Update Fabrication Progress</title>
<link type="text/css" rel="stylesheet" href="../css/goldenform/golden-forms.css"/>
<link type="text/css" rel="stylesheet" href="../css/goldenform/font-awesome.min.css"/>
<script type="text/javascript">
function OnSelectionChange (select) {
var selectedOption = select.options[select.selectedIndex];
//some ajax checkpoint
//alert ("The selected option is " + selectedOption.value);
jQuery.ajax({
url: location.href,
data: {'hm':selectedOption.value, 'ajax':1},
type: "POST",
success: function( data ) {
jQuery("#lbl_qty").html(data);//PRINT QTY TO THE SCREEN
}
});
//some ajax checkpoint
//alert('after ajax');
}
</script>
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
</head>
<body class="bg-wooden">
<div class="gforms">
<div class="golden-forms wrapper">
<form>
<div class="form-title">
<h2>FABRICATION UPDATE</h2>
</div><!-- end .form-title section -->
<div class="form-enclose">
<div class="form-section">
<fieldset>
<legend>  Select HEADMARK and the details will be shown <span class="bubble blue">1</span></legend>
<section>
<div class="row">
<div class="col4 first">
<label for="headmark" class="lbl-text tleft">HEADMARK :</label>
</div><!-- end .col4 section -->
<div class="col8 last">
<!-- POPULATED DROPDOWN LIST FROM THE DB -->
<label for="headmark" class="lbl-ui select">
<?php
$sql_hm_comp = 'SELECT HEAD_MARK FROM FABRICATION';
$result = oci_parse($conn, $sql_hm_comp);
oci_execute($result);
echo '<SELECT name="headmark" id="headmark" onchange="OnSelectionChange(this)">'.'<br>';
echo '<OPTION VALUE=" ">'."".'</OPTION>';
while($row = oci_fetch_array($result,OCI_ASSOC)){
$HM = $row ['HEAD_MARK'];
echo "<OPTION VALUE='$HM'>$HM</OPTION>";
}
echo '</SELECT>';
?>
</label>
</div>
</div>
</section><!-- END OF DROPDOWN LIST -->
<section>
<div class="row">
<div class="col4 first">
<label for="lnames" class="lbl-text tleft">Total Quantity:</label>
</div>
<div class="col8 last">
<!-- VALUE PASSED FROM AJAX PROCESSING -->
<label id='lbl_qty' class='lbl-ui'><font size='3'> </font></label>
</div>
</div>
</section>
</div><!-- end .form-section section -->
</div><!-- end .form-enclose section -->
<div class="form-buttons">
</div><!-- end .form-buttons section -->
</form>
</div><!-- end .golden-forms section -->
</div><!-- end .gforms section -->
<div></div><!-- end section -->
<div></div><!-- end section -->
</body>
</html>
Welcome to SO!
I found two small errors, I think it will do the trick:
Add post method to the form: <form method="post">
Add name attribute at least to one submit button:
<input type="submit" name="submit" value="SUBMIT PROGRESS" class="button red" />
Additionally it is recommended to use JS to determine which submit button has been clicked. For example you can add a hidden element, and modify its value:
echo '<input type="submit" value="GO TO PAINTING" ... onclick="$(\'[name=submit_clicked]\').val(\'no\');" />...';
...
<form method="post">
<input type="hidden" name="submit_clicked" value="yes" />
...
</form>
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.