0

こんにちは、私は Web 開発の新しい学習者です。

ユーザーが送信ボタンをクリックした後、フォームを含むページがあり、ボタンはフォームのコンテンツを次のページに送信して実行し、データベースに保存します。

そのため、私のページは別のページに移動して実行し、ランディング ページに戻ります。

例: index.php と exec.php

index.php:

<form name="g-form" action="gbtn-exec.php" method="post" class="goat-vote" onsubmit="return validategForm()">
<input type="text" name="g-product" placeholder="Brand / Product Name" style="-moz-border-radius: 5px; border-radius: 5px; padding-left:20px; opacity:.5; border:none; margin-left:110px; width:440px; height:38px; font-family:'Proxima Nova Rg';color:#000; font:1.6em;" />


<p class="g-question">Why you love it?</p>

<textarea name="g-reason" style="-moz-border-radius: 5px; border-radius: 5px; padding:5px; opacity:.5; border:none; margin-left:110px; width:450px; height:150px; font-family:'Proxima Nova Rg';color:#333; font-size:1em;"></textarea>

<input name="g-btn" class="vote-btn" type="submit" value="vote" style="margin-left:470px; cursor:pointer;"></form>

exec.php

if ($_POST["g-product"] && $_POST["g-reason"] != "" )
{
$gproduct = $_POST["g-product"];
$greason =  $_POST["g-reason"];

$insert ="INSERT INTO jovine.vote (vote_id ,product_name ,reason ,type) VALUES (NULL, '$gproduct', '$greason', 'goat')";
$result = mysql_query($insert,$con);
echo "<script>";
echo "alert('Thank you. Your vote has been recorded.');";
echo "window.location.href='index.php';";
echo "</script>";
}

私の質問は、exec.php に行かずに index.php で送信ボタンを実行するにはどうすればよいですか? (.php で両方を結合することを意味します) これは、ユーザーが送信ボタンをクリックすると、空白のページが実行され、見栄えがよくないためです。

誰でも助けることができますか?ありがとう!=)

4

3 に答える 3

0

編集:これは無視してください。質問を完全に読んでいないようです

次のようなことを試してください:

index.php

<form name="g-form" action="gbtn-exec.php" method="post" class="goat-vote" onsubmit="return validategForm()">
    <input type="text" name="g-product" placeholder="Brand / Product Name" style="-moz-border-radius: 5px; border-radius: 5px; padding-left:20px; opacity:.5; border:none; margin-left:110px; width:440px; height:38px; font-family:'Proxima Nova Rg';color:#000; font:1.6em;" />

    <p class="g-question">Why you love it?</p>

    <textarea name="g-reason" style="-moz-border-radius: 5px; border-radius: 5px; padding:5px; opacity:.5; border:none; margin-left:110px; width:450px; height:150px; font-family:'Proxima Nova Rg';color:#333; font-size:1em;"></textarea>

    <?php if(!isset($_GET['hidesubmit'])): ?>
    <input name="g-btn" class="vote-btn" type="submit" value="vote" style="margin-left:470px; cursor:pointer;">
    <?php endif; ?>
</form>

exec.php

if ($_POST["g-product"] && $_POST["g-reason"] != "" )
{
    $gproduct = $_POST["g-product"];
    $greason =  $_POST["g-reason"];

    $insert ="INSERT INTO jovine.vote (vote_id ,product_name ,reason ,type) VALUES (NULL, '$gproduct', '$greason', 'goat')";
    $result = mysql_query($insert,$con);
    echo "<script>";
    echo "alert('Thank you. Your vote has been recorded.');";
    echo "window.location.href='index.php?hidesubmit=1';";
    echo "</script>";
}
于 2013-09-23T08:00:40.390 に答える
0
if (isset($_POST["g-btn"]))
{
 $gproduct = $_POST["g-product"];
 $greason =  $_POST["g-reason"];

 $insert ="INSERT INTO jovine.vote (vote_id ,product_name ,reason ,type) VALUES (NULL, '$gproduct', '$greason', 'goat')";
 $result = mysql_query($insert,$con);
 echo "<script>";
 echo "alert('Thank you. Your vote has been recorded.');";
 echo "window.location.href='index.php';";
 echo "</script>";
}

<html>
<form name="g-form" action="a.php" method="post" class="goat-vote" onsubmit="return validategForm()">
<input type="text" name="g-product" placeholder="Brand / Product Name" style="-moz-border-radius: 5px; border-radius: 5px; padding-left:20px; opacity:.5; border:none; margin-left:110px; width:440px; height:38px; font-family:'Proxima Nova Rg';color:#000; font:1.6em;" />


<p class="g-question">Why you love it?</p>

<textarea name="g-reason" style="-moz-border-radius: 5px; border-radius: 5px; padding:5px; opacity:.5; border:none; margin-left:110px; width:450px; height:150px; font-family:'Proxima Nova Rg';color:#333; font-size:1em;"></textarea>

<input name="g-btn" class="vote-btn" type="submit" value="vote" style="margin-left:470px; cursor:pointer;"></form>
</html>

あなたはこのようにすることができます... isset($_POST["g-btn"]) クリックされたかどうかを確認しますか?

于 2013-09-23T08:01:02.900 に答える