Forum Moderators: coopster
<input type = "text" name = "something" value = "<? php echo" $ var ";?>" size = "50" maxlength = "50" class = "clx">
<?php
if ($_POST[something] <= 6) {
if (account_namevalid($_POST['something'])) {
$db = new mysqli('x', 'x', 'x', 'x');
$db -> query("SET NAMES 'latin2'");
$stmt = $db->stmt_init();
if($stmt->prepare("UPDATE `database` SET `table1` = ? WHERE `something` = ? AND `something` = ?")) {
$stmt->bind_param('sis', $a,$b,$c);
$a = "$var1";
$b = "$var2";
$c = "$var3";
$stmt->execute();
if ($stmt) {
$stmt->close();
$db->close();
header("Location: ../allok.php?id=".$id."");
exit();
} else {
printf("<p>Error message</p><br /><p> %s\n", $db->error);
$stmt->close();
$db->close();
}}}}
function account_namevalid() {
// Must be minimum = 1
if (strspn($_POST['something'],"a±bcædeêfghijkl³mnñoópqrs¶tuvwxyz¼¿A¡BCÆDEÊFGHIJKL£MNÑOÓPQRS¦TUVWXYZ¬¯01234567890-/ ") == 0) {
header("Location: ../myscript2.php?id=".$id."");
return false;
exit();
}
// Check insert data
if (strspn($_POST['something'],"a±bcædeêfghijkl³mnñoópqrs¶tuvwxyz¼¿A¡BCÆDEÊFGHIJKL£MNÑOÓPQRS¦TUVWXYZ¬¯01234567890-/ ") != strlen($_POST['something'])) {
header("Location: ../myscript2.php?id=".$id."");
return false;
exit();
}
return true;
}
header("Location: ../test.php");
exit();
?>
function account_namevalid($val,$compstring,$len) { // note the parameters
// Must be minimum = 1
$ok=true;
if (
($val > 6) or
(strspn($val,"$compstring") == 0) or
(strspn($val,"$compstring") != strlen($val)
) {
$ok=false;
}
return $ok;
}
First, the variable "$id" is not going to be available within the function unless you declare it as a global. Which is not a "good use" of functions.
(Also I'm a bit confused, it's saying the value is less than or equal to 6, but your function checks for length 0 and strlen <= 6 . . .huh?)
That should be part of your function, like so.
$comp = 'a±bcædeêfghijkl³mnñoópqrs¶tuvwxyz¼¿A¡BCÆDEÊFGHIJKL£MNÑOÓPQRS¦TUVWXYZ¬¯01234567890-/ ';
if (strspn($_POST['something'],"a±bcædeêfghijkl³mnñoópqrs¶tuvwxyz¼¿A¡BCÆDEÊFGHIJKL£MNÑOÓPQRS¦TUVWXYZ¬¯01234567890-/ ") == 0) {
$my_var = mysql_real_escape_string($_POST['something']);
print_r ($my_var);
exit();
}
if (strspn($_POST['something'],"a±bcædeêfghijkl³mnñoópqrs¶tuvwxyz¼¿A¡BCÆDEÊFGHIJKL£MNÑOÓPQRS¦TUVWXYZ¬¯01234567890-/ ") != strlen($_POST['something'])) {
$my_var= mysql_real_escape_string($_POST['something']);
print_r ($my_var);
exit();
}
return true;
}
Can you show me example.
Ok, but what is $comp, what is $compstring, what is $len ?