How to store the input value to php variable - javascript

<input type="text" id="transaction_id_input" name="transaction_name">
Above is the value that I want to store in PHP variables so I can compare it in the MySQL data to display specific data. I try storing the input value also to a javascript document.getElementByID("sampleID").value then store it in a variable but it didn't also work, hoping you will help me solve this problem.
<form method="GET" id="reg" name="valid" action="<?php echo htmlspecialchars(
$_SERVER["PHP_SELF"]
); ?>">
<input type="text" id="transaction_id_input" name="transaction_name">
<div class="wrapper" >
<div class="search-input">
<a href="" target="_blank" hidden></a>
<input type="text" id="searchmodal" placeholder="Type to search..">
<div class="icon"><i class="fas fa-search"></i></div>
</div>
</div>
<br><br>
<div class="card-header" id="cardheader2">
List of Medicine Transaction
</div><br><br>
<div class="enrollbutton2">
<a class="nav-link" id="transactioninfo_to_addtransan_class" data-toggle="modal" data-target="#myModal_transaction">Add Transaction
<span>
<lord-icon
src="https://cdn.lordicon.com/mecwbjnp.json"
trigger="loop"
colors="primary:#ffffff,secondary:#ffffff"
stroke="70"
style="width:30px;height:30px">
</lord-icon>
</span>
</a>
</div>
<div class="tableholdermodal" id="transactiontable">
<br><br><br><br>
<table>
<thead>
<tr>
<th scope="col">Transaction No.</th>
<th scope="col">Medicine Code</th>
<th scope="col">Supply</th>
<th scope="col">Lot No.</th>
<th scope="col">Expiration Date</th>
<th scope="col">Inputed Date</th>
</tr>
</thead>
<tbody id="myModalTable">
<?php
include "pdo_connection2.php";
$stm3 = $conn->query(
"SELECT * FROM tbl_transaction WHERE transaction_medicinecode = '' "
);
$rows = $stm3->fetchAll(PDO::FETCH_ASSOC);
if (count($rows) > 0) {
foreach ($rows as $row) { ?>
<tr>
<td data-label='Transaction ID' value="<?php echo $row[
"transaction_id"
]; ?>"><?php echo $row["transaction_id"]; ?></td>
<td data-label='Medicine Code' value="<?php echo $row[
"transaction_medicinecode"
]; ?>"><?php echo $row["transaction_medicinecode"]; ?></td>
<td data-label='Supply' value="<?php echo $row[
"transaction_supply"
]; ?>"><?php echo $row["transaction_supply"]; ?></td>
<td data-label='Lot No.' value="<?php echo $row[
"transaction_lotnum"
]; ?>"><?php echo $row["transaction_lotnum"]; ?></td>
<td data-label='Expiration Date' value="<?php echo $row[
"transaction_expdate"
]; ?>"><?php echo $row["transaction_expdate"]; ?></td>
<td data-label='Date Registered' value="<?php echo $row[
"transaction_date"
]; ?>"><?php echo $row["transaction_date"]; ?></td>
<td data-label='Action'>
<button type="button" class="transaction_update_class" name="transaction_update_name" data-toggle="modal" data-target="#myModalupdate_transactopn" value="<?php echo $row[
"transaction_id"
]; ?>">
<lord-icon
src="https://cdn.lordicon.com/wloilxuq.json"
trigger="loop"
colors="primary:#fb0054,secondary:#f55b2a "
stroke="70"
style="width:55px;height:55px">
</lord-icon>
</button>
<button type="button" class="transaction_delete_class" name="transaction_delete_name" data-toggle="modal" data-target="#myModaldelete_transaction" value="<?php echo $row[
"transaction_id"
]; ?>">
<lord-icon
src="https://cdn.lordicon.com/gsqxdxog.json"
trigger="loop"
colors="primary:#fb0054,secondary:#f55b2a "
stroke="70"
style="width:55px;height:55px">
</lord-icon>
</button>
</td>
</tr>
<?php }
} else {
?>
<tr><td><h4 id="h4nodatafound">------ NO DATA FOUND ------</h4></td></tr>
<?php
}
?>
</tbody>
</table>
</div>
</form>

