我试图通过数据从一个页面到另一个在php文件,我不知道一种方法来使工作。
有人能帮帮我吗!
这是我的表单页面,我尝试将其提交到第二页
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>
这里是我想提交表单的页面
第二页
<!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>
我试过javascript,我也看到这可以与php,但我不确定。
2条答案
按热度按时间piv4azn71#
在第二页中,你必须使用php来获取字段值。表单使用的是method=“post”,所以你可以从$_POST数组中获取字段值。
如果希望
<button type="submit" ...>
提交表单,则按钮必须位于<form>
中获取fname文本字段值的基本示例:
fslejnso2#
我添加了php,但什么都没有发生,它将进入下一页,但页面是空白的
可能是因为我得创建一个数据库