FIRST NOTE: I have looked at some of the suggested answers on SO, unfortunately I still haven't found an answer.
I have noticed that in my update statement, the ID value of the item im attempting to edit is not being passed to editUrl.php. However, if I hard code an id number (i.e. WHEREid= '13'";) the update works perfectly.
QUESTION: Why is the value of 'id' not being passed to editUrl.php?
CODE:
editUrlForm.php file:
<!-- Include AJAX Framework -->
<script src="js/ajax.js" language="javascript"></script>
<!--Include Database connections info-->
<?php include('config.php'); ?>
<?php
$id = $_GET['id'];
if(isset($_GET['id'])) {
$cdquery="SELECT * FROM links WHERE `id` = '$id'";
$cdresult=mysql_query($cdquery) or die ("Query to get data from first table failed: ".mysql_error());
while ($row = mysql_fetch_assoc($cdresult)) {
echo "Edit URL:";
echo "<form action='javascript:update()' method='get'>";
echo "<table>";
echo "<tr>";
echo "<th>URL ID:</th> <td><label for='urlId'>". $row['id'] . "</label></td>";
echo "</tr>";
echo "<tr>";
echo "<th>Name:</th> <td><input name='name' type='text' id='name' value='". $row['name'] . "' size'30'></input></td>";
echo "</tr>";
echo "<tr>";
echo "<th>Release Time:</th> <td><input name='releaseTime' type='time' id='releaseTime' value='". $row['releaseTime'] . "'></input></td>";
echo "</tr>";
echo "<tr>";
echo "<th>Release Day:</th> <td><select name='releaseDay' id='releaseDay' value='". $row['releaseDay'] . "'> <option value='monday'>Monday</option> <option value='tuesday'>Tuesday</option> <option value='wednesday'>Wednesday</option> <option value='thursday'>Thursday</option> <option value='friday'>Friday</option> <option value='saturday'>Saturday</option> <option value='sunday'>Sunday</option> </select></td>";
echo "</tr>";
echo "<tr>";
echo "<th>Category:</th> <td><select name='category' id='category' value='". $row['category'] . "'> <option value='television'>Television</option> <option value='movie'>Movie</option> <option value='music'>Music</option> </select></td>";
echo "</tr>";
echo "<tr>";
echo "<th>Genre:</th> <td><select name='genre' id='genre' value='". $row['genre'] . "'> <option value='action'>Action</option> <option value='drama'>Drama</option> <option value='comedy'>Comedy</option> <option value='thriller'>Thriller</option> <option value='horror'>Horror</option> <option value='childrens'>Childrens</option> <option value='romantic'>Romantic</option> </select></td>";
echo "</tr>";
echo "<tr>";
echo "<th>URL:</th> <td><input name='url' type='text' id='url' value='". $row['url'] . "' size'250'></input></td>";
echo "</tr>";
echo "</table><br />";
echo "<input type='submit' name='Submit' value='Edit URL'/>";
echo "<input type='button' value='Cancel' onClick='actionCancel();return false;'/>";
echo "</FORM>";
}
}
?>
ajax function:
function update()
{
var name= encodeURIComponent(document.getElementById('name').value);
var releaseTime = encodeURIComponent(document.getElementById('releaseTime').value);
var releaseDay = encodeURIComponent(document.getElementById('releaseDay').value);
var category = encodeURIComponent(document.getElementById('category').value);
var genre = encodeURIComponent(document.getElementById('genre').value);
var url= encodeURIComponent(document.getElementById('url').value);
xmlhttp.open('get', 'editUrl.php?name='+name+'& releaseTime=' +releaseTime+'& releaseDay=' +releaseDay+'& category=' +category+'& genre=' +genre+'& url=' +url);
xmlhttp.onreadystatechange = urlRefresh;
document.getElementById("content02").innerHTML = "Processing Request. Please wait a moment...";
xmlhttp.send(null);
return;
}
editUrl.php file:
<!-- Include Database connections info. -->
<?php include('config.php'); ?>
<?php
$id = $_GET['id'];
$name = $_GET['name'];
$releaseTime = $_GET['releaseTime'];
$releaseDay = $_GET['releaseDay'];
$category = $_GET['category'];
$genre = $_GET['genre'];
$url = $_GET['url'];
$editUrl_sql = "UPDATE `links` SET `id` = '{$id}', `name` = '{$name}', `releaseTime` = '{$releaseTime}', `releaseDay` = '{$releaseDay}', `category` = '{$category}', `genre` = '{$genre}', `url` = '{$url}' WHERE `id` = '{$id}'";
$editUrl_sql= mysql_query($editUrl_sql) or die(mysql_error());
mysql_close($link);
?>
you do not passed id as parameter
your coude should look like:
var id = encodeURIComponent(document.getElementById('urlId').value);
xmlhttp.open('get', 'editUrl.php?name='+name+'&releaseTime=' +releaseTime+'&releaseDay=' +releaseDay+'&category=' +category+'&genre=' +genre+'&url=' +url+'&id=' +id);
Related
I have a dropdown list that is filled with some values from a MySQL table.
The issue i'm facing is that I cannot place the ID from the selected value into a variable.
This is my code up until now:
<?php
mysql_connect('localhost', 'confidential', 'confidential');
mysql_select_db('mydb');
$sql = "SELECT zone_naam FROM zone";
$result = mysql_query($sql);
echo "<select name='zone_1' id='zone_1'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['idzone'] . "'>" . $row['zone_naam'] . " </option>";
}
echo "</select>";
?>
I would think that I could get the value from $row['idzone'] by using the code below.
if(isset($_POST['submit'])) {
$zone_1 = $_POST['zone_1'];
$richting = $_POST['richting'];
$zone_2 = $_POST['zone_2'];
}
I've tried several things, but I cannot come to a solution.
If I want to do the same thing in HTML with self set data like below it always works, but whenever I want to use PHP for this purpose I seem to fail.
<select name="zone">
<option value="1">Zone1</option>
<option value="2">Zone2</option>
<option value="3">Zone3</option>
</select>
I hope you all understand what I mean and can help me to find the cause of this problem.
Best regards,
Rudibwoyyy
#Rudi
Then David is correct. If you submit the HTML from your post
<select name="zone">
<option value="1">Zone1</option>
<option value="2">Zone2</option>
<option value="3">Zone3</option>
</select>
you can use, according the select name "zone", the variable $_POST['zone'], assuming you are using <form method="post">, (otherwise it's $_GET['zone']) will contain the value (1, 2 or 3 respectively) of the selected entry.
If this doesn't work for you, check if the generated HTML Code hat the correct name.
Below is my code that works!! Thanks for all the tips
<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('confidential');
$sql = "SELECT * FROM zone";
$result = mysql_query($sql);
echo "<form type='submit' class='form-inline' action='' method='POST'>
<select name='zone_1' id='zone_1' class='form-control mb-2 mr-sm-2 mb-sm-
0'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='". $row['idzone'] . "'>" . $row['zone_naam'] . "
</option>";
}
echo "</select>";
echo "<form type=\"submit\" method=\"POST\"> ";
echo " <select name=\"richting\" class='form-control mb-2 mr-sm-2 mb-sm-0'> ";
echo " <option value=\"<-->\"> <--> </option> ";
echo " <option value=\"<--\"> <-- </option> ";
echo " <option value=\"-->\"> --> </option> ";
echo "</select> ";
$result2 = mysql_query($sql);
echo "<select name='zone_2' class='form-control mb-2 mr-sm-2 mb-sm-0'>";
while ($row = mysql_fetch_array($result2)) {
echo "<option value='" . $row['idzone'] . "'>" . $row['zone_naam'] . "
</option>";
}
echo "</select>";
echo "<br><br>";
echo "<input type='submit' value='Submit' name='submit' id='submit' class='btn btn-primary btn-sm'>";
echo "</form>";
if(isset($_POST['submit'])) {
$zone_1 = $_POST['zone_1'];
$richting = $_POST['richting'];
$zone_2 = $_POST['zone_2'];
}
?>
How do I retrieve data from a SQL table, modify the data and store it in another database table with multiple rows & columns and with single submit button I want insert every rows at a time I don't know how to get that hidden value and work properly with that
<?php
include"connect_database.php";
if(isset($_POST['submit'])) {
$amt = $_POST['total'];
if($amt > 0) {
$qry = "INSERT INTO attendance(rollno, name, year, attendance, reason) VALUES "; // Split the mysql_query
for($i=1; $i<=$amt; $i++) {
$qry .= "('".$_POST["rollno$i"]."', '".$_POST["name$i"]."', '".$_POST["year$i"]."', '".$_POST["attendance$i"]."', '".$_POST["reason$i"]."' ),"; // loop the mysql_query values to avoid more server loding time
}
$qry = substr($qry, 0, strlen($qry)-2);
$insert = mysqli_query($dbcon, $qry); // Execute the mysql_query
}
// Redirect for each cases
if($insert) {
$msg = '<script type="text/javascript">alert("added");</script>';
}
else {
$msg = '<script type="text/javascript">alert("Server Error, Kindly Try Again");</script>';
}
};
if (isset($_POST['select']))
{
$sql = "SELECT * FROM data WHERE year='" . $_POST['yr'] . "'";
$myData = mysqli_query($dbcon, $sql);
$num = mysqli_num_rows($myData);
echo "<table border=1>
<tr>
<th>Rollno</th>
<th>Name</th>
<th>Year</th>
<th>Attendance</th>
<th>reason</th>
</tr>";
for ($i=0; $i <$num; $i++)
{
$record = mysqli_fetch_array($myData);
echo "<form action=smanage.php method=post>";
echo "<tr>";
echo "<td>" . "<input type=text name=rollno$i value=" . $record['rollno'] . " </td>";
echo "<td>" . "<input type=text name=name$i value=" . $record['name'] . " </td>";
echo "<td>" . "<input type=text name=year$i value=" . $record['year'] . " </td>";
echo "<td> "."<select name=attendance$i >
<option value=Present >present</option>
<option value=Absent >Absent</option>
</select>"."</td>";
echo "<td>". "<textarea cols=15 rows=2 name=reason$i placeholder=Enter reason ...></textarea>" . "</td>" ;
echo "<td>" . "<input type=hidden name=total value=" . $i-1 . "</td>";
echo "</tr>";
}
echo"</table>";
echo "<input type=submit name=submit value=save class=Button3>";
echo "</form>";
};
mysqli_close($dbcon);
?>
you are opening multiple forms, for each row in your table on.
This causes your html to be invalid, just start the form before displaying the table.
You could use this html
<table>
<?php
for ($i = 0; $i < $num; $i++) {
$record = mysqli_fetch_array($myData);
?>
<tr>
<td><input type="text" name="rollno[<?= $record['rollno'] ?>]" value="<?= $record['rollno'] ?>" </td>
<td><input type="text" name="name[<?= $record['rollno'] ?>]" value="<?= $record['name']?>" </td>
<td><input type="text" name="year[<?= $record['rollno'] ?>]" value="<?= $record['year'] ?>" </td>
<td><select name="attendance[<?= $record['rollno'] ?>]" >
<option value="Present" >present</option>
<option value="Absent" >Absent</option>
</select></td>
<td><textarea cols="15" rows="2" name="reason[<?= $record['rollno'] ?>]" placeholder="Enter reason ..."></textarea></td>
</tr>
<?php
}
?>
</table>
with this your values will every row will be put into the $_POST-Array, you can access the values via the indexes (I am guessing rollno represents the ID of the dataset).
When you really only want to insert all the values into a table, you can leave the index out. Meaning you could write
<td><input type="text" name="rollno[]" value="<?= $record['rollno'] ?>" </td>
Instead of
<td><input type="text" name="rollno[<?= $record['rollno'] ?>]" value="<?= $record['rollno'] ?>" </td>
You don't need the hidden field, you can just count the items in the array.
$total = count($_POST['rollno']);
<?php
include"connect_database.php";
if(isset($_POST['submit'])) {
$amt = $_POST['total'];
$rollnos= $_POST['rollno'];
if($amt > 0) {
$qry = "INSERT INTO attendance(rollno, name, year, attendance, reason) VALUES "; // Split the mysql_query
$i=0;
foreach($rollnos as $rollno) {
$qry .= "('".$rollno."', '".$_POST["name"][$i]."', '".$_POST["year"][$i]."', '".$_POST["attendance"][$i]."', '".$_POST["reason"][$i]."' ),"; // loop the mysql_query values to avoid more server loding time
$i=$i+1;
}
$qry = substr($qry, 0, strlen($qry)-2);
$insert = mysqli_query($dbcon, $qry); // Execute the mysql_query
}
// Redirect for each cases
if($insert) {
$msg = '<script type="text/javascript">alert("added");</script>';
}
else {
$msg = '<script type="text/javascript">alert("Server Error, Kindly Try Again");</script>';
}
};
if (isset($_POST['select']))
{
$sql = "SELECT * FROM data WHERE year='" . $_POST['yr'] . "'";
$myData = mysqli_query($dbcon, $sql);
$num = mysqli_num_rows($myData);
echo "<table border=1>
<tr>
<th>Rollno</th>
<th>Name</th>
<th>Year</th>
<th>Attendance</th>
<th>reason</th>
</tr>";
for ($i=0; $i <$num; $i++)
{
$record = mysqli_fetch_array($myData);
echo "<form action=smanage.php method=post>";
echo "<tr>";
echo "<td>" . "<input type='text' name='rollno[]' value='" . $record['rollno'] . "'> </td>";
echo "<td>" . "<input type='text' name='name[]' value='" . $record['name'] . "'> </td>";
echo "<td>" . "<input type='text' name='year[]' value='" . $record['year'] . "'> </td>";
echo "<td> "."<select name='attendance[]' >
<option value='Present' >present</option>
<option value='Absent' >Absent</option>
</select>"."</td>";
echo "<td>". "<textarea cols='15' rows='2' name='reason[]' placeholder='Enter reason ...'></textarea>" . "</td>" ;
echo "<td></td>";
echo "</tr>";
}
echo "<input type='hidden' name='total' value='" . $i-1 . "'>";
echo"</table>";
echo "<input type='submit' name='submit' value='save' class='Button3'>";
echo "</form>";
};
mysqli_close($dbcon);
?>
The Problem: Trying to calculate sum of a total variable which is inside the table invoicesub in the Form Process (2nd page). Trying to make the sum(total) appear in 3rd page which is display_invoice and also get the customer_name in the form process page(2nd page). somehow $_get["$cust_name"]; is not working and im getting a blank from it. Next, after i can get the sum_total variable how do i parse all these to the 4th page using a form?
Edit:http://imageshack.com/a/img19/8729/btls.png (picture of output)
http://imageshack.com/a/img20/8744/s3ut.png (picture of my database)
Too low rep, i cant post images. I uploaded it to image shack. The 1 on top of the table is from the mysqli_num_rows. This is the first row i entered in the form page. The 2nd row is missing
edit:
New Invoicefinal
echo "<table border='1'>\n";
echo "<tr>\n";
echo "<th>Services Rendered</th>\n";
echo "<th>Quantity</th>\n";
echo "<th>Price($)</th>\n";
echo "<th>Discount(%)</th>\n";
echo "<th>Amount</th>\n";
echo "</tr>";
$cname = $_GET["cname"];
global $connection;
$sql1="SELECT description,quantity, amount, discount, total, SUM(total) as sumtotal FROM invoicesub WHERE cust_name='$cname' GROUP BY description ORDER BY id";
$result2 = mysqli_query($connection, $sql1) or die(mysqli_error($connection));
echo $count;
while ($rows = mysqli_fetch_array($result2)){
echo "<tr>";
echo "<td>" . $rows['description'] . "</td>";
echo "<td>" . $rows['quantity'] . "</td>";
echo "<td>" . $rows['amount'] . "</td>";
echo "<td>" . $rows['discount']. "%" . "</td>";
echo "<td>" ."$". $rows['total'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
<?php
$sql1="SELECT SUM(total) as total_amt FROM invoicesub WHERE cust_name='$cname'";
$result3 = mysqli_query($connection, $sql1) or die(mysqli_error($connection));
while ($rows = mysqli_fetch_array($result3)){
echo "<tr>";
echo "<td>". "Total Amount:" ."$". $rows['total_amt'] . "</td>";
echo "</tr>";
echo "<form action=\"4thpage.php\" method=\"POST\">";
echo "<input type=\"hidden\" name=\"total_amt\"/>";
echo "Customer Paid:";
echo "<input type=\"text\" name=\"paid\" value=\"\"/>";
echo "<input type=\"submit\" name=\"submit\" value=\"Submit\"/>";
echo "<input type=\"button\" value=\"Cancel\" onclick=\"window.location='manage_content.php';\"/>";
echo "</form>";
}
The Form: It consists of a form that can allow more than 1 row of inputs, which means i will have more than 2 descriptions, quantity, amount and discount. Thus, i put them inside an array
Form Process: This is the 2nd page, it will take in all the arrays parsed in, make a loop to insert all the inputted variables in the form into the table invoicesub.
Display_invoice: This is the 3rd page, i want to show all the customer_name, descriptions, quantity, amount, total_amt that was keyed into invoicesub and then do a sum(total) and show it at the bottom of the page. I also want to insert the customer_name, sum(total) variable into the fourth page through the form at display_invoice. Is this possible?
Form
function addTextArea(){
count= count+1;
var div = document.getElementById('name');
div.innerHTML += "<div> <input type='text' name='name[]' value='' "+"id=name"+count+"> </div>";
div.innerHTML += "\n<br />";
var div = document.getElementById('quantity');
div.innerHTML += "<div><input type='text' name='quantity[]' value ='' "+"id=quantity"+count+"></div>";
div.innerHTML += "\n<br />";
var div = document.getElementById('amount');
div.innerHTML += "<div><input type='text' name='amount[]' value ='' "+"id=amount"+count+"></div>";
div.innerHTML += "\n<br />";
var div = document.getElementById('discount');
div.innerHTML += "<div><input type='text' name='discount[]' value ='' "+"id=discount"+count+"></div>";
div.innerHTML += "\n<br />";
}
function removeTextArea(){
document.getElementById("name"+count).remove();
document.getElementById("quantity"+count).remove();
document.getElementById("amount"+count).remove();
document.getElementById("discount"+count).remove();
count = count-1;
}
</script>
</head>
<body>
<form action="invoiceprocess.php" method="POST">
<?php
echo "<table border='2'>\n";
echo "<tr>\n";
echo "<th>Description</th>\n";
echo "<th>Quantity</th>\n";
echo "<th>Amount($)</th>\n";
echo "<th>Discount(%)</th>\n";
echo "</tr>";
echo "<tr>";
echo "<td>"?><input type='text' size="50" name='name[]' value='Examination and Consultation' readonly/><?php "</td>";
echo "<td>"?><input type='text' size="50" name='quantity[]' value='' /><?php "</td>";
echo "<td>"?><input type='text' size="50" name='amount[]' value='' /><?php "</td>";
echo "<td>"?><input type='text' size="50" name='discount[]' value='' /><?php "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>"?><div id="name"></div> <?php "</td>";
echo "<td>"?><div id="quantity"></div> <?php "</td>";
echo "<td>"?><div id="amount"></div> <?php "</td>";
echo "<td>"?><div id="discount"></div> <?php "</td>";
echo "</tr>";
?>
Customer Name:
<br />
<input type="text" name="cust_name" value="" />
<br />
<input type="button" value="Add Description" onClick="addTextArea();">
<input type="button" value="Remove Description" onClick="removeTextArea();">
<input type="submit" name="submit" value="submit">
</form>
</body>
invoiceprocess (The 2nd page)
if (isset($_POST['submit'])){ // Process the form
$name_array = $_POST['name'];
$quantity_array = $_POST['quantity'];
$amount_array = $_POST['amount'];
$discount_array = $_POST['discount'];
$cust_name_array = mysql_prep( $_POST['cust_name']);
for ($i = 0; $i < count($name_array); $i++){
$cust_name = $cust_name_array;
$name = $name_array[$i];
$quantity = $quantity_array[$i];
$amount = $amount_array[$i];
$discount = $discount_array[$i];
$total_amt = ($amount - ($amount * ($discount / 100))) * $quantity;
global $connection;
$query = "INSERT INTO invoicesub (";
$query.= " cust_name, description, quantity, amount, discount, total";
$query.= ") VALUES (";
$query.= " '{$cust_name}', '{$name}', {$quantity}, {$amount}, {$discount}, {$total_amt}";
$query.= ")";
$result = mysqli_query($connection, $query);
}
redirect_to("invoicesubmitfinal.php?cname=".urlencode($cust_name));
}
Display_Invoice(invoicesubmitfinal.php)
echo "<table border='1'>\n";
echo "<tr>\n";
echo "<th>Customer_name</th>\n";
echo "<th>Description</th>\n";
echo "<th>Quantity</th>\n";
echo "<th>Amount($)</th>\n";
echo "<th>Discount(%)</th>\n";
echo "<th>Total_amt</th>\n";
echo "</tr>";
$cust_name = $_GET["$cust_name"];
global $connection;
$sql1="SELECT SUM(total) FROM invoicesub WHERE cust_name='$cust_name'";
$result2 = mysqli_query($connection, $sql1) or die(mysqli_error($connection));
while ($rows = mysqli_fetch_array($result2)){
echo "<tr>";
echo "<td>" . $rows['quantity'] . "</td>";
echo "<td>" . $rows['amount'] . "</td>";
echo "<td>" . $rows['discount']. "%" . "</td>";
echo "<td>" ."$". $rows['total'] . "</td>";
echo "<td>" . "$" . $total_amt . "</td>";
echo "</tr>";
<form action="insertfinal.php" method="POST">
Customer Paid:
<input type="text" name="paid" value="" />
</form>
Is it possible to fetch data from db upon changing value of my drop down, I want to pull up the data that corresponds to the value of the drop down and show it to a text area, I got the codes that I've tried to create just don't know how to make it work to what I want.
I want my page to just initially show the drop down then after selecting a value it will show the data in a text area without refreshing the page, here is the code:
<div id="mainContent">
<table width="619" border="0" align="center">
<td align="center"><form id="form1" name="form1" method="post" action="" >
<fieldset>
<legend><strong>EA</strong></legend>
<p>
<select name="ea_name" id="ea_name">
<option value="" selected="selected">Please select...</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</p>
</fieldset>
</form></td>
</table>
<div id="results"></div>
</div>
I am thinking an "onchange" could do it but just dont know how to implement it, also want to echo the resulting data to a text area within a fieldset.
Here is the code that I've tried that will pull up data and show to a text area:
<?php
require 'include/DB_Open.php';
$ea_name = $_POST['ea_name'];
$sql="SELECT * FROM ea_error WHERE ea_name = '" . $ea_name . "'";
$myData = mysql_query($sql);
//to count if there are any results
$numrow = mysql_num_rows($myData);
if($numrow == 0)
{
echo "No results found.";
}
else
{
echo "<fieldset><legend><strong>Information</strong></legend><p>
<table width="auto" height="172" border="0">
<tr><th scope="row">Error</th></tr>
<tr><th scope="row">Resolution</th></tr>
<tr><th scope="row">Contact/s</th></tr>;"
while($info = mysql_fetch_array($myData))
{
echo "<form action='retrieve.php' method='post'>";
echo"<tr>";
echo "<td align='center'>" . $info['error'] . "<input type=hidden name=error value=" . $info['error'] . " </td>";
echo "<td align='center'>" . $info['resolution'] . "<input type=hidden name=resolution value=" . $info['resolution'] . " size='11' maxlength='11' /> </td>";
echo "<td align='center'>" . $info['contacts'] . "<input type=hidden name=contacts value=" . $info['contacts'] . "' /> </td>";
echo "</tr>";
echo "</form>";
}
}
echo "</fieldset>";
include 'include/DB_Close.php';
?>
UPDATED CODE:
<?php
require 'include/DB_Open.php';
$ea_name = $_POST['ea_name'];
$sql="SELECT * FROM ea_error WHERE ea_name = '" . $ea_name . "'";
$myData = mysql_query($sql);
//to count if there are any results
$numrow = mysql_num_rows($myData);
if($numrow == 0)
{
echo "No results found.";
}
else
{
echo '<fieldset><legend><strong>Information</strong></legend><p>
<table width="auto" height="172" border="0">
<tr><th>Error</th></tr>
<tr><th>Resolution</th></tr>
<tr><th>Contact/s</th></tr>';
while($info = mysql_fetch_array($myData))
{
echo "<form action='retrieve.php' method='post'>";
echo"<tr>";
echo "<td align='center'>" . $info['error'] . "<input type=hidden name=error value=" . $info['error'] . " </td>";
echo "<td align='center'>" . $info['resolution'] . "<input type=hidden name=resolution value=" . $info['resolution'] . " size='11' maxlength='11' /> </td>";
echo "<td align='center'>" . $info['contacts'] . "<input type=hidden name=contacts value=" . $info['contacts'] . "' /> </td>";
echo "</tr>";
echo "</form>";
}
}
echo "</fieldset>";
include 'include/DB_Close.php';
?>
This should do the trick. Just put this javascript either in script tags in the head of your page, after the jQuery include, or in another js file and include that after jQuery...
$(function() { // document.ready
$("#ea_name").on("change", function() {
$.ajax({
url: "phpfile.php",
type: "POST",
data: {
ea_name: $(this).val()
},
success: function(data) {
$("#results").html(data);
}
});
});
});
It assigns an event handler to the change event of the drop down. When this is triggered it sends an ajax request to your php file (don't forget to put the correct filename for the url!) which then returns the html. This is then pushed into the results div.
Note: I fixed a typo that may or may not be in your php file. At the end of the line where you create the query, you'd missed a closing ". Just in case that was a copy and paste from the real file.
You have to implement ajax call to php file with ea_name as post parameter file. and place response to specific div.
I am using the following code to select a variable for a query. I need a value/variable to be automatically selected when the page loads.
$ID_SOCIEDAD = $_POST['Country'];
echo "<form name='country_list' method='POST' action='http://opben.com/colombia/familias-de-carteras' >";
echo "<select name='Country' >";
while($row = mysql_fetch_array($result))
{
echo " <option selected value='". $row['Fund_Manager_Company_Code'] ."'>". $row['Fund_Manager_Company_Name'] ."</option>";
}
echo " </select>
<input type='submit' value='Filter' />";
echo "</form>";
use this code
<?=($_POST['country']== $row['Fund_Manager_Company_Code']) ?"selected='selected'" : "" ?>
or
echo ($_POST['country']== $row['Fund_Manager_Company_Code']) ?"selected='selected'" : "";