So hi guys. I have a problem regarding a variable passing. I can't explain it clearly but here's the code. I know it'll be clearer with this.
<tbody>
<tr>
<td><?php echo $row['nameSchool'] ?></td>
<td><?php echo $row['address'] ?></td>
<td><?php echo $row['honor'] ?></td>
<td><?php echo $row['year'] ?></td>
<td width = "5%"><div id='basic-modal-2'><img src="../img/edit.png" height="22" width="22"></div></td>
<td><img src="../img/Delete.png" height="22" width="22"></td>
</tr>
<?php
}
?>
</tbody>
//some codes here.
<!-- Update Employee -->
<div id="basic-modal-content-2">
<h3>Update Information</h3>
<p></p>
</br>
<form method="post" action="add3.php">
<table id = "box-table-c2" class = "basic-modal-content-2">
<thead></thead>
<tbody>
<tr>
<td><strong><?php echo $_GET['idnum']; ?></strong></td>
<td>:</td>
<td><input type="text" class="input-xlarge" name = "NS"></td>
</tr>
<tr>
<td><strong>Address</strong></td>
<td>:</td>
<td><input type="text" class="input-xlarge" name = "ad"></td>
</tr>
<tr>
<td><strong>Honors Received</strong></td>
<td>:</td>
<td><input type="text" class="input-xlarge" name = "HR"></td>
</tr>
<tr>
<td><strong>Year Graduated</strong></td>
<td>:</td>
<td><input type="text" class="input-xlarge" name = "YG"></td>
</tr>
<tr>
<td align= "left" width= "3"><button class="btn-primary" type="submit" style = "cursor: pointer";>Submit</button></td>
</tr>
</tbody>
</table>
</form>
</div>
They are both on the the same php file (educinfo.php)
My error is that i can't pass the value of the "EDIT" link to the simplemodal.
Thank You guys.
You can pass value in PHP using many ways. one way is passing value in Query String. That is you can pass value after file name with question mark. just like key value passing
phpfilename.php?key1=value1&key2=value2
You can pass any number of key and value. After that you can access in next page using key value.
In HTML Part:
<a href="filename.php?QueryString=valueOne" title = "Edit" class = "basic">
<img src="../img/edit.png" height="22" width="22">
</a>
In php you can get like this
$Idvalue = isset($_GET['QueryString']) ? $_GET['QueryString'] : "";
Please let me know if you have any issue for passing value like this
Related
I am trying to process form fields via POST method. I will post a long code for you to inspect, however the structure of the code is simply like this
<form> <table> <th> </th> <td> </td> </table> </form>
so it is a table inside a form. When the form is submitted, I am taken to the "cart.php" page which is expected, but that page shows the echo statement and shows the variables correctly for a split second, then shows the rest of the page but the variables in the echo statement become "undefined".
P.S: Please don't mark as duplicate with this question, thanks.
This is the first page index.php
<div class="table-responsive" id="order_table">
<form method="POST" action="cart.php" class="form-group">
<table class="table table-bordered">
<tr>
<th width="40%">Product Name</th>
<th width="10%">Quantity</th>
<th width="20%">Price</th>
<th width="15%">Sub Total</th>
<th width="5%">Action</th>
</tr>
<?php
if(!empty($_SESSION["shopping_cart"]))
{
$sub_total = 0;
foreach($_SESSION["shopping_cart"] as $keys => $values)
{
?>
<tr>
<td><?php echo $values["product_name"]; ?></td>
<td><input type="text" name="quantity[]" id="quantity<?php echo $values["product_id"]; ?>" value="<?php echo $values["product_quantity"]; ?>" data-product_id="<?php echo $values["product_id"]; ?>" class="form-control quantity" /></td>
<td align="right">$ <?php echo $values["product_price"]; ?></td>
<td align="right">$ <?php echo number_format($values["product_quantity"] * $values["product_price"], 2); ?></td>
<td><button name="delete" class="btn btn-danger btn-xs delete" id="<?php echo $values["product_id"]; ?>">Remove</button></td>
</tr>
<?php
$sub_total = $sub_total + ($values["product_quantity"] * $values["product_price"]);
$tax = $sub_total * 0.075;
$total = $sub_total + $tax;
}
?>
<tr>
<td colspan="3" align="right"><span style="font-size:1.3em;">Tax</span></td>
<td align="right">$ <?php echo number_format($tax,2); ?></td>
</tr>
<tr>
<td colspan="3" align="right"><span style="font-size:1.3em;">Total</span></td>
<td align="right">$ <?php echo number_format($total, 2); ?></td>
<td></td>
</tr>
<tr>
<td colspan="5" align="center">
<textarea name="comments" id="comment" class="form-control" placeholder="Please enter any special instructions for the order"></textarea> <br>
<input type="submit" name="place_order" id="place_order" class="btn btn-warning" value="Place Order" />
</td>
</tr>
<?php
}
?>
</table>
</form>
And this is the beginning of cart.php:
$comment = $_POST['comments'];
echo $comment. $_POST['place_order'];
print_r($_POST);
How I know that the variables do get passed is cause I noticed some result appearing for a split second so I took a video and paused it there and it had the expected POST array, before the page suddenly appears as expected but with
"Undefined index: comments "
and
"Undefined index: place_order"
and "Array()" at the top. cart.php does not have any commands that make it refresh. Thank you.
I have one php page in which I have changed font for input to devnagri. I need to display it in next php page and also need to insert those to mysql.
first page index.php contains this details......
<table width="535" height="54" border="1">
<tbody>
<tr>
<td height="23">नाम</td>
<td><input type="text" name="name" id="name" style="font-family: Preeti">
</td>
</tr>
<tr>
<td height="23">काम</td>
<td><input type="text" name="job" id="job" style="font-family: Preeti">
</td>
</tr>
</tbody>
</table>
my second page post.php contains
<table width="535" height="54" border="1">
<tbody>
<tr>
<td height="23">नाम</td>
<td><?php
echo $_POST['name'];
?></td>
</tr>
<tr>
<td height="23">काम</td>
<td><?php
echo $_POST['job'];
?></td>
</tr>
</tbody>
</table>
when I type कला in name and खेप in job input
it displays relative english letters on the 2nd page .....
where as I need to display as it displays in input.
I also need to insert those input to mysql and again need to display those mysql data to another page....
I am not getting the way to display and stuck at this point so insert and select query is yet to be done....
Need help to figure it out.
Thanx a lot Phil.
<table width="535" height="54" border="1">
<tbody>
<tr>
<td height="23">नाम</td>
<td style="font-family: Preeti"><?php
echo $_POST['name'];
?></td>
</tr>
<tr>
<td height="23">काम</td>
<td style="font-family: Preeti"><?php
echo $_POST['job'];
?></td>
</tr>
</tbody>
</table>
It has displayed preeti font...
Still INSERT and SELECT query is remaining.
On my website enter link description here I'm using checkbox buttons for updating data in a MySql table (pages are with login) and use this code in PHP that's working fine:
<?php
$sql="SELECT *,cast(DATE_FORMAT(datum,'%d-%m-%Y ') AS CHAR(32)) as datum FROM wedstrijden";
$result=mysqli_query($db,$sql);
$count=mysqli_num_rows($result);
?>
<table style="width: 100%;">
<tr>
<td><form name="frmactive" action="1fanionchange.php" method="post">
<tr>
<td colspan="6"><input name="activate" type="submit" id="activate" value="Open selected" />
</tr>
<tr>
<td> </td>
</tr><tr>
<td align="center"><!--<input type="checkbox" name="allbox" title="Select or Deselct ALL" style="background-color:#ccc;"/> --></td>
<td align="center"><strong>Id</strong></td>
<td align="center"><strong>Datum</strong></td>
<td align="center"><strong>Uur</strong></td>
<td align="center"><strong>Thuis</strong></td>
<td align="center"><strong>Uit</strong></td>
</tr>
<?php
while($rows=mysqli_fetch_array($result)){
?>
<tr>
<td align="center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td>
<td align="center"><? echo $rows['id']; ?></td>
<td align="center"><? echo $rows['datum']; ?></td>
<td align="center"><? echo $rows['uur']; ?></td>
<td align="center"><? echo zoeknaam($rows['thuisploeg']); ?></td>
<td align="center"><? echo zoeknaam($rows['uitploeg']); ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="6"><input name="activate" type="submit" id="activate" value="Open selected" />
</tr>
</form>
</td>
</tr>
</table>
But when I use the same code in WordPress (I'm trying to make the website in WordPress), it is not working and no records are displayed. When I try to find the number of rows using:
echo $count. "<br />";
I get the correct number of records in that table. But the records are not showed?
Any idea how to handle the problem? Thanks.
PS. I use the plugin phpexec in WordPress!
In WordPress it is suggested to use the WordPress builtin Queries. So that it can have maximum compatibility with the server too it is hosted.
Reference: https://codex.wordpress.org/Class_Reference/wpdb
global $wpdb;
And all the following functions will attach the database that is defined as global..
$wpdb->insert('wp_submitted_form', array(
'name' => 'Kumkum',
'email' => 'kumkum#gmail.com',
'phone' => '3456734567', // ... and so on
));
Like wise you can use it for Update / Select as per your wish and it is considered as the best one according to WordPress..
I've stucked a bit when it comes to a small piece of my PHP code. The role of this script is to display whole table from mysql plus adding to each row a hyperlink to delete such row.
<?php
$connection=mysql_connect('localhost','root','') or die(mysql_error());
error
mysql_select_db('localhost_db',$connection) or die(mysql_error());
$query=mysql_query("SELECT * FROM cms_contest") or die(mysql_error());
if(mysql_num_rows($query)>0):
?>
<table width="100%" border="0">
<tr style="font-weight:bold;">
<td align="center">Id</td>
<td align="center">First Name</td>
<td align="center">Last Name</td>
<td align="center">Email</td>
<td align="center">Phone</td>
<td align="center">Answer</td>
<td align="center">Remove</td>
</tr>
<?php
while($row=mysql_fetch_object($query)):?>
<tr>
<td align="center"><?php echo $row->ID; //row id ?></td>
<td align="center"><?php echo $row->name; // row first name ?></td>
<td align="center"><?php echo $row->surname; //row las tname ?></td>
<td align="center"><?php echo $row->email; //row created time ?></td>
<td align="center"><?php echo $row->phone_number; //row created time ?></td>
<td align="center"><?php echo $row->contest_answer; //row created time ?></td>
<td align="center">REMOVE</td>
</tr>
<?php endwhile;?>
</table>
<?php
else: ?>
<h3>No Results found.</h3>
<?php endif; ?>
It would be perfect if there appear a short javascript popup with question like: are you sure you want to remove this entry? OK / Cancel.
I have no clue how to do it.. thanks for any tips!
Simple/stupid method:
<td>nuke me</td>
But if a web spider or a browser link pre-fetch tool gets loose on this page, you'll be nuking ALL of your records.
Somewhat better:
<td>
<form method="post" action="deleteme.php">
<input type="hidden" name="id" value="<?php echo $row->ID ?>" />
<input type="submit" value="Nuke me" />
</form></td>
And then there's various options involving radio buttons/checkboxes, or JS to trap the click-on-the-link etc...
But, in the end, they ALL boil down to "you have to sent the ID of the row back to the server". How you go about that is up to you... just don't use the plain "click here" version.
Indeed there are several different ways to do this. One way I like is to wrap the entire table in a form that submits to the delete script, and use a button for each row with the row ID as its value.
<form method="post" action="delete.php">
<table width="100%" border="0">
<tr style="font-weight:bold;">
<td align="center">Id</td>
<td align="center">First Name</td>
<td align="center">Last Name</td>
<td align="center">Email</td>
<td align="center">Phone</td>
<td align="center">Answer</td>
<td align="center">Remove</td>
</tr>
<?php while($row=mysql_fetch_object($query)): ?>
<tr>
<td align="center"><?php echo $row->ID; //row id ?></td>
<td align="center"><?php echo $row->name; // row first name ?></td>
<td align="center"><?php echo $row->surname; //row las tname ?></td>
<td align="center"><?php echo $row->email; //row created time ?></td>
<td align="center"><?php echo $row->phone_number; //row created time ?></td>
<td align="center"><?php echo $row->contest_answer; //row created time ?></td>
<td align="center">
<button name="delete-id" type="submit" value="<?php echo $row->ID; ?>">
REMOVE
</button>
</td>
</tr>
<?php endwhile;?>
</table>
</form>
There are also many different ways to confirm the deletion. The simplest I know of on the client side is to add onclick="return confirm('Are you sure?');" to the delete button.
click event:
DELETE
<script type="text(javascript">
function confirmDelete(id){
if(confirm('sure u want to delete entry with id: ' + id + '?')){
window.location.href = "ursite.php?id="+id+"&delete=true";
}
}
</script>
PHP
if(isset($_GET['delete'])){
$stmt = "DELETE FROM cms_contest WHERE ID = ".$_GET['id'];
mysql_query($stmt);
}
it's the worst way to do it.
I recommend you to look at:
jQuery $.post()jQuery $.ajax()
I hope it will help you.
This question already has answers here:
why the appended row's data didn't displayed after being submitted?
(2 answers)
Closed 9 years ago.
This page got a button ADD to append the row.Once the appended row is filled,when submit,it will connect/link to another page ,then the filled information will display at that page.But the problem is how to display the filled information of appended row on 2nd page had been done in 1st page by using PHP.(Sorry for my poor English and hope for understand).
<table width="600px" id="project">
<tr>
<td>1</td>
<td><textarea name="pro_1" cols="100" rows="2"></textarea></td>
</tr>
<tr>
<td>2</td>
<td><textarea name="pro_2" cols="100" rows="2"></textarea></td>
</tr>
<tr>
<td>3</td>
<td><textarea name="pro_3" cols="100" rows="2"></textarea></td>
</tr>
</table>
<input id="addbtn" type="button" name="addbtn" value="ADD">
Jquery script(for append the row):
$(document).ready(function() {
$("#addbtn").click(function(){
var num=parseInt($("#project tr:last").text());
num+=1;
$("#project").append("<tr><td>"+num+"</td><td><textarea cols='100' rows='2'></textarea></td></tr>");
});
PHP source code(for 2nd page):
<table width="600px" id="pub">
<tr>
<td>1</td>
<td><?php echo $_post["pro_1"]; ?></td>
</tr>
<tr>
<td>2</td>
<td><?php echo $_post["pro_2"]; ?></td>
</tr>
<tr>
<td>3</td>
<td><?php echo $_post["pro_3"]; ?></td>
</tr>
</table>
<table width="600px" id="project">
<?php //to show the filled appended row but fail
$index = 1;
while(isset($_POST["pro_".$index])) {
?>
<tr>
<td><?php echo $index; ?></td>
<td><?php echo $_POST["pro_".$index]; ?></td>
</tr>
<?php
$index++;
} ?>
</table>
the output as below:
you forgot to add name attribute to append command
name='pro_'+num;
$("#project").append("<tr><td>"+num+"</td><td><textarea name="+name+" cols='100' rows='2'></textarea></td></tr>");