-3

以下は、空のフィールドまたは不要な文字を検出し、出力としてエラー メッセージを警告するために php 内にフォーム検証を実装する例を示しています。私はこの作品にクレジットを持っていません。自分のサイトのニーズに合うようにそれらをほとんど合成していません。これは、以前にコードを見つけるのが困難であったため、コードを共有するためのものです。以下の回答は、私がそれを機能させることができなかった、より高度な解決策を提供します。それは彼らの問題ではなく、php の私の初心者のスキルによるものです。

したがって、基本的には、以前の私のような初心者を支援するための基本的な手順を示しているだけです。以下のコードは、ユーザーが送信を押したときに、非常に基本的な php フォームの検証と特定の電子メール アドレスへの電子メールを示しています。

<?php
   $me =$_SERVER['REQUEST_METHOD']; 
 if ($_POST['mail']=='' && $me =="POST") { //remember in the input tag,set name as 'mail' and in form tag set action to " "; 

$name = preg_replace('/[^A-Za-z]/','', $_POST['name']);//filter all letters only
$tel = preg_replace('/[^0-9]/','', $_POST['tel']);//filter all number only
//$email$regex credit to Adam Khoury www.developphp.com
$email = $_POST['email'];
$regex = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/'; 

$comments = preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '', $_POST['comments']); //allow alphanumeric only

$error_status = false;//set default error status as false

if (empty($email)){ //empty in the field, it should go through these codes, remember don't put any value in the input tag thou, or else it will detect it as the default value
$error_email='<h4>Please fill in your email</h4>';
$error_status = true; //error status toggle
} else
if (preg_match($regex, $email)) { //if this is to ensure the format of email correctly entered
   } else { 
     $error_email='<h4>This is an invalid email. Please try again.</h4>';
     $error_status = true;
} 


if (empty($name)){
$error_name= '<h4>Please Fill Your Name</h4>';
$error_status = true;
} 

if (empty($tel)){
$error_tel ='<h4>Please Fill Your Contact Number</h4>';
$error_status = true;
}

if (empty($comments)){
$error_comments ='<h4>Please give us comments</h4>';
$error_status = true;
}


if(!$error_status) {
$success='<h4>Thanks for your comments. We will reply to you shortly</h4>';
$to_address="someone@gmail.com";
$subject="Online Comments";

$message="Input from online comments box.\n\n";
$message .="Name: ".$name."\n";
$message .="Tel: ".$tel."\n";
$message .="Email: ".$email."\n";
$message .="Comments: ".$comments."\n";

mail($to_address, $subject, $message);
unset($name,$tel,$email,$comments);
}
}

?>
4

3 に答える 3

1

たとえば、次のように、フォーム フィールドが最初に投稿され、cart.php で有効かどうかを確認します。

if(is_numeric($_POST["quantity"]) && $_POST["quantity"]>0) {
 $each_item['quantity']=$_POST["quantity"];
}

ここで、数量がゼロではなく数値であることを確認しています。より多くのフィールドに対してこれを行うことができ、チェックを作成するタイプに応じて、次のようになります。

if(!empty($_POST["customer_name"])) {
 $customerName=$_POST["customer_name"];
}

より高度な検証には、正規表現を使用できます: preg-match

于 2013-07-31T08:33:42.033 に答える
1

あなたの問題はあなたのif文にあります

これを置き換えます:

if (empty($_POST['customer_name']) $err[] = "Username field is required";  
if (empty($_POST['tel_num']) $err[] = "Comments field is required";  

と:

if (empty($_POST['customer_name'])) {
  $err[] = "Username field is required";
  }  
if (empty($_POST['tel_num'])) {
  $err[] = "Comments field is required";  
}

問題は、立っていた)後を逃したことです。)

だからあなたはこれを持っていました:

empty($_POST['customer_name']) //notice 1 (

しかし、それはこれでなければなりません:

empty($_POST['customer_name'])) //notice 2 (

