Jump to content

Recommended Posts

im trying to create a clean_data function...just want to strip it of tags and trim the spaces of the end...heres the display

 

<html>
<body>
<form action='hhh.php' method='POST'>

<?PHP
include("caneck.inc");
include("cleandata.php");
?>
Email Address<input type="text" name="email" 
                      value="<?php echo @$email ?>" 
                      size="50" maxlength="50"><br>	


<input type="submit" name="do" value="Submit">
</form>
</body>
</html>

 

heres what i want the form to do using the function. just echo the data on the page cleaned to make sure its working

 

<?php
include("caneck.inc");
include("cleandata.php");

$clean = clean_data($_POST['email']);

echo $clean;

?>

 

and heres the functions include file

<?php
include("caneck.inc");

function clean_data($variable)
{
include("caneck.inc");
$cxn = mysqli_connect($host,$user,$passwd,$dbname)
         or die("Couldn't connect"); 
mysqli_escape_string($cxn, strip_tags($variable));
}


function clean_post($string)
{
  $tring = trim($string);
  
  $cxn = mysqli_connect($host, $user,$passwd,$dbname) 
            or die ("Couldn't connect to server.");
mysqli_real_escape_string($cxn, strip_tags($tring));
}

?> 

 

right now it displays nothing, i tried putting single quotes around $clean but it just displayed the literal characters $clean like i expected...anyone catch what im not doing right? thanks

Link to comment
https://forums.phpfreaks.com/topic/151167-solved-help-with-creating-a-function/
Share on other sites

    A few things:
    • You were missing a 's' in $string for the clean_post() function...
    • Why are you including "caneck.inc" twice?
    • Why are you connecting to a database to sanatize a string?
    • Use "mysqli_real_escape_string" instead.

     

    Try:

     

    include("caneck.inc");
    
    function clean_data($variable)
    {
       $cxn = mysqli_connect($host,$user,$passwd,$dbname) or die("Couldn't connect"); 
       return mysqli_real_escape_string($cxn, strip_tags($variable));
    }
    
    function clean_post($string)
    {
       return strip_tags(trim(($string))); 
    } 
    ?> 

if you don't select any thing from the list, why it is not showing any message, like "please choose one from the list"

 

You are correct, that is a required parameter.  I was referring to the clean_post() function not the clean_data() function  ;)

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.