I am trying to pass data from one page to another in php file and I don’t know a way to make that work.
Can someone help me please!
That is my form page and i try to submit it to the second page
First page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="add.css">
</head>
<body>
<div class="flex_container">
<div class="product_add"><b>Product Add</b></div>
<button type="submit" name="submit" id="save_btn">Save</button>
</div>
<hr size="2" color="rgb(156,1,0)" width="95%" style="clear: both;">
<br>
<div>
<form action="main.php" method="post" id="product_form">
<div>
<label for="sku">SKU</label>
<input type="text" id="sku" name="fname">
</div>
<div>
<label for="name">Name</label>
<input type="text" id="name" name="fname">
</div>
<div>
<label for="number">Price ($)</label>
<input type="number" id="price" min="1" step="any" />
</div>
<div>
<label for="type">Type Switcher</label>
<select id="productType" onclick="display();">
<option value="null" selected disabled>Choose one...</option>
<option value="disc" id="DVD">DVD-disc</option>
<option value="book" id="Book">Book</option>
<option value="furniture" id="Furniture">Furniture</option>
</select>
<div id="a" style="display: none;">
<label for="size">Size (MB)</label>
<input id="size" type="number" />
<h4>Please provide Size in MB !</h4>
</div>
<div id="b" style="display: none;">
<label for="weight">Weight (KG)</label>
<input id="weight" type="number" />
<h4>Please provide Weight in KG !</h4>
</div>
<div id="c" style="display: none;">
<div>
<label for="height">Height (CM)</label>
<input id="height" type="number" />
</div>
<div>
<label for="width">Width (CM)</label>
<input id="width" type="number" />
</div>
<div>
<label for="length">Length (CM)</label>
<input id="length" type="number" />
</div>
<h4>Please provide Height, Width, and Length in CM !</h4>
</div>
</div>
</form>
</div>
<script src="add.js"></script>
</body>
</html>
And here is the page where i would like the form to be submitted
Second page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="main.css">
</head>
<body>
<div class="flex_container">
<div class="product_list"><b>Product List</b></div>
<a href="add-product.html"><button id="add_button">ADD</button></a>
<button id="delete_button">MASS DELETE</button>
</div>
<hr size="2" color="rgb(156,1,0)" width="95%" style="clear: both;">
<div>
</div>
<hr size="2" color="rgb(156,1,0)" width="95%" style="clear: both;">
</body>
</html>
I tried javascript also i saw that can be possible with php but I’m not sure.
2
Answers
I added the php but nothing is happening it is going to the next page but the page is blank
Maybe because i have to create a database
In the second page you have to use php to get the field values.
The form is using method="post" , so you can get the field values from the $_POST array.
If you want the
<button type="submit" ...>
to submit the form, the button has to be within the<form>
A basic example to get the value of the fname text field: