1

1)$ _ GET ['id']を使用してmysql行を定義します。2)データベースから電子メールアドレスを含む関連情報を抽出します。3)抽出した電子メールアドレスに電子メールを送信します。

エラー報告でエラーは報告されませんが(貼り付けられたコードではコメントアウトされていることに注意してください)、以下の変数($street2および$email)はインクルードファイルを介して保持されていないようです。コメントアウトされていない場合、エコーはすべて正常に機能します。$ email変数(インクルードファイルにあり、表示されていません)を実際の電子メールアドレスに置き換えると、すべてが正常に送信されます。

注意すべき主なことは9行目だと思います。$idを定義すると、すべてが正常に機能します。ただし、$_GETを使用して$id変数を定義しようとすると、エコーされた変数は引き続き正常に表示されます(つまり、dbクエリが成功します)が、インクルードファイルは機能しません。

これが私のコードです。HTMLフォームの上に配置されます。コード内にいくつかのコメントを含めたので、何が機能したかどうかをよりよく理解できます。

<?php
session_start() or die("Could not start session.");

//error_reporting(E_ALL);
//ini_set('display_errors', '1');
$id = 0;
if(isset($_GET['id']) && is_numeric($_GET['id']))
    $id = (int)$_GET['id'];
//$id=4;
//if Line 9 is not commented out, then the whole script works fine and email is sent
require('connect.php');

$query1 = mysql_query("SELECT street2 FROM prop_one WHERE sellerID='$id'") or die("OOPS: Bad    query1");
$row1 = mysql_fetch_assoc($query1, MYSQL_NUM);
$street2 = $row1[0];
//echo "This is $street2";

$query2=mysql_query("SELECT email FROM account WHERE sellerID='$id'") or die("OOPS: Bad query2");
$row2 = mysql_fetch_assoc($query2, MYSQL_NUM);
$email = $row2[0];
//echo "<br>This is $email";

if (isset($_POST['submit']))
{
include_once("emailSeller_inc.php");
}
?>

フォームは次のとおりです。

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" name="emailToSeller">
<fieldset>
  <legend>Your Contact Info
  </legend>
  <label for="conFName">First name*</label>
  <input name="conFName" type="text" id="conFName" value="<?php echo stripslashes(htmlentities($conFName)) ?>" placeholder="required" required = "required" size="35" maxlength="50"/>
<label for="conLName">Last name</label>
<input name="conLName" type="text" id="conLName" value="<?php echo stripslashes(htmlentities($conLName)) ?>" size="35" maxlength="50"/>
<label for="conEmail">Email*</label>
<input name="conEmail" type="email" id="conEmail" value="<?php echo stripslashes(htmlentities($conEmail)) ?>" placeholder="required" required="required" size="35" maxlength="50"/>
<label for="conTel">Phone</label>
    <input name="conTel" type="text" id="conTel" value="<?php echo stripslashes(htmlentities($conTel)) ?>" placeholder="" size="25" maxlength="15"/>&nbsp;e.g., 555.555.5555
</fieldset>

<fieldset style="text-align: center; position: absolute; top: -200; z-index: -1000;">
<input class="teaser" type="submit" name="submit" id="submit" value="Submit"/>
</fieldset>

<fieldset>
  <legend>Your Message
  </legend>
  <label for="conSubject">Subject*</label>
  <input name="conSubject" type="text" id="conSubject" value="<?php echo stripslashes(htmlentities($conSubject)) ?>" placeholder="required" required="required" size="35" maxlength="50"/>
  <label for="conMessage">Message*</label>
  <textarea name="conMessage" type="textarea" id="conMessage" placeholder="required" required="required" cols="50" rows="8" maxlength="400"/><?php echo stripslashes(htmlentities($conMessage)) ?></textarea>

  <label class="teaser">Email</label>
  <input class="teaser" name="validate" id="validate" type="text" autocomplete="off" />
</fieldset>

<fieldset style="text-align: center">
  <input class="button" type="submit" name="submit" id="submit" value="Send email"/>
</fieldset>
   </form>
  </div>
4

1 に答える 1

1

から ID を取得しようとしていますが、後での「送信」を$_GETチェックしています。$_POSTフォームのメソッドは何ですか? 私の推測では、あなたの方法は POST です。

$_GET['id']コメントで言及されているscalopusのように、9行目の前でecho'ingを試すか、に切り替えてみてください$_POST['id']

編集

コメントに記載されているように、id の非表示フィールドをフォームに追加します。一番下のelse dieはオプションで、期待通りに動作していることを確認したら削除できます。インクルードをisset($_POST['submit'])これ以上ラップする必要はありません。id が設定されている場合は、送信も同様です。お役に立てれば。

    <?php
    session_start() or die("Could not start session.");

    $id = 0;
    $email = null;
    $street2 = null;

    if(isset($_POST['id']) && is_numeric($_POST['id']))
    {
        $id = $_POST['id'];
        require('connect.php');

        $query = mysql_query("SELECT po.street2, a.email FROM prop_one po JOIN account a ON po.sellerId = a.sellerId WHERE sellerID = '$id' LIMIT 1") or die("OOPS: Bad query " . mysql_error() );
        list( $street2, $email ) = mysql_fetch_row($query);

        //echo "Street2 is $street2";
        //echo "<br>Email is $email";

        include_once("emailSeller_inc.php");
    }
    else
    {
       die( 'no Id set in Post');
    }
?>
于 2012-04-19T16:01:34.607 に答える