users register to site. admin will login & see list of users.
I am trying to give an option for admin to select checkbox and change status of user through Dropdown submit. when i tried below code i can able to select "Y/N/A" , after clicking submit button its displaying message "Added Successfully" , but its not updating values in database.
table name : tbl_users , column : userStatus [enum] , values : Y, N, A
form
<form method="post" action="ajax1.php">
<select name="userStatus">
<option value="N">N</option>
<option value="Y">Y</option>
<option value="A">A</option>
</select>
<button type="submit" name="submit" >Submit</button>
</form>
ajax1.php
if(isset($_POST["submit"]))
{
$userStatus=$_POST["userStatus"];
$conn = new Database();
$stmt = $conn->dbConnection()->prepare("INSERT INTO tbl_users (userStatus) VALUES ('$userStatus')");
echo " Added Successfully ";
}
code to display users checkbox, id, name ,email :
$stmt = $user_home->runQuery("SELECT * FROM tbl_users");
$stmt->execute(array(":uid" => $_SESSION['userSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->execute();
$status = array('Y'=>'Verified','N'=>'Not verified' , 'A'=>'Approved');
echo "<table>";
echo "<tr>
<td></td>
<td>id</td>
<td>name</td>
<td>email</td>
</tr>";
while($data = $stmt->fetch())
{
echo "<tr>
<td> <input type='checkbox' > </td>
<td>" . $data['userID'] . "</td>
<td>" . $data['name'] . "</td>
<td>" . $data['email'] . "</td>
</tr>";
}
echo "</table>";
i researched & tried lot before posting question, in some links i saw we need to use Javascript, but in some other links, they mentioned we can achieve only with php.
i am very new to coding, please help me
Edit
after following below answer , i updated code as $stmt = $conn->dbConnection()->prepare('UPDATE tbl_users SET userStatus = ? WHERE userID = ?');
<form method="post" action="ajax1.php">
<select name="userStatus" id="userStatus" onchange="UpdateStatus();">
<option value="N">N</option>
<option value="Y">Y</option>
<option value="A">A</option>
</select>
<button type="submit" name="submit" >Submit</button>
</form>
<script>
function UpdateStatus(){
var staus=$('#userStatus :selected').val();
allCheckedBoxes="";
$("input[id^='checkBoxId']:visible:checked").each(function(){ // this is to get checked checkbox vaues to update which user to update
allCheckedBoxes=allCheckedBoxes+$(this).val()+","; // comaseparated valuse
});
var dataString="allCheckedBoxes="+allCheckedBoxes+"&staus="+staus;
$.post("aupdate_status.php",'allCheckedBoxes='+allCheckedBoxes'&staus='+staus,function(result,status,xhr)
{
if( status.toLowerCase()=="error".toLowerCase() )
{ alert("An Error Occurred.."); }
else
{
alert(result);
}
})
.fail(function(){ alert("something went wrong. Please try again") });
}
</script>
update_status.php
<?php
$staus=$_POST['staus'];
$allCheckedBoxes=$_POST['allCheckedBoxes'];
$ArrallCheckedBoxes=explode(",",$allCheckedBoxes);
foreach($ArrallCheckedBoxes as $tempBoxes){
$sqlQueryToUpdate=" UPDATE tbl_users SET userStatus = '".$staus."' WHERE userID = '".$tempBoxes."' ;";
$conn = new Database();
$stmt = $conn->dbConnection()->prepare($sqlQueryToUpdate);
echo " ok success";
}
?>
Please try this . This is working in my case. This will work you too. Don't forget add jquery in your coding.
What you are doing is actually inserting a new row to the table with this line:
"INSERT INTO tbl_users (userStatus) VALUES ('$userStatus')"
You should do an UPDATE, not an insert. What you basically want to do is UPDATE the user WHERE the user userID (or whatever the id column is named) is the id of the selected user.
See MySQL UPDATE.
Related
I have a drop down pull from an oracle database. when I select a drop down value and click a show details button , the details show but the drop down defaults back to the first one in the list. I need it to stay on the selected value.
I am doing this in PHP
I have tried this but it cannot recognize the
<form name= "fund" method="post" >
<label id= "fund" for="fund">Fund:</label>
<Select name="fund" id="fund">
<option value="--Select A Fund--">--Select a Fund--</option>
<?php
$sql = 'SELECT Account_name ||\' - \'|| Fund_id as FUND, FUND_ID FROM FUND_ACCOUNTS';
$stid = oci_parse($conn, $sql);
$success = oci_execute($stid);
while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS+OCI_ASSOC))
{
$selected = (!empty($_POST['fund']) && $_POST['fund'] == $row['FUND']) ? 'selected' : '';
echo '<option value="' . $row['FUND'] . '" ' . $selected . '>' . $row['FUND'] . '</option>';
}
?>
</select>
<input type="submit" name="fund"
value="Show Current Fund Investors"/>
</form>
<BR>
<?php
echo 1 . $row['FUND'];
echo 1 . $_POST['fund'];
?>
But $selected is never populated. Not sure where to go from here, and I am not a web developer. Any ideas where I am going wrong ?
the output of the final echos is 11Show Current Fund Investors
Likely this line just needs to do this:
$selected = (!empty($_POST['fund']) && $_POST['fund'] == $row['FUND'])) ? 'selected' : '';
What you have is matching the default option with || ($row['FUND'] == '--Select A Fund--') and probably also adding selected to the one you actually do select from the drop down. View the page source in the browser, there might be two options with the selected attribute.
By default, if nothing is selected, it will just show the first item in the dropdown which is --Select A Fund-- anyway.
Also you probably should have a space before the $selected variable and after the quote:
echo '<option value="' . $row['FUND'] . '" ' . $selected . '>' . $row['FUND'] . '</option>';
Should come out to:
<option value="whatever" selected>Whatever</option>
Edit
Based on your edit, you need to remove the name attribute from the submit button, or rename it. It’s conflicting with your select name.
<input type="submit" value="Show Current Fund Investors"/>
A tip:
You should encapsulate your fetching of that list in a function (at the very least) and include it in the page at the top:
/functions/fetchFundAccounts.php
<?php
function fetchFundAccounts($conn)
{
$stid = oci_parse($conn, 'SELECT Account_name ||\' - \'|| Fund_id as FUND, FUND_ID FROM FUND_ACCOUNTS');
$success = oci_execute($stid);
$results = [];
while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS+OCI_ASSOC)) {
$results[] = $row;
}
return $results;
}
To use:
<?php include(__DIR__.'/functions/fetchFundAccounts.php') ?>
<form name= "fund" method="post" >
<label id= "fund" for="fund">Fund:</label>
<select name="fund" id="fund">
<option value="--Select A Fund--">--Select a Fund--</option>
<?php foreach(fetchFundAccounts($conn) as $row): ?>
<option value="<?php echo $row['FUND'] ?>" <?php echo (!empty($_POST['fund']) && $_POST['fund'] == $row['FUND']) ? 'selected' : '' ?>><?php echo $row['FUND'] ?></option>
<?php endforeach ?>
</select>
<input type="submit" value="Show Current Fund Investors"/>
</form>
My intention is to create a form in HTML where the user could register some quality features of a product. The number of features to be registered varies according to the model, this info is registered on a table in SQL.
So far I manage to generate the inputs, but it is very fast, the user cannot fill all the inputs.
## query to get the product information from database ##
$query_list = "SELECT * FROM data_products";
$result_list = mysqli_query($conn, $query_list);
## get the number of rows
$query_data_rows = mysqli_query($conn, $query_list);
$data_rows = mysqli_fetch_array($query_data_rows);
?>
## here is the first form, where the user selects the product model,
## therefore it should query the number of raws (n) registered on the table
<div class="container">
<form action="" method="post" onsubmit="getdata()">
<select name="select1">
<option value=" "> </option>
<?php
while ($row = mysqli_fetch_array($result_list)) {
echo "<option value='" . $row['customer_Id'] . "'>" . $row['customer_Id'] . "</option>";
}
?>
</select>
<input type="submit" name="submit" value="Go"/>
</form>
</div>
## here my intention is to return the (n) number of input fields
## it correctly displays the number of input fields, but it is very fast
## I am missing something here
<?php
if(isset($_POST['select1'])){ ?>
<form id="form" action="" method="post">
<input type="submit">
</form>
<?php
}
?>
## I am almost zero skilled on Javascript,
## but browsing on the world web wide and reading the documentation of the language
## I got the code below.
<script>
function getdata() {
var no = <?php echo $data_rows['number'] ;?>;
for(var i=0;i<no;i++) {
var textfield = document.createElement("input");
textfield.type = "text";
textfield.value = "";
textfield.name = i+1 + "a"
textfield.placeholder = i+1
document.getElementById('form').appendChild(textfield);
}
}
</script> ```
Here what actually happening is that when you are submitting the form getdata() function is called till the it get submitted, after submission is done the content called by function disappears, in order to avoid this use return false statement at the end of the function.
<div class="container">
<form action="" id="form_id" method="post" onsubmit="return getdata()">
<select name="select1">
<option value=" "> </option>
<?php
//accesing the database table
$query_list = "SELECT * FROM `data_products`";
$result = mysqli_query($conn, $query_list);
//to get rows
$data_rows = mysqli_num_rows($result);
echo $data_rows;
while ($row = mysqli_fetch_array($result)) {
echo "<option value='" . $row['srno'] . "'>" . $row['srno'] . "</option>";
}
?>
</select>
<input type="submit" name="submit" value="go"/>
</form></div>
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST' ){
echo '<form id="form" action="" method="post">
<input type="submit">
</form>';
}
?>
<script>
function getdata() {
var no = <?php echo $data_rows;?>;
for(var i=0;i<no;i++) {
var btn = document.createElement("INPUT");
btn.type = "text";
btn.value = "";
btn.name = i+1 + "a"
btn.placeholder = i+1
document.getElementById('form').appendChild(btn);
}
return false;
}
</script>
This is working. Here I have made some changes in your code like replacing 'textfield' with 'btn', 'customerid' with 'srno' (for easy understanding) and avoid using php again and again.
I have search google, here and w3schools but this answer i cant find anyway. Not even in the "questions that may already have your answer".
I am trying to learn a bit more about AJAX and i have come to a hold at this guide W3schools AJAX database
All the guide i can get to work but when i try to suit it to my needs it goes wrong. What i want is that when i get to "getuser.php" i want to be able to update db in this file. If possible without me leaving this page with the result i have found. I choose from a dropdown table before this site. The php files which is supposed to update the db works (tried them on a normal page, and all is good). My current workaround is to add a button which opens a second window to update the info.
When i get to this point:
<?php
$q = intval($_GET['q']);
include 'db.php';
$con = new mysqli($servername, $username, $password, $dbname);
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"webhelp");
$sql="SELECT * FROM advisors WHERE id = '".$q."'";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_assoc($result)) {
echo "<table><tr><td>Phone</td><td>" . $row['phone'] . "</td>
<td><form action='addphone.php' method='post'>
<input type='hidden' name='id' value='".$q."'>
<td><input type='text' name='phone'></td>
<td><input type='submit' value='Update'></td>
</form></td></tr></table>";
echo "<tr><td>LoB</td><td>" . $row['lob'] . "</td>
<td><form action='addlob.php' method='post'>
<input type='hidden' name='id' value='".$q."'>
<td><select name='lob'>
<option value='". $row['lob'] ."'>" . $row['lob'] . "</option>".
$sql = "SELECT * FROM lob";
$result = $con->query($sql);
while($row = $result->fetch_assoc()) {
echo "<option value='" . $row["lob"] . "'>" . $row["lob"] . "</option>"; }
"</select></td>
<td><input type='submit' value='Update'></td>
</form>
</tr>";
echo "<tr><td>Country</td><td>" . $row['country'] . "</td>
<td><form action='addcountry.php' method='post'>
<input type='hidden' name='id' value='".$q."'>
<td><select name='country'>
<option value='". $row['country'] ."'>" . $row['country'] . "</option>".
$sql = "SELECT * FROM country";
$result = $con->query($sql);
while($row = $result->fetch_assoc()) {
echo "<option value='" . $row["country"] . "'>" . $row2["country"] . "</option>" ; }
"</select></td>
<td><input type='submit' value='Update'></td>
</form>
</tr>";
}
echo "</table>";
mysqli_close($con);
?>
The "Update" buttons doesnt work. It doesnt matter where i place the files (same folder, different folder) ect. However if i add a button with a link outside of the then that button work. But as soon as it is inside a table PLUS also method="post" is in the form it mess it up.
What am i doing wrong?
Alternatively is it possible to make a button here which carries the $id over to a small popup window? (I can open it in a new window but I can't choose how big the window should be)
You want to do this for all your 3 forms. I give you example for first one.
Form
echo "<form class='addPhoneForm' action='addphone.php' method='post'>
<table>
<tr>
<td>Phone</td><td>" . $row['phone'] . "</td>
<td><input class='phoneID' type='hidden' name='id' value='".$q."'></td>
<td><input class='phoneNumber' type='text' name='phone'></td>
<td><input class='submitme' type='submit' value='Update'></td>
</td>
</tr>
</table>
</form>";
AJAX
$(document).ready(function(){
$(".submitme").click(function(){
//collect variables from input
var phoneID = $(".phoneID").val();
var phoneNumber = $(".phoneNumber").val();
// store in a string
var dataAddPhone = 'phoneID='+ phoneID + '&phoneNumber='+ phoneNumber;
// send to database
$.ajax({
type: "POST",
url: "addphone.php",
data: dataAddPhone,
cache: true,
//if success
success: function(response){
//display message
$(".displayMessage").html(response);
//and reset form
$(".addPhoneForm").trigger("reset");
}
});
return false;
});
});
I have two divs.
First div
Has inputs like checkbox and select.
<div>Events Selection</div>
Events <input type="checkbox" id="Option-1" checked="true">
Leaves <input type="checkbox" id="Option-2" checked="true">
Meetings <input type="checkbox" id="Option-3" checked="true">
Travels <input type="checkbox" id="Option-4" checked="true">
<div>Station Selection</div>
<select id="Filters1">
<option value="0">All Stations</option>
<option value="1">Main Station</option>
<option value="2">Sub Station</option>
<option value="3">Sub Station Main Office</option>
</select>
Second div
Has a SQL statement $sql = "SELECT * FROM events"; which i want to echo all those checked and selected options from First div.
So, my question is how to dynamically change the SQL statement when the selections or checkbox changed in First div.
Like: When the page loads, it should be like this:
$sql = Select * From events Where (every checkboxes are
checked and `All Stations` are selected.)
and when a user wants to filter the result from First div then the $sql statement should be changed to what the user selected and checked.
Like: I want to check the Events and Meetings checkbox with Main Station selection, so now i want that the $sql statement should be change to my selection in the Second div.
At first use parameterized query's, don't construct them dynamically. Examples and explanation on MSDN.
Write stored procedure that will receive value of selected option and will bring you data you need. F.e.:
CREATE PROCEDURE dbo.getevents
#value int
AS
SELECT *
FROM events
WHERE somecolumn = #value
It is simplified version, I guess you need some if statement like IF #value = 0...SELECT this ... IF #value = 1
In that case you can use:
$sql = "EXEC dbo.getevents ?";
$stmt = sqlsrv_query($conn, $sql, array($value));
And then fetch results and show it on your page.
EDIT#1
Using XAMP and SQL Server 2014
Disclaimer: I post this code only for demonstration purpose. Parameters are passed as a string, no styling, maybe some mistakes.
I have an installed XAMP. Downloaded sqlsrv libraries, enable them in php.ini.
I got local SQL Server with database Test. SQL server has an instance named sqldev. My computer name is workshop. So, instead of SERVER\INSTANCE should be workshop\sqldev. Instead of DATABASE - Test. That is what I wrote to connect.
At first I create table like this:
CREATE TABLE dummy (
id int identity(1,1),
[Desc] nvarchar(max),
[Type] nvarchar(100)
)
INSERT INTO dummy VALUES
('Do something already','Events'),
('Congrats!','Events'),
('Meet up at six PM','Meetings'),
('To Amsterdam','Travels'),
('goodbye!','Leaves')
Table contains some dummy-data to play with.
The next step:
Download jQuery from https://jquery.com/download/ (I used jquery-3.1.1.js)
index.php
<html>
<head>
<script src="jquery-3.1.1.js"></script>
<style>
table {
width:20%
}
table, td, th {
border-collapse: collapse;
border: 1px solid gray;
}
</style>
</head>
<body>
<div>Events Selection</div>
Events <input type="checkbox" id="option" class="options" name="options[]" value="Events">
Leaves <input type="checkbox" id="option" class="options" name="options[]" value="Leaves">
Meetings <input type="checkbox" id="option" class="options" name="options[]" value="Meetings">
Travels <input type="checkbox" id="option" class="options" name="options[]" value="Travels">
<div id="response"></div>
<script>
$('input:checkbox').click(function() {
$.ajax({
url: "sql_page.php",
type: "post",
data: $('.options:checked').serialize(),
success: function(data) {
$('#response').html(data);
}
});
});
</script>
</body>
</html>
sql_page.php
<?php
header('Content-Type: text/html; charset=utf-8');
$serverName = "SERVER\INSTANCE";
$connectionInfo = array("Database"=>"DATABASE");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if(isset($_POST['options'])) {
if( $conn === false ) {
echo "Unable to connect.</br>";
die( print_r( sqlsrv_errors(), true));
}
$values = $_POST['options'];
$valuelist = "'" . implode("', '", $values) . "'";
$tsql = "SELECT * FROM dummy WHERE [Type] IN (".$valuelist.");";
$stmt = sqlsrv_query($conn, $tsql);
if( $stmt === false ) {
echo "Error in executing query.</br>";
die( print_r( sqlsrv_errors(), true));
}
echo "<table>";
while ($obj = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC)) {
echo "<tr>
<td>".$obj[0]."</td>
<td>".$obj[1]."</td>
<td>".$obj[2]."</td>
</tr>\n";
}
echo "</table>";
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn );
}
?>
Then I go on index.php in my browser:
If you are using MySQL you need another libraries and commands to use, but they are similar to what I wrote. The main idea is to connect to the database and run some query with parameters, it is a sql_page.php idea.
The index.php part sends Ajax request to sql_page.php when checkboxes are clicked. And then show the data from this page (that was got from SQL Server) in div with id=response.
EDIT#2
Using EasyPHP Devserver 16.1.1 dowloaded from here
I installed EasyPHP in default folder, start it, went to http://127.0.0.1:1111, started Apache + PHP on port 8888, started MySQL.
I create a DB named air-hr, table named events in it. The script and structure of table below:
CREATE TABLE `events` (
`eventid` int(11) NOT NULL,
`eventname` varchar(100) NOT NULL,
`eventcategory` varchar(100) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO `events` (`eventid`, `eventname`, `eventcategory`) VALUES
(1, 'Go now!', 'Leaves'),
(2, 'Meet some new people', 'Meetings'),
(3, 'Travel to Amsterdam', 'Travels'),
(4, 'PARTY HARD!', 'Events');
Also I create user test that can connect to DB and select from table.
I have created 2 files in C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www project folder (their description is below) and copy jquery-3.1.1.js.
index.php like above and
sql_page.php
<?php
header('Content-Type: text/html; charset=utf-8');
if(isset($_POST['options'])) {
$values = $_POST['options'];
$valuelist = "'" . implode("', '", $values) . "'";
$query = "SELECT * FROM events WHERE eventcategory IN (".$valuelist.");";
$link = mysqli_connect("localhost", "test", "testpass", "air-hr");
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
echo "<table>";
if ($result = mysqli_query($link, $query)) {
while ($row = mysqli_fetch_row($result)) {
echo "<tr>
<td>".$row[0]."</td>
<td>".$row[1]."</td>
<td>".$row[2]."</td>
</tr>\n";
}
mysqli_free_result($result);
}
echo "</table>";
mysqli_close($link);
}
?>
And results here:
Hope this helps you!
here you code
first named your inputs and select as follow:
<form action="sql_page.php" method="post">
<div>Events Selection</div>
Events <input type="checkbox" id="Option-1" name="Option-1" checked="true">
Leaves <input type="checkbox" id="Option-2" name="Option-2" checked="true">
Meetings <input type="checkbox" id="Option-3" name="Option-3" checked="true">
Travels <input type="checkbox" id="Option-4" name="Option-4" checked="true">
<div>Station Selection</div>
<select id="Filters1" name="Filters1">
<option value="0">All Stations</option>
<option value="1">Main Station</option>
<option value="2">Sub Station</option>
<option value="3">Sub Station Main Office</option>
</select>
<input type="submit" id="submit">
</form>
and in your sql_page.php here php code
if (isset($_POST)) {
foreach ($_POST as $col => $value) {
$whare .= "$col = '$value' AND ";
}
$whare = rtrim($whare,'AND ');
$sql = "Select * From events Where $whare";
}
I have a drop down if the value selected in drop down its shows the data in html table regarding the value selected in dropdown, i have search box now search is working fine it displays result without refreshing the page ,problem is now its showing the drop down html table and searched value result on the same page ,but i want to display the searched result on the same html table,see my code below,can anyone guide me to do this thanks.
<html>
<select name="client" id="client" style="margin:-8px 0 0 1px;background-color:#E8E8E8;width:104px;position: absolute;">
<option value="">Select Client</option>
<?php
i am connection to mysql
$sql=mysql_query("xxxxxxxxxx");
$clientid=$_GET['clientid'];
while($row=mysql_fetch_assoc($sql))
{
if(strlen($_GET['clientid'])>0 && $_GET['clientid']==$row['clientid'])
{
print' <option id="client" name="client" value="'.$row['clientid'].'">'.$row['clientid'].' </option>';
}
else{
print' <option id="client" name="client" value="'.$row['clientid'].'">'.$row['clientid'].' </option>';
}
}
?>
</select>
<form id="lets_search" action="" style="width:0px;margin:-27px 0 0;text-align:left;">
<input type="text" name="region" id="region">
<input type="text" name="country" id="country">
<input type="submit" value="search" name="search" id="search">
</form>
<div id="content"></div>
<table id="CPH_GridView1" >
<thead class="fixedHeader">
<tr>
<th style=" width:103px">Region </th>
<th style=" width:102px" >Country </th>
<tbody id="fbody" class="fbody" style="width:1660px" >
<div id="content">
<?php
$client_id = $_POST['title'];
if($client_id!=""){
$sql_selectsupplier = "xxxxxxxxxxx";
echo ' <td style="width:103px" class=" '.$rows["net_id"].'">'.$rows["clientid"].'</td>
<td style="width:102px" id="CPH_GridView1_clientid" class=" '.$rows["net_id"].'">'.$rows["region"].'</td>';
</div>
</tbody>
</table>
</html>
//javascript on the same page
<script type="text/javascript">
$(function() {
$("#lets_search").bind('submit',function() {
var valueregion = $('#region').val();
var valuecountry = $('#country').val();
$.post('clientnetworkpricelist/testdb_query.php',{valueregion:valueregion,valuecountry:valuecountry}, function(data){
$("#content").html(data);
});
return false;
});
});
</script>
testdb_query.php
<?php
$dbHost = 'localhost'; // usually localhost
$dbUsername = 'xxxxxx';
$dbPassword = 'xxxxxxxxxxxx';
$dbDatabase = 'xxxxxxxxxxxxxx';
$db = mysql_connect($dbHost, $dbUsername, $dbPassword) or die ("Unable to connect to Database Server.");
mysql_select_db ($dbDatabase, $db) or die ("Could not select database.");
$region=$_POST['valueregion'];
$country=$_POST['valuecountry'];
$clientid=$_POST['clientid'];
if (strlen($region) > 0 && $region!="" ){
$sql_search.= " AND s.region = '".$region."' ";
}
if (strlen($country) > 0 && $country!="" ){
$sql_search.= " AND s.country = '".$country."' ";
}
$query = mysql_query("SELECT * FROM supplierprice s,$clientid c WHERE s.supp_price_id = c.net_id $sql_search");
echo '<table>';
while ($data = mysql_fetch_array($query)) {
echo '
<tr>
<td style="font-size:18px;">'.$data["region"].'</td>
<td style="font-size:18px;">'.$data["country"].'</td>
</tr>';
}
echo '</table>';
?>
for best practice separate your php code from html - get all the data from the db in an array before rendering the html, and afetr that just use foreach in the html to parse each row.
put the DB login and connection in a differnet file and inlcude it with require_once() at top of the page
display errors for better understandig of your script
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
comment "i am connection to mysql" this line since it will bring an error in this format
After connecting to the DB initialize
$sql_search = ""; // otehrwise it will bring a notice when calling "$sql_search.="
and check the http_request so that it won't bring any errors when first accessing the page without the $_POST data
if ( $_SERVER['REQUEST_METHOD'] === 'POST')
{
//code for displaying the new table with the post data
}
Ok, I see two issues with your HTML code. One is that you are using two html elements with same ID ("content"), which is not the purpose of ID. Second, placing div inside the tbody is not valid HTML.
From your explanation I got that you are trying to show the result of both the actions in a single table.
So, remove first div
<div id="content"></div>
from code and update code inside $.post to something like this
$("#CPH_GridView1").append(data);
Also, remove the div inside tbody as well.