John Davidson

How can i access an html variable using PHP

0 comments
Message:


 $name= $row['name'];
$price = $row['price'];
$img = $row['image'];
$id = $row['order_no'];

echo "<div class='col-md-4 d-flex justify-content-center'>
<div class='card cust-card-bg' style='width: 18rem'>
<img
src='foodGallery/$img'
class='card-img-top cust-card-img'

/>
<div class='card-body d-flex flex-column'>
<h5 class='card-title primary-text'>$name</h5>
<p class='card-text'>
Some quick example text to build on the card title and make up
the bulk of the cards content.
</p>
<div
class='d-flex justify-content-between align-items-center mt-auto'
>
<h4 class='primary-text m-0'>$price tk</h4>
<a href='order.php?' order_id = $id class='btn btn-danger' >Order Item</a>
</div>
</div>
</div>
</div>";

Here I am trying to to get the value of order_id. I tried using $_GET['order_id] but it says undefined array key



My Answer:
To access the HTML variable `order_id` in PHP, you need to make sure that it is passed as a query parameter in the URL. In your code snippet, you are trying to pass the `order_id` as an attribute in the anchor tag, but it is not correctly formatted as a query parameter.

You can modify the anchor tag to include the `order_id` as a query parameter like this:

php
echo "Order Item";


Then, in your `order.php` file, you can access the `order_id` using `$_GET['order_id']`:

php
$order_id = $_GET['order_id'];


Make sure to sanitize and validate the input before using it in your PHP code to prevent any security vulnerabilities.

Rate this post

3 of 5 based on 5927 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us