また、<?phpを開くためにショートタグ()を使用<?phpしますが、他のスクリプトと同じように使用することをお勧めします

編集

cart.php では、次のコードを使用する必要があります。

<?php  
if ($_SERVER['REQUEST_METHOD']=='POST') {  
  $err = array();
  //performing all validations and raising corresponding errors
  if (empty($_POST['customer_name'])) {
  $err[] = "Username field is required";
  }  
  if (empty($_POST['tel_num'])) {
  $err[] = "Comments field is required";  
  }

  if (empty($err)) {  
    //if no errors - saving data and redirect
    header("Location: ".$_SERVER['PHP_SELF']);
    exit;
  }  else {
    // all field values should be escaped according to HTML standard
    foreach ($_POST as $key => $val) {
      $form[$key] = htmlspecialchars($val);
    }
  }
} else {
  $form['customer_name'] = 'm;
  $form['tel_num'] = '';  
}
include 'form.tpl.php';
?>  

EDIT2 ご質問のコードを再度確認しました。問題は見つかりませんでした。私はいくつかの小さな変更を加えました

このスクリプトを使用すると、機能するはずです。

<?php
    session_start();
    /* Created by Adam Khoury @ www.developphp.com */

    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    // Connect to the MySQL database  
    include "storescripts/connect_to_mysqli.php";

    // Determine which page ID to use in our query below ---------------------------------------------------------------------------------------
    if (!empty($_GET['pid'])) {
        $pageid = 1;
    } else {
        $pageid = preg_replace("[^0-9]", "", $_GET['pid']); // filter everything but numbers for security
    }

    // Query the body section for the proper page
    $sqlCommand = "SELECT pagebody FROM pages WHERE id='$pageid' LIMIT 1";
    $query = mysqli_query($myConnection, $sqlCommand) or die(mysqli_error());
    while ($row = mysqli_fetch_array($query)) {
        $body = $row["pagebody"];
    }
    mysqli_free_result($query);
    //---------------------------------------------------------------------------------------------------------------------------------------------------------------
    // Query the module data for display ---------------------------------------------------------------------------------------------------------------
    $sqlCommand = "SELECT modulebody FROM modules WHERE showing='1' AND name='footer' LIMIT 1";
    $query = mysqli_query($myConnection, $sqlCommand) or die(mysqli_error());
    while ($row = mysqli_fetch_array($query)) {
        $footer = $row["modulebody"];
    }
    mysqli_free_result($query);
    //---------------------------------------------------------------------------------------------------------------------------------------------------------------
    // Query the module data for display ---------------------------------------------------------------------------------------------------------------
    $sqlCommand = "SELECT modulebody FROM modules WHERE showing='1' AND name='custom1' LIMIT 1";
    $query = mysqli_query($myConnection, $sqlCommand) or die(mysqli_error());
    while ($row = mysqli_fetch_array($query)) {
        $custom1 = $row["modulebody"];
    }
    mysqli_free_result($query);
    //---------------------------------------------------------------------------------------------------------------------------------------------------------------
    // Build Main Navigation menu and gather page data here -----------------------------------------------------------------------------


    $sqlCommand = "SELECT id, linklabel FROM pages WHERE showing='1' ORDER BY id DESC";
    $query = mysqli_query($myConnection, $sqlCommand) or die(mysqli_error());

    $menuDisplay = '';
    while ($row = mysqli_fetch_array($query)) {
        $pid = $row["id"];
        $linklabel = $row["linklabel"];
        $menuDisplay .= '<a href="index.php?pid=' . $pid . '">' .
                $linklabel . '</a><br />';
    }
    mysqli_free_result($query);
    //---------------------------------------------------------------------------------------------------------------------------------------------------------------
    //mysqli_close($myConnection); 
    // This file is www.developphp.com curriculum material
    // Written by Adam Khoury January 01, 2011
    // http://www.youtube.com/view_play_list?p=442E340A42191003
    // Script Error Reporting
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //       Section 1 (if user attempts to add something to the cart from the product page)
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    if (isset($_POST['pid'])) {
        $pid = $_POST['pid'];
        $wasFound = false;
        $i = 0;
        // If the cart session variable is not set or cart array is empty
        if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) {
            // RUN IF THE CART IS EMPTY OR NOT SET
            $_SESSION["cart_array"] = array(0 => array("item_id" => $pid, "quantity" => 1));
        } else {
            // RUN IF THE CART HAS AT LEAST ONE ITEM IN IT
            foreach ($_SESSION["cart_array"] as $each_item) {
                $i++;
                while (list($key, $value) = each($each_item)) {
                    if ($key == "item_id" && $value == $pid) {
                        // That item is in cart already so let's adjust its quantity using array_splice()
                        array_splice($_SESSION["cart_array"], $i - 1, 1, array(array("item_id" => $pid, "quantity" => $each_item['quantity'] + 1)));
                        $wasFound = true;
                    } // close if condition
                } // close while loop
            } // close foreach loop
            if ($wasFound == false) {
                array_push($_SESSION["cart_array"], array("item_id" => $pid, "quantity" => 1));
            }
        }
        header("location: cart.php");
        exit();
    }

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //       Section 2 (if user chooses to empty their shopping cart)
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    if (isset($_GET['cmd']) && $_GET['cmd'] === 'emptycart') {
        unset($_SESSION["cart_array"]);
    }

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //       Section 3 (if user chooses to adjust item quantity)
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    if (isset($_POST['item_to_adjust']) && $_POST['item_to_adjust'] != "") {
        // execute some code
        $item_to_adjust = $_POST['item_to_adjust'];
        $quantity = $_POST['quantity'];
        $quantity = preg_replace('#[^0-9]#i', '', $quantity); // filter everything but numbers
        if ($quantity >= 100) {
            $quantity = 99;
        }
        if ($quantity < 1) {
            $quantity = 1;
        }
        if (empty($quantity)) {
            $quantity = 1;
        }
        $i = 0;
        foreach ($_SESSION["cart_array"] as $each_item) {
            $i++;
            while (list($key, $value) = each($each_item)) {
                if ($key == "item_id" && $value == $item_to_adjust) {
                    // That item is in cart already so let's adjust its quantity using array_splice()
                    array_splice($_SESSION["cart_array"], $i - 1, 1, array(array("item_id" => $item_to_adjust, "quantity" => $quantity)));
                } // close if condition
            } // close while loop
        } // close foreach loop
    }

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //       Section 4 (if user wants to remove an item from cart)
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    if (isset($_POST['index_to_remove']) && $_POST['index_to_remove'] !== '') {
        // Access the array and run code to remove that array index
        $key_to_remove = $_POST['index_to_remove'];
        if (count($_SESSION["cart_array"]) <= 1) {
            unset($_SESSION["cart_array"]);
        } else {
            unset($_SESSION["cart_array"][$key_to_remove]);
            sort($_SESSION["cart_array"]);
        }
    }

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //       Section 5  (render the cart for the user to view on the page)
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    $cartOutput = "";
    $cartTotal = "";
    $pp_checkout_btn = '';
    $product_id_array = '';

    if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) {
        $cartOutput = "<h3 align='center'>Your shopping cart is empty</h3>";
    } else {
        // Start PayPal Checkout Button

        $pp_checkout_btn .= '<form action="http://chenlikpharmacy.freeserver.me/order_list.php" method="post">
    <input type="hidden" name="cartOutput" value = "$cartOutput">';

        // Start the For Each loop
        $i = 0;
        foreach ($_SESSION["cart_array"] as $each_item) {
            $item_id = $each_item['item_id'];
            $sqlCommand = "SELECT * FROM products WHERE id='$item_id' LIMIT 1";
            $sql = mysqli_query($myConnection, $sqlCommand);
            while ($row = mysqli_fetch_array($sql)) {
                $product_name = $row["product_name"];
                $price = $row["price"];
                $details = $row["details"];
            }
            $pricetotal = $price * $each_item['quantity'];
            $cartTotal = $pricetotal + $cartTotal;
            setlocale(LC_MONETARY, "en_US");
            $pricetotal = money_format("%10.2n", $pricetotal);
    // Dynamic Checkout Btn Assembly

            $pp_checkout_btn .= '<input type="hidden" name="item_name[]" value="' . $product_name . '">
    <input type="hidden" name="amount[]" value="' . $price . '">
    <input type="hidden" name="quantity[]" value="' . $each_item['quantity'] . '">  ';
            // Create the product array variable
            $product_id_array .= "$item_id-" . $each_item['quantity'] . ",";
            // Dynamic table row assembly
            $cartOutput .= "<tr>";
            $cartOutput .= '<td><a href="product.php?id=' . $item_id . '">' . $product_name . '</a><br /><img src="inventory_images/' . $item_id . '.jpg" alt="' . $product_name . '" width="40" height="52" border="1" /></td>';
            $cartOutput .= '<td>' . $details . '</td>';
            $cartOutput .= '<td>RM' . $price . '</td>';
            $cartOutput .= '<td><form action="cart.php" method="post">
            <input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" />
            <input name="adjustBtn' . $item_id . '" type="submit" value="change" />
            <input name="item_to_adjust" type="hidden" value="' . $item_id . '" />
            </form></td>';
            //$cartOutput .= '<td>' . $each_item['quantity'] . '</td>';
            $cartOutput .= '<td>' . $pricetotal . '</td>';
            $cartOutput .= '<td><form action="cart.php" method="post"><input name="deleteBtn' . $item_id . '" type="submit" value="X" /><input name="index_to_remove" type="hidden" value="' . $i . '" /></form></td>';
            $cartOutput .= '</tr>';
            $i++;
        }
        setlocale(LC_MONETARY, "ms_MY");
        $cartTotal = money_format("%10.2n", $cartTotal);
        $cartTotal = "<div style='font-size:18px; margin-top:12px;' align='right'>Cart Total : " . $cartTotal . " MYR</div>";
        // Finish the Paypal Checkout Btn
        $pp_checkout_btn .= '<input type="hidden" name="custom" value="' . $product_id_array . '">
    Name: <input type="text" name="customer_name">
    <br/>
    Tel: <input type="text" name="tel_num">

        <input type="submit" value="Submit">
        </form>';
    }

    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        $err = array();
        //performing all validations and raising corresponding errors
        if (empty($_POST['customer_name'])) {
            $err[] = "Username field is required";
        }
        if (empty($_POST['tel_num'])) {
            $err[] = "Comments field is required";
        }

        if (empty($err)) {
            //if no errors - saving data and redirect
            header("Location: " . $_SERVER['PHP_SELF']);
            exit;
        } else {
            // all field values should be escaped according to HTML standard
            foreach ($_POST as $key => $val) {
                $form[$key] = htmlspecialchars($val);
            }
        }
    } else {
        $form['customer_name'] = '';
        $form['tel_num'] = '';
    }
    include 'form.tpl.php';
    ?>  
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html lang="en-US" xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
        <head>
            <title>CHENLIK PHARMACY ONLINE CATALOGUE</title>
            <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
            <link rel="shortcut icon" href="css/images/favicon.ico" />
            <link rel="stylesheet" href="css/style.css" type="text/css" media="all" />
            <script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
            <script type="text/javascript" src="js/jquery.jcarousel.min.js"></script>
            <!--[if IE 6]>
            <script type="text/javascript" src="js/png-fix.js"></script>
            <![endif]-->
            <script type="text/javascript" src="js/functions.js"></script>
        </head>
        <body>
            <!-- Header -->
            <div id="header" class="shell">
                <div id="logo">
                    <h1><a href="http://chenlikpharmacy.freeserver.me/index.php">Chenlik Pharmacy Sdn. Bhd.</a></h1><span><a href="http://chenlikpharmacy.freeserver.me">Serve with Care & Passion</a></span></div>

                <!-- Navigation -->
                <div id="navigation">
                    <ul>
                        <li><a href="http://chenlikpharmacy.freeserver.me/index.php" >Home</a></li>
                        <li><a href="http://chenlikpharmacy.freeserver.me/product_list.php">Products</a></li>
                        <li><a href="http://chenlikpharmacy.freeserver.me/promotions.php">Promotions</a></li>
                        <li><a href="http://chenlikpharmacy.freeserver.me/profile.php">Profile</a></li>
                        <li><a href="http://chenlikpharmacy.freeserver.me/about_us.php" class="active">About Us</a></li>
                        <li><a href="http://chenlikpharmacy.freeserver.me/contacts.php" >Contacts</a></li>
                    </ul>
                </div>

                <!-- End Navigation -->

                <div class="cl">&nbsp;</div>

                <!-- Login-details -->

                <div id="login-details">

                    <p>Welcome, <a href="#" id="user">Guest</a> .</p>
                    <p><a href="http://chenlikpharmacy.freeserver.me/cart.php" class="cart" ><img src="css/images/cart-icon.png" alt="" /></a>Shopping Cart <a href="http://chenlikpharmacy.freeserver.me/cart.php" class="sum"> Cart Total</a></p>

                </div>

                <!-- End Login-details -->

            </div>
            <!-- End Header -->


            <!-- Main -->

            <div id="main" class="shell">


                <!-- Products -->
                <div id="main" class="products">            
                    <table width="100%" border="1" cellspacing="0" cellpadding="6">
                        <tr>
                            <td width="18%" bgcolor="#C5DFFA"><strong>Product</strong></td>
                            <td width="45%" bgcolor="#C5DFFA"><strong>Product Description</strong></td>
                            <td width="10%" bgcolor="#C5DFFA"><strong>Unit Price</strong></td>
                            <td width="9%" bgcolor="#C5DFFA"><strong>Quantity</strong></td>
                            <td width="9%" bgcolor="#C5DFFA"><strong>Total</strong></td>
                            <td width="9%" bgcolor="#C5DFFA"><strong>Remove</strong></td>
                        </tr>
    <?php echo $cartOutput; ?><br/>

        <!-- <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr> -->
                    </table>
    <?php echo $cartTotal; ?>
                    <br />
                    <br />
    <?php echo $pp_checkout_btn; ?>
                    <br />
                    <br />
                    <a href="cart.php?cmd=emptycart">Click Here to Empty Your Shopping Cart</a>

                    <!-- End Products -->


                    <div class="cl">&nbsp;</div>

                </div>



                <div class="cl">&nbsp;</div>

            </div>

            <!-- End Main -->

            <!-- Footer -->

            <div id="footer" class="shell">

                <div class="top">

                    <div class="cnt">

                        <div class="col about">

                            <h4>About Chenlik Pharmacy Sdn. Bhd.</h4>

    <?php echo $custom1; ?>

                        </div>

                        <div class="col store">

                            <h4>Store</h4>

    <?php echo $footer; ?>

                        </div>

                        <div class="col" id="newsletter">

                            <h4>Newsletter</h4>

                            <p>This function is not activate yet. </p>

                            <form action="" method="post">

                                <input type="text" class="field" value="Your Name" title="Your Name" />

                                <input type="text" class="field" value="Email" title="Email" />

                                <div class="form-buttons"><input type="submit" value="Submit" class="submit-btn" />
                                </div>

                            </form>

                        </div>

                        <div class="cl">&nbsp;</div>

                        <div class="copy">

                            <p>&copy;2013 <a href="http://chenlikpharmacy.freeserver.me">Chenlik Pharmacy Sdn. Bhd.</a>&nbspDesign by <a href="http://css-free-templates.com/">CSS-FREE-TEMPLATES.COM</a> &nbsp.Source code credit to: <a href="http://www.developphp.com">Adam Khoury</a>. Modified & Complied by: Philip Tiong</p>
                        </div>
                    </div>
                </div>
            </div>
            <!-- End Footer -->
        </body>
    </html>

