English 中文(简体)
显示员额的合乎逻辑的方法是使用php提交错误信息
原标题:A logical method of displaying post submit error messages using php
//deal with individual form section posts
//-->Faction Name
if(isset($_POST[ factionname ])){
    $unsani_faction_name = $_POST[ faction ];
    $new_faction_name = str_replace(",", "", $unsani_faction_name);
    $faction_name = mysql_real_escape_string($new_faction_name);
    $faction_name = preg_replace( /ss+/ ,    , $faction_name);//strips excess white space
    $faction_name = stripslashes($faction_name);//strips slashes from name

    //remove special chars except: "& $ £ ^ - ( )"
    $faction_name = preg_replace( /[^a-z0-9s£&$^()-]/i ,   , $faction_name);  
    $string_length = strlen($faction_name);

    if($string_length < 0 || $string_length > 20) { 
        echo  <strong>Error:</strong> Property name needs to be between 1-20 characters.&nbsp; ; 
    }else { 
        $sql = mysql_query("SELECT * FROM ".TBL_USERPROPBANKS." WHERE prop_name= $prop_name "); 
        $num_rows = mysql_num_rows($sql);
        if ($num_rows > 0) { 
            echo  <strong>Error:</strong> Bank with the same name in existance.&nbsp; ; 
        }else {  
            mysql_query("UPDATE ".TBL_USERPROPBANKS." SET prop_name= $prop_name  WHERE prop_id= $bankid "); 
            header("Location: bank_cp.php?bankid=".$bankid."&section=settings");
        }
    }

I m working out my errors using the above method. What is (in your opinion) the most logical way to:

  1. Counting the number of errors
  2. And echoing/printing them inside a separate section of my layout to show each error message in a list?

我现在可以想到的是,如果独一无二的变数不符合我的验证要求,那么就把无效价值分配给独一无二的var,然后用独一无二的错误信息加以填补(这将是20+不同错误)。 在这个问题上有什么想法?

最佳回答

我将建立一个空洞的阵列,我将把错误推向前进,然后简单地加以澄清和展示。

$errors = array();
...
if($string_length < 0 || $string_length > 20) {
  $errors[] =  <strong>Error:</strong> Property name needs to be  between 1-20 characters.&nbsp; ;
}
...
if($num_rows > 0) {
  $errors[] =  <strong>Error:</strong> Bank with the same name in existance.&nbsp; ;
}

// lower in a place you display the errors
echo implode( <br /> , $errors);
问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签