dadamssg Posted March 26, 2009 Share Posted March 26, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/151167-solved-help-with-creating-a-function/ Share on other sites More sharing options...
aseaofflames Posted March 26, 2009 Share Posted March 26, 2009 your function doesn't return any values Quote Link to comment https://forums.phpfreaks.com/topic/151167-solved-help-with-creating-a-function/#findComment-794119 Share on other sites More sharing options...
dadamssg Posted March 26, 2009 Author Share Posted March 26, 2009 how do i fix that? im not real familiar with creating functions :-\ Quote Link to comment https://forums.phpfreaks.com/topic/151167-solved-help-with-creating-a-function/#findComment-794120 Share on other sites More sharing options...
Maq Posted March 26, 2009 Share Posted March 26, 2009 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))); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/151167-solved-help-with-creating-a-function/#findComment-794127 Share on other sites More sharing options...
dadamssg Posted March 26, 2009 Author Share Posted March 26, 2009 hey thanks that worked! for whatever reason it wouldn't include that file if it wasn't included inside the brackets...no clue why. i thought you had to connect to the db in mysqli_real_escape_string? hence the $cxn in it. Quote Link to comment https://forums.phpfreaks.com/topic/151167-solved-help-with-creating-a-function/#findComment-794134 Share on other sites More sharing options...
Maq Posted March 26, 2009 Share Posted March 26, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/151167-solved-help-with-creating-a-function/#findComment-794145 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.