Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
The code below executed and ran without any notices, warnings or errors of any sort. It did make for some interesting behavior though. The if statement evaluated to true every time, regardless of whether or not they matched. Notes added and non relevent code has been removed.
switch ($_POST['Action']) {
case 'blah':
break;
case 'blah2':
while ($Data = $Database->fetchRow) {
if ($_POST['FieldName'] == $Data['Field']) // missing an opening {
$Status['Error'] = true;
$Status['Message'] = 'A database field by that name already exists.';
break 2;
}
// missing a closing }
break;
}
Last edited by Benjamin on Fri Jul 14, 2006 5:26 am, edited 1 time in total.
Yeah they were both strings and they didn't match. It also either didn't set $Status['Error'], or it changed it's value to false. $Status['Message'] was set to the error message though.
switch ($_POST['Action']) {
case 'blah':
break;
case 'blah2':
while ($Data = $Database->fetchRow) {
if ($_POST['FieldName'] == $Data['Field']) {
$Status['Error'] = true;
}
$Status['Message'] = 'A database field by that name already exists.';
break 2;
}
break;
}
switch ($_POST['Action']) {
case 'blah':
break;
case 'blah2':
while ($Data = $Database->fetchRow) {
if ($_POST['FieldName'] == $Data['Field']) {
$Status['Error'] = true;
}
$Status['Message'] = 'A database field by that name already exists.';
break 2;
}
break;
}
if(strcmp($_POST['FieldName'], $Data['Field']) == 0) {
$Status['Error'] = true;
}
$Status['Message'] = 'A database field by that name already exists.';
I wouldn't trust PHP or any language to judge the similarities of Strings based on a single '==' comparsions. I would try the function instead and if it still doesn't work, I will stick a fork in my eye and post the pictures.
I have read that '===' may also work.
Last edited by santosj on Fri Jul 14, 2006 1:12 pm, edited 1 time in total.
Did you echo the strings within the function to make sure that what you were seeing was what the function was seeing? If they are the same in the database but something goes wonkiy in the app, there is a chance that the function could see if(1 == 1) or something silly like that.