<?php
$mysql_pekare=mysqli_connect("localhost", "1","2", "3") or die(mysqli_error($mysql_pekare));
if(!empty($_GET['name'])) {
$query = "INSERT INTO Personinfo(`Personname`, `Personage`) VALUES('$_GET[namn]', '$_GET[age]')";
if (!mysqli_query($mysql_pekare,$query)) {
die('Error: ' . mysqli_error($mysql_pekare));
}
echo "Welcome ". $_GET["namn"];
}
?>
<form id="Personinfo" action="index.php" > <!-- default form method is GET -->
<input type="text" id="namn" name="namn" placeholder="namn"/>
<input type="text" id="age" name="age" placeholder="age"/>
<input type="submit"/>
</form>
</body>
<body>
<?php
$mysql_pekare=mysqli_connect("localhost", "1","2", "3") or die(mysqli_error($mysql_pekare));
if(!empty($_GET['Product'])) {
$query = "INSERT INTO Produkter(`ProduktNamn`, `ProduktPris`) VALUES('$_GET[Product]', '$_GET[Price]')";
if (!mysqli_query($mysql_pekare,$query)) {
die('Error: ' . mysqli_error($mysql_pekare));
}
}
?>
<form id="Produkter" action="index.php" > <!-- default form method is GET -->
<input type="text" id="Product" name="Product" placeholder="Produkt" />
<input type="text" id="Price" name="Price" placeholder="Pris"/>
<input type="submit"/>
</form>
You have two forms with different input names, so you can check for these names, instead of generic $_GET
:
if( isset( $_GET['namn'] ) )
{
(...)
}
elseif( isset( $_GET['Product'] ) )
{
(...)
}
If you want be more chic , you can identify different forms through an hidden <input>
identifier:
<form id="Personinfo" action="index.php" >
<input type="hidden" name="formID" value="Personinfo"/>
(...)
<form id="Produkter" action="index.php" >
<input type="hidden" name="formID" value="Produkter"/>
(...)
and in you php code, check for this:
if( isset( $_GET['Personinfo'] ) )
{
(...)
}
elseif( isset( $_GET['Produkter'] ) )
{
(...)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.