如何在操作重定向到另一个页面时在同一页面上调用php函数

时间:2016-03-05 12:41:58

标签: javascript php jquery html

我有一个问题。我想在提交时执行php函数,但由于多维数组foreach循环,php函数必须在同一页面上。所以简单来说输入类型="提交" action ="仅将$ orderid发布到ideal.php" onclick =" phpFunction在同一页面上#34;

这是我的代码:

$total =0;
$b = 0;
$items = array();
foreach ($_SESSION["cart_products"] as $cart_itm)
{
    $product_qty = $cart_itm["product_qty"];
    $pid = $cart_itm["product_code"];
    $results = mysql_query("SELECT * FROM Products WHERE ProductID = '".$pid."'");
    while($row = mysql_fetch_array ($results)) {
$naam = $row["ProductName"];
$liters = $row["ProductLiters"];
$kleur = $row["ProductColor"];
$product_price = $row["ProductPrice"];
$beschrijving = $row["ProductDescription"];
$image = $row["ProductImage"];
$merk = $row["SupplierID"];
}
    $items[] = array('pid' => $pid, 'qty' => $product_qty);
    $subtotal = ($product_price * $product_qty);
    $total = ($total + $subtotal);
?>

<div class="'.$bg_color.'">
    <h1 class="ptitel" id="ptitel"><?= $naam ?></h1>
    <p class="prijs" id="prijs">&euro;<?= $product_price ?> x <?= $product_qty ?></p>
    <p class="verzenden">Geen verzendkosten binnen Nederland</p>
    <p id="pinfo"><?= $beschrijving ?></p>
<div id="liter">
<p class="text">Liters:  <?= $liters ?></p>
</div>
<div id="kleur">
<p class="text">Kleur:  <?= $kleur ?></p>
  </div>
    </div>

    <?php
}
?>
    </div>
            <div class="left">
<?php
---------THIS HAS TO BE EXECUTED-----------
$orderid = mt_rand(100000,900000);
foreach ($items as $key => $value) {
mysql_query("INSERT INTO Bestellingen (pid, qty, orderid) VALUES         ('".$value['pid']."', '".$value['qty']."', '".$orderid."')");
}
------------------END----------------------


?>
    <form method="post" action="test.php">
        <input type="text" name="realname" id="name" placeholder="Volledige naam" required/>
        <input type="text" name="postcode" id="postcode" placeholder="Postcode" required/>
        <input type="text" name="adres" id="adres" placeholder="Straatnaam+huisnummer" required/>
        <input type="text" name="plaats" id="plaats" placeholder="Plaats" required/>
        <input type="tel" name="telefoon" id="telefoon" placeholder="Mobiel nummer" required/>
        <input type="email" name="email" id="email" placeholder="mail@voorbeeld.com" required/>
        <textarea name="Message" placeholder="Heeft u wat te vertellen?"></textarea>
        <input type="text" name="discount" id="discount" placeholder="Kortingscode"/>

        <input type="submit" name="betaal" class="knop" value="BETALEN &euro;<?= $total ?>" />
</form>

1 个答案:

答案 0 :(得分:0)

1。您可以使用ajax将表单日期发布到任何页面。

2。您可以根据方便使用js更新表单标记中的操作。

额外建议:使用标记<?php ?>