简体   繁体   English

如何获得两个不同的_GET? (php,mysql,apache,phpmyadmin)

[英]How can I have two different _GET? (php, mysql, apache, phpmyadmin)

<?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 : 您有两种具有不同输入名称的表单,因此可以检查这些名称,而不是通用$_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: 如果您想更别致 ,则可以通过隐藏的<input>标识符识别不同的形式:

<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: 并在您的php代码中,检查以下内容:

if( isset( $_GET['Personinfo'] ) )
{
    (...)
}
elseif( isset( $_GET['Produkter'] ) )
{
    (...)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MySQL-获得两个不同的结果(PHP和phpMyAdmin) - MySQL - Getting Two Different Results (PHP and phpMyAdmin) 我如何才能在PHPmyadmin中工作的mysql脚本在PHP mysql查询中工作? - How can I get a mysql script that works in PHPmyadmin, to work in a PHP mysql query? 如何获得 MySQL 中两个不同行的 timediff? - How can i get the timediff of two different rows in MySQL? 我的php代码中有一个mysql查询,该查询被剪切并粘贴在两个地方。 我如何才能将它放在一个地方? - I have a mysql query in my php code that is cut and pasted in two places. How can I get it to be in one place? 如何在Mac上开始使用Apache,MySQL和(PHP,Perl,Python)? - How can I get started with Apache, MySQL, and (PHP, Perl, Python) on a Mac? PHP 4.4.9和匹配的mysql,phpmyadmin和apache - PHP 4.4.9 and matching mysql, phpmyadmin & apache 我可以在两台使用PHP的不同服务器上使用MySql Create Select吗? - Can I use MySql Create Select on two different servers with PHP? mysql排序规则在php / mysql / phpmyadmin中有所不同 - mysql collation different in php/mysql/phpmyadmin 如何使用php将两种不同形式的输入存储在mySQL数据库中? - How can I store the input of two different forms in mySQL database with php? 如何使用 php mysql 数据库更新和插入两个不同的表 - How can I update and insert into two different tables using php mysql database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM