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