Jump to content

getting passed my valaidation


Danny620

Recommended Posts

why is it that when enter something in my text box it does not vailidate it and it gets passed

 

<?php 
require_once('access/mysqli_connect.php');

//Function val validates form submissions by;
//Striping html tags from from;
//Must be greater than three letters long;

function val($field = false){
			global $dbc;
			$errors = false;

		if(strlen($field) > 3 && strlen($field) < 15){

		strip_tags($field);
		trim($field);
		htmlentities($field);
		$username = $field;
		$username = mysqli_real_escape_string($dbc,$username);
	    echo $username;

		} else { 

		$errors = "The field must be at least 3 characters long & no more than 15 characters!";

	  }

		if($errors){

	return $errors; }

		}

	//END of val function;
?>

 

heres the code for the form

 

<?php include('val.php');?>
<?php 
	if(isset($_POST['sub'])){
	$user = $_POST['username'];
    $suser = val($user);
				}
?>

<form name="form1" method="post" action="">
  <label>
  <input name="username" type="text" id="username" value="<?php if (isset($suser)){ echo $suser; } ?>">
  </label>
  <p>
    <input name="sub" type="hidden" id="sub" value="TRUE">
  </p>
  <p>
    <label>
    <input type="submit" name="send" id="send" value="send">
    </label>
</p>
</form>

Link to comment
https://forums.phpfreaks.com/topic/165814-getting-passed-my-valaidation/
Share on other sites

function val($field = false) {
    global $dbc;
    $errors = false;
    
    $strlen = strlen($field);
    if($strlen > 3 && $strlen < 15) {
        $field = strip_tags($field);
        $field = trim($field);
        $field = htmlentities($field);
        $username = $field;
        $username = mysqli_real_escape_string($dbc,$username);
        echo $username;
    } else { 
        $errors = "The field must be at least 3 characters long & no more than 15 characters!";
    }
    
    if($errors) {
        return $errors;
    }
}

 

Try this and behold the magic of proper indentiation.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.