how can I pass this value which data is in database. I want to pass the value from another page by textbox. how can I do it?
here is my database
and I want to pass the Value on the textbox from another page how can I do that?
here is my code
include("topupcard.php";)
<td>
<?php echo htmlentities($row['value']);?>
</td>
<button class="btn btn-success mr-4">Generate QR Code</button>
and to pass the data to another page.
<input type="text" value="$row['value']" name="id">
right now, it is not working nothing is being passed.
also, i dont know if I'll use Session or not, help thanks.
so the output should be 200 or 1000 is displayed on the other page when i click the button.
Using #danblack's explanation you can
Option 1 (not a safe method if this involves transactions):
<a href="generatecode.php?value=<?php echo htmlentities($row['value']); ?>">
then on the other page
<input type="text" value="<?php echo $_GET['value']; ?>" name="id">
Option 2 :
session_start();
$_SESSION['value'] = $row['value'];
then on the other page
session_start();
$value = $_SESSION['value'];
<input type="text" value="<?php echo $value; ?>" name="id">
Related
I have a normal form in a PHP page, I send data to the php page from another for using POST. The PHP page runs some scripts to update data to SQL but on that page I have a second form that needs to be completed with data from the initial form prior to updating the SQL.
$recipient_nr = $_REQUEST['recipient_nr'];
Here I draw the info from the first form
Now I want to use this in a new form on the current PHP page how do I state this in the new form
<input type="text" name="recipient_nr" id="recipient_nr" value=".$recipient_nr.">
This is what I am attempting but it is not working I know I have too many "'" xxx"'" in the lines but not sure how to remidy this
Do you generate the new form in PHP? If so, where is the code where you do that?
If this is some kind of ...?> <input type="..."...> <?php ... page generation then you'll need to echo that $recipient_nr into the PHP-generated response:
...
?>
<input type="text"
name="recipient_nr"
id="recipient_nr"
value="<?php echo $recipient_nr; ?>">
<?php
...
Or, if you have short echos turned on,
...
?>
<input type="text"
name="recipient_nr"
id="recipient_nr"
value="<?= $recipient_nr ?>">
<?php
...
use this:
<input type="text" name="recipient_nr" id="recipient_nr" value="<?php echo $recipient_nr; ?>">
Something like this:
$recipient_nr = array_key_exists('recipient_nr', $_REQUEST)
? (string) $_REQUEST['recipient_nr']
: 'default value or empty string';
And output it:
<input type="text"
name="recipient_nr"
id="recipient_nr"
value="<?=$recipient_nr?>">
But if you want store this data for/between other pages you can use $_SESSION global array for save it.
This is my second code but the problem is I have 3 queries. So it only returns the last product_id when i Click update it always return product_id=3, but i want update the product_id=2
<form action="update_qty.php" method="POST">
<?php while($getorder = mysqli_fetch_array($order)){ ?>
<input type="hidden" value="<?=$getorder['price']?>" name="actual_price">
<input type="hidden" value="<?=$getorder['product_id']?>" name="product">
<input type="text" value="<?=$getorder['qty']?>" name="qty" size="1" style="text-align:center">
<input type="submit" value="update" name="update">
<?php } ?>
</form>
Your problem is that the PHP is server side and you need something client side to read the value of the text box. You would need a page refresh to pass the text field value to the server so it could write it to the url in the anchor tag. Which is what the form submit would do, but as it would have submitted the value already the anchor tag would be pointless
To do it without a page refresh use Javascript. It would be easy to do with jQuery. You could add an event that writes whatever is entered in the text box the the anchor tags href as it is typed.
I'll do something more like this.
One form per product.In your case when you submit the form the qty value will always be the las found.
<?php while($getorder = mysqli_fetch_array($order)){ ?>
<form action="update_qty.php" method="POST">
<input type="hidden" value="<?=$getorder['price']?>" name="actual_price">
<input type="hidden" value="<?=$getorder['product_id']?>" name="product">
<input type="text" value="<?=$getorder['qty']?>" name="qty" size="1" style="text-align:center">
<input type="submit" value="update" name="update">
</form>
<?php } ?>
You can add more information like this
update
You can not get all values as like that because input name overwrite in every loop iteration.
For multiple values you can try in two ways like:
<?php
while($getorder = mysqli_fetch_array($order)){
$newArr[] = $getorder['price']."~".$getorder['product_id']."~". $ getorder['qty'];
} //while end
?>
<input type="hidden" name="allinputs" value="<?=$newArr?>">
Input field outside the loop.
In php explode array value with ~ and get the all values.
Other solution is that
Your input field name must be change like:
<?php while($getorder = mysqli_fetch_array($order)){ ?>
<input type="hidden" value="<?=$getorder['price']?>" name="actual_price_<?=$getorder['product_id']?>">
<?php } ?>
Change field name in every iteration.
In current scenario either you need three different buttons or the best solution to use AJAX request .
update
On update_qty.php u can use like this
<?php echo $_GET['product_id'];?>
my page receives data which i retrieve with $_post. I display some data and at the bottom of page my button has to save data to mysql. I could submit form to next page, but how do i access the data that I have retrieved with post then? Lets say i have following code (in reality alot more variables ..):
<?php
$v= $_POST["something"];
echo $v;
echo "Is the following information correct? //this would be at the bottom of the page with the buttons
?>
<input type="button" value="submit data" name="addtosql">
You can do it in two methods:
1) You can save the POST variable in a hidden field.
<input type="hidden" name="somevalue" value="<?php if(isset($_POST["something"])) echo $_POST["something"];?>" >
The hidden value also will get passed to the action page on FORM submission. In that page you can access this value using
echo $_POST['somevalue'];
2) Use SESSION
You can store the value in SESSION and can access in any other page.
$v= $_POST["something"];
session_start();
$_SESSION['somevalue']=$v;
and in next page access SESSION variable using,
session_start();
if(isset($_SESSION['somevalue']))
echo $_SESSION['somevalue'];
Take a look. Below every thing should be on single php page
// first create a function
function getValue($key){
if(isset($_POST[$key]))
return $_POST[$key];
else
return "";
}
// process your form here
if(isset($_POST['first_name']){
// do your sql stuff here.
}
// now in html
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="first_name" value="<?php echo getValue("first_name"); ?>" />
<input type="submit" />
</form>
I've created a registration form that successfully passes its variables from the registration page (go-gold.php) to a summary/verfication page (go-gold-summary.php). The data appears correctly on the second page.
However, I want to able to use an image button to return back to the registration page, in case the user made an entry error. Going back, the original form should now be populated with the data that was first entered.
The problem is that I cannot re-send/return the data from the second page, back to the first. My text fields appear blank. I do NOT want to use Session variables.
The code is truncated from the entire page.
Registration Page (go-gold.php):
<?php
$customer_name = $_POST['customer_name'];
?>
<form action="go-gold-summary.php" method="post">
Name: <input type="text" name="customer_name" id="customer_name" value= "<?php echo $customer_name ?>" />
<input name="<?php echo $customer_name ?>" type="hidden" id="<?php echo $customer_name ?>">
</form>
Summary Page (go-gold-summary.php)
<?php
$customer_name = $_POST['customer_name'];
?>
<form action="go-gold.php" method="post">
Name: <?php echo $customer_name ?> <input type="hidden" id="<?php echo $customer_name ?>" name="<?php echo $customer_name ?>">
<INPUT TYPE="image" src="images/arrow_back.png" id="arrow" alt="Back to Registration"> (Button to go back to Registration Page)
</form>
Thanks!
go-gold-summary.php should be changed like this.
<?php
$customer_name = $_POST['customer_name'];
?>
<form action="go-gold.php" method="post">
Name: <?php echo $customer_name ?> <input type="hidden" value="<?php echo $customer_name ?>" name="customer_name">
<INPUT TYPE="submit" src="images/arrow_back.png" id="arrow" alt="Back to Registration"> (Button to go back to Registration Page)
</form>
notice how I've changed this line
<input type="hidden" id="<?php echo $customer_name ?>" name="<?php echo $customer_name ?>">
into this
<input type="hidden" value="<?php echo $customer_name ?>" name="customer_name">
$_POST is an associative array and as you submit the form it will be populated like this:
$_POST["index"] = value;
where "index" is the text field "name" and value is the text field value.
You've missed that one in your code. Just update it with my code and it will work
Why you would not want to use the php session? Please give any reason for not to use it. I am asking this way since my reputation does not allow me to comment questions or answers any other than my own. Plese do not -1 for this.
Another way could be using cookies to store the data temporarily, but that and posting the data back and forth in the post request is really insecure compared to session.
there are very few ways to maintain variables across pages. The alternative is to have separate form on the second page with hidden text fields containing the $_POST data, and the submit button calls the previous page. No way of getting around the "back button" on a browser though unfortunately.
I missed the bold text about the session variables - disregard if this does not apply:
one way to maintain variables across pages on the server side is to use $_SESSION
first include the following at the top of your PHP pages to keep a session active:
session_start();
once you submit the for and move to page 2, add the following:
$_SESSION['customer_name'] = $_POST['customer_name'];
As well, on the first page, you could change the form element as such:
<input type="text" name="customer_name" value="<?PHP if isset($_SESSION['customer_name'] || !empty($_SESSION['customer_name'])) { echo $_SESSION['customer_name']; } ?>">
this will keep the filled in data and display it when the user returns tot he page, and if they put in something different it will be updated when they hit page 2 again.
I need to get a value from a text box, but I'm not using a form, therefore I can't use $_POST or $_GET. Is there any method to get that value from the text box? Below is the code that I'm using
<input name="txtQty" type="text" id="txtQty" size="5" value="<?php echo $qty; ?>" onKeyUp="checkNumber(this);"> //here I'm the displaying the quantity, then the user can change it, and I need to get that value to pass it throught this link:
<input name="btnEdit" type="button" value="Edit" onClick="window.location.href='<?php echo $_SERVER['PHP_SELF'] . "?action=update&cid=$shoppingCartId&qty=$qty //here I need that new value from the textbox"; ?>';"
Thanks for your help
If you're doing this without a page refresh you need javascript. If you do have a page refresh, you need a form.
Without form or javascript controlled request - no you can't
Ajax must be used to Pass client data to sever if not wish to refresh the page. Check below code, which was written with simple changes.
<input name="txtQty" type="text" id="txtQty" size="5" value="<?php echo $qty; ?>">
<input name="btnEdit" type="button" value="Edit" id="btnEdit" onclick="redirectUser()" />
<script>
function redirectUser(){
var qty = document.getElementById('txtQty').value;
location.replace('<?php echo $_SERVER['PHP_SELF']; ?>action=update&cid=<?php echo $shoppingCartId; ?>&qty='+qty);
}
</script>
PHP only runs on the server, so the only way to get the values from your inputs would be to somehow pass them to the server.
You could do it in a number of ways, but the easiest would likely be to put your inputs into a form, and post the form to a PHP script.
You can use javascript:
document.getElementById("txtQty").value
Why are you saving text box box variable in php?
If you are passing value to text box in php, then you can echo php value over there.
<input name="btnEdit" type="button" value="Edit" onClick="window.location.href='<?php echo $_SERVER['PHP_SELF'] . "?action=update&cid=$shoppingCartId&qty="+<?php echo $qty; ?>';"
If not then you can use directly form item as value over there.
<input name="btnEdit" type="button" value="Edit" onClick="window.location.href='<?php echo $_SERVER['PHP_SELF'] . "?action=update&cid=$shoppingCartId&qty="+document.getElementById("txtQty").value';"