Reputation: 756
I want to somehow check the name of HTML file which has a submit button which goes to 'updatecart.php', in this php file I wanted to do an IF statement such as:
updatecart.php - Pseudo code:
IF(calling HTML file == "book1.html"){
// INSERT BOOK1 DATA INTO DATABASE TABLE (SQL)
}
IF(calling HTML file == "book2.html"){
// INSERT BOOK2 DATA INTO DATABASE TABLE (SQL)
}
etc...
I basically have multiple HTML files which all have a form with action set to action = "updatecart.php"
and I want to insert different data into the same database table depending on which page the form was submitted.
So I need to find the name of the HTML page from which the form was submitted.
Upvotes: 1
Views: 364
Reputation: 891
I think it's better to use an input field hidden
with value that you want to check.
Eg:
book1.html
<form action="updatecart.php" method="post">
<input type="hidden" name="filename" value="book1" />
</form>
book2.html
<form action="updatecart.php" method="post">
<input type="hidden" name="filename" value="book2" />
</form>
And you can check it by,
<?php
$filename = $_POST['filename'];
if ($filename === 'book1') {
// INSERT BOOK1 DATA INTO DATABASE TABLE (SQL)
} else if ($filename === 'book2') {
// INSERT BOOK2 DATA INTO DATABASE TABLE (SQL)
}
?>
Upvotes: 2
Reputation: 191809
You can use $_SERVER['HTTP_REFERER']
, to get the requesting page, but this is not always completely dependable. A better way to go about this would be to put a hidden input unique to the particular page in that page's form and check that instead.
Upvotes: 4