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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.