Related

Pass PHP variable with button to popup via javascript?

I have a table created dynamically with PHP to display requests. In each row of my table there is a button to open a popup. The ID of each request should be transferred to this popup in order to read out all data.
How can I make it so that in a dynamic table (all button names are the same) each button is differentiated, or recognized which button I pressed? And how can I pass the variable from PHP to the popup via javascript?
I would appreciate any help, I've been trying for days now, but I'm not getting any results.
Here's the table view
Popup window
<table id="meineTabelle" data-role="table" class="content"
data-mode="columntoggle" data-column-btn-text="Spalten">
<thead>
<div class="tablehead">
<tr>
<th class="thblackborder" data-priority=""></th>
<th class="thblackborder" data-priority="">1.Projektant</th>
<th class="thblackborder" data-priority=""></th>
<th class="thblackborder" data-priority="">2.Projektant</th>
<th class="thblackborder" data-priority=""></th>
<th class="thblackborder" data-priority="">3.Projektant</th>
<th class="thblackborder" data-priority=""></th>
<th class="thblackborder" data-priority="">4.Projektant</th>
<th class="thblackborder" data-priority=""></th>
<tr>
<th class="">ID</th>
<th class="">Vorname</th>
<th class="">Nachname</th>
<th class="">Vorname</th>
<th class="">Nachname</th>
<th class="">Vorname</th>
<th class="">Nachname</th>
<th class="">Vorname</th>
<th class="">Nachname</th>
<th class="">Titel</th>
<th class="">Standort</th>
<th class="">Klasse</th>
<th class="">Beginn</th>
<th class="">Abgabe</th>
<th class="">Beschreibung</th>
<th class="">Status</th>
<th class="">Erstellt</th>
</tr>
</tr>
</div>
</thead>
<tbody>
<?php
foreach ($Ausgabe as $row) {
?>
<form>
<tr onclick="dialogOeffnen('loslegen-dialog')">
<td>
<?php echo $row["ID"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Vorname"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Nachname"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Vorname2"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Nachname2"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Vorname3"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Nachname3"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Vorname4"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Nachname4"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Titel"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Standort"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Klasse"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Beginn"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Abgabe"] . "<br>"; ?>
</td>
<td>
<center>Link</center>
</td>
<td>
<?php echo $row["Genehmigt"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Erstellt"] . "<br>"; ?>
</td>
<td>
<input type="button" value="" onclick="">
</td>
</tr>
</form>
<?php
}
?>
</tbody>
</table>
Popup HTML
<div id="body-overlay"></div>
<div class="dialog" id="loslegen-dialog">
<a href="#" role="button" class="dialog-schließen-button" onclick="dialogSchliessen('loslegen-dialog')">
<i class="fas fa-times"></i>
</a>
<div class="textarea">
<h1><?php echo $row['ID'] ?></h1>
<textarea placeholder="Platz für Bemerkungen" name="Bemerkungen" id="" cols="30" rows="10"></textarea>
</div>
<form classaction="">
<div class="txt_field">
<input type="text" name="email" value="<?= $fetch_profile['email'];?>" required>
<span></span>
<label>E-Mail</label>
</div>
<div class="txt_field">
<input type="text" name="password" required>
<span></span>
<label>Passwort</label>
</div>
<input type="submit" value="Bestätigen" name="submit">
<div class="signup_link">
</form>
</div>
<script src="dialoge.js">
</script>
<script>
</script>
</body>
</html>
</body>
</html>
dialoge.js
function dialogOeffnen(dialogId) {
document.getElementById(dialogId).classList.add("sichtbar");
document.getElementById("body-overlay").classList.add("sichtbar");
}
function dialogSchliessen(dialogId) {
document.getElementById(dialogId).classList.remove("sichtbar");
document.getElementById("body-overlay").classList.remove("sichtbar");
}
If I echo out $row["ID"] for sure it shows me the last ID in my table
First, let's clean up your HTML a bit. Tables have predetermined structures. That means that a only some elements can be used as a parent or child. For example, you can't nest a <tr> inside a another <tr>. Learn about the basics of tables.
<table id="meineTabelle" data-role="table" class="content" data-mode="columntoggle" data-column-btn-text="Spalten">
<thead>
<tr>
<th>ID</th>
<th>Vorname</th>
<th>Nachname</th>
<th>Vorname</th>
<th>Nachname</th>
<th>Vorname</th>
<th>Nachname</th>
<th>Vorname</th>
<th>Nachname</th>
<th>Titel</th>
<th>Standort</th>
<th>Klasse</th>
<th>Beginn</th>
<th>Abgabe</th>
<th>Beschreibung</th>
<th>Status</th>
<th>Erstellt</th>
</tr>
</thead>
<tbody>
<?php foreach ($Ausgabe as $row) : ?>
<tr>
<td><?= $row["ID"] ?></td>
<td><?= $row["Vorname"] ?></td>
<td><?= $row["Nachname"] ?></td>
<td><?= $row["Vorname2"] ?></td>
<td><?= $row["Nachname2"] ?></td>
<td><?= $row["Vorname3"] ?></td>
<td><?= $row["Nachname3"] ?></td>
<td><?= $row["Vorname4"] ?></td>
<td><?= $row["Nachname4"] ?></td>
<td><?= $row["Titel"] ?></td>
<td><?= $row["Standort"] ?></td>
<td><?= $row["Klasse"] ?></td>
<td><?= $row["Beginn"] ?></td>
<td><?= $row["Abgabe"] ?></td>
<td>Link</td>
<td><?= $row["Genehmigt"] ?></td>
<td><?= $row["Erstellt"] ?></td>
<td>
<button class="dialog-open" type="button" value="<?= $row["ID"] ?>">Button</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
I've changed your button to a <button> element because it's a bit more flexible to use. Output the ID of the row in the value attribute. Give the button a class value to identify it with. We'll need this for JS.
Select the table in JavaScript. Listen for click events that happen within the table. The code below checks if the clicked element (event.target) is a button with the class we gave it. If it is, then we'll read the value from button and pass it to the open modal function.
const table = document.querySelector('#meinTabelle');
table.addEventListener('click', event => {
if (event.target.matches('.dialog-open') {
const dialogId = event.target.value;
dialogOeffnen(dialogId);
}
});
function dialogOeffnen(dialogId) {
document.getElementById(dialogId).classList.add("sichtbar");
document.getElementById("body-overlay").classList.add("sichtbar");
}

Page redirect After Update data with custom code in wordpress

I have put a WordPress code to change the profile. The data is being updated, but after updating it is not redirected to the main page. Now I have to redirect it to another page if it gets redirected, then data not update. How could I do that?
<form method="post" id="adduser" action="<?php the_permalink(); ?>" class="profile-field">
<table class="table table-bordered">
<tbody>
<!--tr>
<td>Name</td>
<td><?php echo $user_details['first_name'][0]; ?></td>
</tr>
<tr>
<td>Email</td>
<td><?php echo wp_get_current_user()->user_email;?></td>
</tr-->
<p class="form-username">
<label for="first-name"><?php _e('First Name', 'profile'); ?></label>
<input class="text-input" name="first-name" type="text" id="first-name"
value="<?php the_author_meta( 'first_name', $current_user->ID ); ?>" />
</p>
<p class="form-username">
<label for="last-name"><?php _e('User mail', 'profile'); ?></label>
<input class="text-input" name="last-name" type="text" id="last-name"
value="<?php the_author_meta( 'user_email', $current_user->ID ); ?>" />
</p>
<!--tr>
<td>Company Code</td>
<td><?php echo $user_details['companycode'][0]; ?></td>
</tr>
<tr>
<td>Industry</td>
<td><?php echo $user_details['industury'][0]; ?></td>
</tr>
<tr>
<td>Job title</td>
<td><?php echo $user_details['jobtitle'][0]; ?></td>
</tr>
<tr>
<td>Experience</td>
<td><?php echo $user_details['experience'][0]; ?> Years</td>
</tr>
</tbody>
</table-->
<?php do_action('edit_user_profile',$current_user); ?>
<p class="form-submit">
<?php echo $referer; ?>
<div>
<button name="updateuser" type="submit" id="updateuser" class="submit button"
value="<?php _e('Update', 'profile'); ?>">update</button>
<?php //wp_nonce_field( 'update-user' ) ?>
<input name="action" type="hidden" id="action" value="update-user" />
</p>
<!--a class="profileinfo-edit" id ="edit" href="<?php echo site_url();?>/my-profile">Update Profile</a-->
</form>
<?php endif; ?>
See: https://codex.wordpress.org/Action_Reference/profile_update
add_action( 'profile_update', 'my_profile_update', 10, 2 );
function my_profile_update( $user_id, $old_user_data ) {
// Redirect
$redirect_url = '/your-redirect/permalink';
wp_redirect( $redirect_url );
exit();
}

submit product with session with add to cart

I have asked this question before. But it is updated with ajax and add to cart.
I have a form, which have some input fields and also have some check box fields. If any one fill fields and select some checkbox and then submit. Then some data according submission shows on another div.
Now If same person again fill that fields after first submission and select checkbox and submit. Then some data according submission shows on div. But it replace old submission content. I need all submission content, on div including all old submission content.
My code is:
<form class="reservation-form mb-0" action="" method="post" novalidate autocomplete="off">
<input name="name1" class="form-control required " type="text" placeholder="Enter Name" aria-required="true" required>
<input name="age" class="form-control required " type="number" placeholder="Enter Age" aria-required="true" required>
<select required id="selectarea" class="form-control" name="selectgender">
<option>Select Gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
<?php
$query1=mysql_query("select * from lab_location_package_rel where city_id='$selectcity1' AND area_id='$selectarea1' AND lab_id='$selectlab1'") or die (mysql_error());
while($value = mysql_fetch_array($query1)) {
$mrp=$value['mrp'];
$opp=$value['offer_price_perc'];
$package_id=$value['package_id'];
$per=$mrp*$opp/100;
$total=$mrp-$per;
$query2=mysql_query("select * from package_master where id='$package_id'") or die (mysql_error());
$value2 = mysql_fetch_array($query2);
?>
<li class="list-group-item">
<div class="checkbox">
<input type="checkbox" id="checkbox" name="namec[]" class="quantity<?php echo $value["id"]; ?>" value="<?php echo $value["id"]; ?>" />
<label for="checkbox">
<b>Package Name:</b> <?php $package_title1=$value2['package_title']; echo $package_title1;?> <br>
<b>MRP:</b> <strike><?php $mrp1=$value['mrp']; echo $mrp1; ?> </strike><br>
<b>Offer Price:</b> <?php $total1=$total; echo $total1; ?>
</label>
</div>
</li>
<?php }
?>
<input type="button" class="pull-right btn btn-warning" value="Submit" onclick="add_cart('<?php echo $value["id"]; ?>')">
</form>
<div class="cart_data">
</div>
My AJAX is:
<script>
function add_cart(p_id=""){
var quantity = $(".quantity"+p_id).val();
$.ajax({
type:"post",
url:"ajax_cart.php",
data:{action:'add',p_id:p_id,quantity:quantity},
success:function(result){
$('.cart_data').html(result);
}
});
}
function remove_cart(p_id){
//alert(p_id);
$.ajax({
type:"post",
url:"ajax_cart.php",
data:{action:'delete',p_id:p_id},
success:function(result){
$('.cart_data').html(result);
}
});
}
function empty_cart(){
$.ajax({
type:"post",
url:"ajax_cart.php",
data:{action:'empty'},
success:function(result){
$('.cart_data').html(result);
}
});
}
</script>
My ajax_cart.php is:
<?php
include"connection.php";
$action = $_REQUEST['action'];
#$p_id = trim($_REQUEST['p_id']);
//$_SESSION['product_cart'] = array();
if($action == 'add'){
#$quantity = $_REQUEST['quantity'];
if(!empty($p_id)){
$query1=mysql_query("select * from lab_location_package_rel where id='$p_id'") or die (mysql_error());
while($product_data = mysql_fetch_assoc($query1)) {
$mrp=$product_data['mrp'];
$opp=$product_data['offer_price_perc'];
$package_id=$product_data['package_id'];
$per=$mrp*$opp/100;
$total=$mrp-$per;
$query2=mysql_query("select * from package_master where id='$package_id'") or die (mysql_error());
$value2 = mysql_fetch_array($query2);
}
$product = array("p_id"=>$product_data['id'],"title"=>$value2['package_title'],"price"=>$product_data['mrp']*$quantity,"image"=>$product_data['offer_price_perc']);
if(isset($_SESSION['product_cart']) && !empty($_SESSION['product_cart']))
{
if(!array_key_exists($product_data['id'],$_SESSION['product_cart']))
{
$_SESSION['product_cart'][$product_data['id']] = $product;
}
}
else{
$_SESSION['product_cart'][$product_data['id']] = $product;
}
}
}
if($action == "delete"){
unset($_SESSION['product_cart'][$p_id]);
}
if($action == "empty"){
session_destroy();
}
?>
<div class="cart_data">
<?php
if(isset($_SESSION['product_cart'])){
foreach($_SESSION['product_cart'] as $data){
?>
<h5>Patient Details</h5>
<table class="table table-bordered">
<tbody>
<tr>
<th>Name</th>
<th>Age</th>
<th>Sex</th>
<th></th>
</tr>
<tr>
<?php //if(isset($_POST["submit"])==true)
{
?>
<td><?php //echo $_POST['name1']; ?></td>
<td><?php //echo $_POST['age']; ?></td>
<td><?php //echo $_POST['selectgender']; ?></td>
<td>Update</td>
</tr>
</tbody></table>
<br><br>
<h5>Package Details</h5>
<table class="table table-bordered">
<tbody>
<tr>
<th>Package</th>
<th>MRP</th>
<th>Offer Price</th>
<th></th>
</tr>
<tr>
<td><?php echo $data['title']; ?></td>
<td><strike><?php echo $data['price']; ?></strike></td>
<td><?php echo $data['image']; ?></td>
<td>Delete</td>
</tr>
<?php
}
?>
</tr>
</tbody></table>
<?php } } ?>
</div>

incorrect run php by button click

I have php function which update all records in data table and need it run by click button in html.
My php function look like this:
<?php
try {
$sql = 'SELECT id_data, date_record, value1, value2, value3 FROM data ';
$s = $pdo->prepare($sql);
$s->execute();
} catch (PDOException $e) {
$error = 'Error with select data' . $e->getMessage();
include 'error.html.php';
exit();
}
while ($row = $s->fetch()) {
$dane[] = array(
'id_data' => $row['id_data'],
'date_record' => $row['date_record'],
'value1' => $row['value1'],
'value2' => $row['value2'],
'value3' => $row['value3']
);
}
if (isset($_GET['edytion'])) {
foreach ($data as $data2) {
try {
$sql = 'UPDATE data SET date_record = :date_record, value1 = :value1, value2 = :value2, value3 = :value3 WHERE id_data= :id_data';
$s = $pdo->prepare($sql);
$s->bindValue(':date_record', $_POST['date_record']);
$s->bindValue(':value1', $_POST['value1']);
$s->bindValue(':value2', $_POST['value2']);
$s->bindValue(':value3', $_POST['value3']);
$s->bindValue(':id_data', $_POST['id_data']);
$s->execute();
} catch (PDOException $e) {
$error = 'Edit data error ' . $e->getMessage();
include 'error.html.php';
exit();
}
}
Header("Location: theme3.php");
}
?>
And my form in html where i try run this look:
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>Date</th>
<th>Value 1</th>
<th>Value 2</th>
<th>Value 3</th>
</tr>
</thead>
<?php if (isset($data)): ?>
<?php foreach ($data as $data1): $a = 0 ?>
<form action="?edytion" method="post" id='ed'>
<tr class="bg-primary">
<input type="hidden" name="id_data" id="id_data" value="<?php echo $data1['id_data']; ?>">
<td><input type="date" name="date_record" id="date_record" value="<?php echo $data1['date_record']; ?>"> </td>
<td><input type="text" name="value1" id="value1" value="<?php echo $data1['value1']; ?>"> </td>
<td><input type="text" name="value2" id="value2" value="<?php echo $data1['value2']; ?>"> </td>
<td><input type="text" name="value3" id="value3" value="<?php echo $data1['value3']; ?>"> </td>
<!-- <input type="hidden" ondblclick="default" id="id_buttona" value="Edit"/> -->
</tr>
</form>
<?php $a++;
endforeach; ?>
<?php endif; ?>
</tbody>
</table>
<input type="submit" id="id_buttona" onclick="document.getElementById('ed').submit();" value="Edit"/>
</div>
Ultimately when i try update data it update only first record in table, rest of them is invariable.
Anybody know what is wrong and have idea how correct it? I will be grateful for help!
You create too many forms with the same id. Surround the table with the <form> and do foreach on <tr> only.
Something like this
<div class="table-responsive">
<form action="?edytion" method="post" id='ed'>
<table class="table table-bordered">
<thead>
<tr>
<th>Date</th>
<th>Value 1</th>
<th>Value 2</th>
<th>Value 3</th>
</tr>
</thead>
<?php if (isset($data)): ?>
<?php $a = 0; foreach ($data as $data1): ?>
<tr class="bg-primary">
<input type="hidden" name="id_data<?php echo $a; ?>" id="id_data" value="<?php echo $data1['id_data']; ?>" />
<td><input type="date" name="date_record<?php echo $a; ?>" value="<?php echo $data1['date_record']; ?>"> </td>
<td><input type="text" name="value1<?php echo $a; ?>" value="<?php echo $data1['value1']; ?>"> </td>
<td><input type="text" name="value2<?php echo $a; ?>" value="<?php echo $data1['value2']; ?>"> </td>
<td><input type="text" name="value3<?php echo $a; ?>" value="<?php echo $data1['value3']; ?>"> </td>
</tr>
<?php $a++;
endforeach; ?>
<?php endif; ?>
</tbody>
</table>
<input name="row_count" value="<?php echo isset($a) ? $a : 0; ?>" type="hidden"/>
</form>
<input type="submit" id="id_buttona" onclick="document.getElementById('ed').submit();" value="Edit"/>
</div>
The way you created each form for each row will not work well because: (1) all your forms have the same javascript id, when you do getElementById only the first form is affected, (2) when you submit that one form the page reloads and all the changes to other rows are lost.
One solution is to make only 1 form and have different name to all fields. Forms fields are sent by name and value so you need different names for all fields and you don't really need ids.
You can add row count somewhere in the form and then change php to something like this:
$row_count = $_POST['row_count'];
for($i = 0; i < $row_count; i++) {
try {
$sql = 'UPDATE data SET
date_record = :date_record,
value1 = :value1,
value2 = :value2,
value3 = :value3
WHERE id_data= :id_data';
$s = $pdo->prepare($sql);
$s->bindValue(':date_record', $_POST['date_record' . $i]);
$s->bindValue(':value1', $_POST['value1' . $i]);
$s->bindValue(':value2', $_POST['value2' . $i]);
$s->bindValue(':value3', $_POST['value3' . $i]);
$s->bindValue(':id_data', $_POST['id_data' . $i]);
$s->execute();
}
catch (PDOException $e) {
$error = 'Edit data error ' . $e->getMessage();
include 'error.html.php';
exit();
}
}
It is all html file
<!DOCTYPE HTML PUBLIC>
<html>
<head>
<title>Tematyka2</title>
<link rel="stylesheet" href="style.css" type="text/css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"/>
</head>
<body>
<div id="container">
<div id="heading"></div>
<table border="0" width="766" cellpadding="0" cellspacing="0" align="center">
<tr>
<td class="t1"><p>Example title</p></td><td class="t2"> <b class="linkW" style="padding-left: 60%">Logout</b></td>
</tr>
<tr>
<td class="top1"><div class="inscription">Your Page</div></td>
<td class="top2" valign="top"></td>
</tr>
</table>
<table align="center" cellpadding="0">
<tr>
<td valign="top">
<table cellpadding="0" cellspacing="0">
<tr><td class="topm">Main menu</td></tr>
<tr><td class="tlom">
:: Main page <br>
</td></tr>
<tr><td class="dolm"></td></tr
</table>
<table cellpadding="0" cellspacing="0">
<tr><td class="topm">Them</td></tr>
<tr><td class="tlom">
:: Them 1 <br>
:: <b>Them 2</b> <br>
:: Them 3 <br>
</td></tr>
<tr><td class="dolm"></td></tr
</table>
<table cellpadding="0" cellspacing="0">
<tr><td class="topm">Charts</td></tr>
<tr><td class="tlom">
:: Chart1 <br>
:: Chart2 <br>
</td></tr>
<tr><td class="dolm"></td></tr>
</table>
<br>
</td>
<td width="1"></td>
<td valign="top">
<table cellpadding="0" cellspacing="0">
<tr><td class="topn"></td></tr>
<tr><td class="tlon">
<div class="span7 center">
<h2>
EDYTION
</h2>
</div>
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>Date</th>
<th>Value 1</th>
<th>Value 2</th>
<th>Value 3</th>
</tr>
</thead>
<?php if(isset($data)): ?>
<?php foreach($data as $data1): $a=0?>
<form action="?edytion" method="post" id='ed'>
<tr class="bg-primary">
<input type="hidden" name="id_data" id="id_data" value="<?php echo $data1['id_data']; ?>">
<td><input type="date" name="date_record" id="date_record" value="<?php echo $data1['date_record']; ?>"> </td>
<td><input type="text" name="value1" id="value1" value="<?php echo $data1['value1']; ?>"> </td>
<td><input type="text" name="value2" id="value2" value="<?php echo $data1['value2']; ?>"> </td>
<td><input type="text" name="value3" id="value3" value="<?php echo $data1['value3']; ?>"> </td>
<!-- <input type="hidden" ondblclick="default" id="id_buttona" value="Edit"/> -->
</tr>
</form>
<?php $a++; endforeach; ?>
<?php endif; ?>
</tbody>
</table>
<input type="submit" id="id_buttona" onclick="document.getElementById('ed').submit();" value="Edit"/>
</div>
</td></tr>
<!-- <tr><td class="doln"></td></tr> -->
</table>
</td>
</tr>
</table>
<table align="center" cellpadding="0" cellspacing="0">
<tr>
<td class="foot1"> My page</td>
<td class="foot2"><img src="images/dol2.jpg" alt="anything"></td>
</tr>
</table>
And Php part:
<?php
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
include $_SERVER['DOCUMENT_ROOT'] . '/connection_to_database.php';
include $_SERVER['DOCUMENT_ROOT']. '/check_login.php'; try {
$sql = 'SELECT id_data, date_record, value1, value2, value3 FROM data ';
$s = $pdo->prepare($sql);
$s->execute();
} catch (PDOException $e) {
$error = 'Error with select data' . $e->getMessage();
include 'error.html.php';
exit();
}
while ($row = $s->fetch()) {
$dane[] = array(
'id_data' => $row['id_data'],
'date_record' => $row['date_record'],
'value1' => $row['value1'],
'value2' => $row['value2'],
'value3' => $row['value3']
);
}
if (isset($_GET['edytion'])) {
foreach ($data as $data2) {
try {
$sql = 'UPDATE data SET
date_record = :date_record,
value1 = :value1,
value2 = :value2,
value3 = :value3
WHERE id_data= :id_data';
$s = $pdo->prepare($sql);
$s->bindValue(':date_record', $_POST['date_record']);
$s->bindValue(':value1', $_POST['value1']);
$s->bindValue(':value2', $_POST['value2']);
$s->bindValue(':value3', $_POST['value3']);
$s->bindValue(':id_data', $_POST['id_data']);
$s->execute();
}
catch (PDOException $e) {
$error = 'Edit data error ' . $e->getMessage();
include 'error.html.php';
exit();
}
}
Header("Location: theme3.php");
}
?>
And that's all about update data. Php and html are in one file, I know it's look unprofessionally and i shoudln't do it in this way.

How to pass DATA to PopUp Div in PHP?

I want to the pass ID value to POPUP DIV and update into table with status , suggest_text area with ID.
if I pass like this href="#pop1?id=<?php echo $row['id']; ?> The POPUP div is Not opening. so I dont know how to pass,so some one tell me that how can I pass in PHP or else in Javascript
Thanks in advance
<div class="widget-content">
<table class="table table-bordered table-striped data-table">
<thead>
<tr>
<th>S.No</th>
<th>Employee Name</th>
<th>Reason</th>
<th>Category</th>
<th>From</th>
<th>To</th>
<th>No Of Days</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$result=mysql_query("select * from leave_request");
while($row=mysql_fetch_array($result))
{?>
<tr>
<td><?php echo $row['id'];?></td>
<td> <?php echo $row['emp_name'];?></td>
<td> <?php echo $row['reason'];?></td>
<td> <?php echo $row['category'];?></td>
<td><?php echo $row['from_date'];?></td>
<td><?php echo $row['to_date'];?></td>
<td><?php echo $row['no_of_days'];?></td>
<td>
Accept |
Reject |
Suggest </td>
<div id="pop1" class="pop-up">
<?php $suggest_id = $_GET['id']; ?>
<div class="popBox">
<div class="popScroll">
<form>
<textarea name="suggest" id="suggest" cols="60" rows="8" ></textarea>
<input type="text" name="id" value="<?php echo $suggest_id; ?>">
<input type="text" name="status" value="3">
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
</form>
<!-- popup content end here -->
</div>
<span>Back to links</span>
</div>
Back to links
</div>
</tr>
<?php }?>
</tbody>
</table>
</div>
As I see your popup div is in WHILE loop so you can get your id like this :-
Initialize a value say K = 1; and put this value to every popup
Suggest
Full Code :-
<?php
$result=mysql_query("select * from leave_request");
while($row=mysql_fetch_array($result))
{
$k =1;
?>
<tr>
<td><?php echo $row['id'];?></td>
<td> <?php echo $row['emp_name'];?></td>
<td> <?php echo $row['reason'];?></td>
<td> <?php echo $row['category'];?></td>
<td><?php echo $row['from_date'];?></td>
<td><?php echo $row['to_date'];?></td>
<td><?php echo $row['no_of_days'];?></td>
<td>
Accept |
Reject |
Suggest </td>
<div id="pop<?php echo $k; ?>" class="pop-up">
<div class="popBox">
<div class="popScroll">
<form>
<textarea name="suggest" id="suggest" cols="60" rows="8" ></textarea>
<input type="text" name="id" value="<?php echo $row['id']">
<input type="text" name="status" value="3">
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
</form>
<!-- popup content end here -->
</div>
<span>Back to links</span>
</div>
Back to links
</div>
</tr>
<?php
$k++;
}?>

Categories

Resources