エラーを表示するには、エラーを表示する html にこれを追加する必要があります。

<?php
if (!empty($err)) :
foreach ($err as $error) :
echo $error; 
endforeach;
endif;
于 2013-07-31T19:42:10.107 に答える
0

php は、サーバー側の検証、つまりフォームの送信後に使用できます。フォームの入力中にエントリを検証する場合は、jquery を使用する必要があります。私は両方の方法の例に言及しています。

<script> 
$(document).ready(function(){
$( "#registerationform" ).validate({
    rules: {
           fname:"required",
           lname:"required",
           age: {required: true,
                number: true,
                digits: true,

           },
           email:{ required:true,
                    email: true
           },
           pword:{required: true,
                    minlength: 5
           },
           uname: {required : true
           }

        },
   messages: {
        fname:"Please, enter your First name",
        lname:"Please, enter your Last name",
        age:{required :"Please, Enter your age",
             number: "Only numerals"
        },
        email: {required :"Please, Enter your Email ID",
                email :"Please, Enetr a valid Email ID"
        },
        pword:{required:"Please, Enter your password",
                minlength:"Minimum 5 character required"
        },
        uname:"Please, Enter your UserName"


        }

    });
});
</script>


<form name="registerationform" id="registerationform" method="post" autocomplete="off">
    <input type="hidden" name="action" value="signup">
    <div class="editProfileCont">
            <div class="formFieldRow">
             <div class="fields">

    First Name<sup><font color="#FF0000">*</sup></font>: <input type="text" name="fname"  maxlength="30" id="fname" class="required" minlength="1" value="<?php if(isset($_POST[fname])){ echo $_POST[fname];}?>"></div></div><br><br>
     <div class="formFieldRow">
         <div class="fields">
    Last Name<sup><font color="#FF0000">*</sup></font>: <input type="text" name="lname"  maxlength="30" id="lname" class="required" minlength="1" value="<?php if(isset($_POST[lname])){ echo $_POST[lname];}?>"></div></div> <br><br>
     <div class="formFieldRow">
         <div class="fields">
    Age<sup><font color="#FF0000">*</sup></font>:       <input type="text" name="age" maxlength="2" id="age" class="required" minlength="1" value="<?php if(isset($_POST[age])){ echo $_POST[age];}?>"></div></div><br>
    <b><?php echo $errorEmail?><br></b>
     <div class="formFieldRow">
         <div class="fields">
    E-Mail Id<sup><font color="#FF0000">*</sup></font>: <input type="text" name="email" maxlength="40" id="email" class="required email" minlength="1" value="<?php if(isset($_POST[email])){ echo $_POST[email];}?>"></div></div><br>
    <b><?php echo $errorUname?><br></b>
    <div id="disp"></div>
     <div class="formFieldRow">
         <div class="fields">
    User Name<sup><font color="#FF0000">*</sup></font>: <input type="text" name="uname"  maxlength="10" id="uname" class="required" minlength="1" value="<?php if(isset($_POST[uname])){ echo $_POST[uname];}?>"></div></div> <br><br>
     <div class="formFieldRow">
         <div class="fields">
    Password<sup><font color="#FF0000">*</sup></font>:  <input type="password" name="pword" id="pword" class="required" minlength="5"></div></div><br><br><br>

  




これは、フォームと同じページでの jquery 検証でした。フォームのアクション ページで、php 検証を実行します。これは非常に簡単です。

<?php
if(isset($_post['uname'])){
$uname = $_post['uname'];
$sql="INSERT INTO persons ( UserName )Values('$_POST[uname]')";
}else echo "please enter username/empty fields not allowed";
?>
于 2013-07-31T09:07:21.377 に答える