Jump to content

substr() Whats wrong?


SharkBait

Recommended Posts

This is the block of code that deals with a $_POST;
[code]
<?php
foreach($_POST['sn'] as $sn) {
$sn = mysql_real_escape_string(trim($sn));
$pre = substr(strtolower($sn),0,3);
if ($pre != "tr-") {
echo "{$pre} <br />";
$errMsg .= "<li>The Serial Number must follow the TR- scheme.</li>";
break;
} else {
echo "AGHHFDF";
}
if ($sn <> "") {
$strqry = "SELECT * FROM rebates WHERE sn = '{$sn}'";
$query = mysql_query($strqry) or die("MySQL Error: Aborting Query");
$found = mysql_num_rows($query);
if($found > 0) {
$FOUNDSN[$b] = $sn;
$SNFAILED = true;
} else {
$FOUNDSN[$b] = "";
}

$i++;
} else {
$FOUNDSN[$b] = "";
}
$b++;
}
?>
[/code]

Now it never echos the 'Pre is {$pre}' but it does assign [code=php:0] $errMsg .= "<li>The Serial.....</li>";[/code]

It does echo the AGHHFDF so I am completely confused as to what is happening.  Does it have to do with the break; I have?  I want the foreach loop to stop on this if statement.
Link to comment
https://forums.phpfreaks.com/topic/21330-substr-whats-wrong/#findComment-95520
Share on other sites

I used [code=php:0]echo gettype($sn);[/code] and it returned as a boolean type (which is what php.net says about substr()))

So in the above code, am I really compairing a boolean to a string? Or am I right to think that its compairing a boolean to the integer value of "tr-" ?

Am I comparing strings in an incorrect way???
Link to comment
https://forums.phpfreaks.com/topic/21330-substr-whats-wrong/#findComment-95606
Share on other sites

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.