0

フォームを取得し、jquery で変数チェックを行い、それを ajax の php ファイルに渡しますが、この通知が表示されます

Notice: Undefined index: your_name in C:\xampp\htdocs\process.php 行 3 ここで何かが間違っています Notice: Undefined index: your_email in C:\xampp\htdocs\process.php 行 7

ここに私のjqueryコードがあります

        $(".button").click(function(){
    $('.error').hide(); 
    var your_email=$("input#your_email").val(); 
    if(your_email ==""){
        $("label#youremail_error").show();  
        $("input#your_email").focus(); 
        return false; 
    }
    var your_name=$("input#your_name").val(); 
    if(your_name==""){
        $("label#yourname_error").show();
        $("input#your_name").focus(); 
        return false; 
    }
    var friends_email=$("input#friends_email").val(); 
    if(friends_email==""){
        $("label#friendsemail_error").show(); 
        $("input#friends_email").focus(); 
        return false; 
        }
    var friends_name=$("input#friends_name").val(); 
    if(friends_email==""){
        $("label#friendsname_error").show(); 
        $("input#friends_name").focus(); 
        return false;
        }
        var dataString = 'your_email=' + your_email + '&friends_email=' + friends_email + '&your_name=' + your_name + '&friends_name=' + friends_name; 
        //alert(dataString); 
        $.ajax({
        type: "POST", 
        url:"process.php",
        data: dataString, 
        success: function(ret) {
            alert(ret); 
            //alert("thank you for signing up"); 
        },

ここに私のPHPがあります

   <?php
include 'inc/class.phpmailer.php';
if(isset($_POST['your_name'])){
    $your_name=$_POST['your_name'];
    }
else{
    echo "something is wrong with your name having:";
    var_dump($_POST['your_name']);
    echo "<br/>"; 
    }
if(isset($_POST['your_email'])){
    $your_email=$_POST['your_email']; 
}
else{
    echo "something is wrong with your email having:";
    var_dump($_POST['your_email']); 
    echo "<br/>"; 
    }
if(isset($_POST['friends_name'])){
    $friends_name=$_POST['friends_name']; 
    }
else{
    echo "something is wrong with friends name having:"; 
    var_dump($_POST['friends_name']);
    echo "<br/>"; 
    }

この通知が表示される理由がわかりません $_POST の値が設定されていないようです。
私はこれで頭がいっぱいです。$_POST が設定されていない理由/時期を知っていますか?

4

3 に答える 3

2

最初に your_name の値を取得してから、それが存在するかどうかを確認しています

$your_name=$_POST["your_name"];  <--- this line should be inside an if isset
if(!isset($_POST['your_name'])){

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

if (isset($_POST['your_name'])) {
   $your_name = $_POST['your_name'];
   // do whatever here
}
于 2012-04-24T07:51:50.327 に答える
1

$_POST['your_name'] を変数 $your_name に割り当てることはできません。「your_name」が投稿されていないため、存在しないためです..最初に存在するかどうかを確認してから、変数に割り当てる必要があります..コードは次のようになります。

if (isset($_POST['your_name'])) {
   $your_name = $_POST['your_name'];
}
else { 
   echo "something is wrong here";
}
于 2012-04-24T11:15:39.497 に答える
0

あなたのjsコードには何の問題も見られませんでしたが、あなたのphpコードには小さな欠陥があります

 <?php
include 'inc/class.phpmailer.php';

//it can be like that or
if(!isset($_POST['your_name'])){
    echo "something is wrong here"; 
}
else{
    $your_name=$_POST["your_name"]; 
}

注: PHP エラー処理を適切に行う必要があります。そうしないと、php 警告を無効にすることができます。

于 2012-04-24T09:11:32.287 に答える