Jump to content

Help on if/else Statements


Sam Laundon
 Share

This topic is 5753 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I have gotten the statement below to work:

<?php

if ($searchResult['foundCount']==1)

{

}else{

echo "There was no match for the email address your entered. Press the back button and try again or

call Us at 000-000-0000" ;

}

?>

It follows the beginning php code (<?php) at the start of the page before .

I would like to be able to format the response in html (There was no match...), but don't know how to format or place the above statement within the

.

Thanks in advance for your help - Sam

Link to comment
Share on other sites

Try this:

$message = "There was no match for the email address your entered.

Press the back button and try again or

call Us at 000-000-0000" ;

then in the html...

<? echo $message; ?>

Another option would be to set a flag:

<?php

$flag = 0;

if ($searchResult['foundCount']==1)

{

}else{

$flag = 1 ;

}

?>

then in your html:

<? if(flag==1) { ?>

no records found blah blah blah

call us... blah blah

etc

<? } ?>

Link to comment
Share on other sites

Thanks to Garry and Mindal,

Garry's solution is the one that came close to working, but when there is a $message = True, the page just displays the number "1".

Mindal's two solution either gave me blank page or the the text showed, but was not formated.

What could I be doing wrong? I copied and pasted the code into my php document with the first string of code placed above the head and the second string of code placed in the body.

Thanks again - Sam

Link to comment
Share on other sites

both our codes would need some fine tuning to make it specifically work for your solution.

The best method is to set the flag (either use true / false or a number).

copy the code as you have it and post it and if either Gary or I get time, I am sure we can make the few edits to help you out.

Link to comment
Share on other sites

Mindal,

I have included the code below. When the FoundCount==1 the page displays correctly. When the FoundCount==0 I get a blank page.

<?php

include_once('FX/FX.php');

include_once('FX/FMErrors.php');

include_once('FX/server_data.php');

$email=$_POST['email'];

$groupSize='1';

$search=new FX($serverIP,$webCompanionPort,'FMPro7');

$search->SetDBData('XXX.fp7','php',$groupSize);

$search->SetDBPassword('XXX','XXX');

$search->AddDBParam('email',$email);

$searchResult=$search->FMFind();

?>

<?php

$flag = 0;

if ($searchResult['foundCount']==1)

{

}else{

$flag = 1 ;

}

?>

<?php

foreach($searchResult['data'] as $key=>$searchData){

?>

Email User Id and Password

<? if(flag==1) { ?>logo.gif

There was no match for the email address your entered.

Press the back button and try again or call Us at 000-000-000. <? } ?>

Thanks agin - Sam

Edited by Guest
Link to comment
Share on other sites

Hi Garry,

I copied and pasted your code into my document, but I still come up with a blank page when there is no match. When there is a match then I get the information that is suppose to be there.

Maybe the problem is on the page that the query is being submitted from. I discovered in FileMaker that and email address cannot be searched without double equal signs ==. So the text entry field has "==" already in the box. This is probably not a very elegant way of making sure there is a match. I know there is a way of doing this on the the page the form is being submitted to, but have not gotten it to work. The search field is "email". Could this be causing the problem in getting the result page to display properly depending on if there was a match or not?

Thanks - Sam

Link to comment
Share on other sites

FoundCount = <? echo $searchResult['foundCount']?>

<? if($flag==1) { ?>

logo.gif

There was no match for the email address your entered.

Press the back button and try again or call Us at 000-000-000.

<? } ?>

This text is here to prove we don't get a blank page.

Link to comment
Share on other sites

<?php if($flag==1) { ?>

logo.gif

There was no match for the email address your entered.

Press the back button and try again or call Us at 000-000-000.

<?php }

else {

foreach($searchResult['data'] as $key=>$searchData) {

?>

<?php }; };?>

logo.gif

<?php

}

?>

<?php echo $searchData['web_title'][0]; ?> here is your email Information.

<?php echo $searchData['email'][0]; ?>

Link to comment
Share on other sites

Interesting about the '==' is that I search for email addresses in filemaker and do not need to use it.

My code that I posted should work. To test it out, change only the database information in the PHP at the top and try it and see.

I am also want to see what code you are using on the form that sends information to this page.

On the page you just posted there are a few errors.

Since you only want to find 1 record, you do not need to loop your foreach statement (ie drop the '{ }')

There are also some useful error checking codes you could insert to try and track where your data is going.

echo $searchResult['errorCode'];

And my favourite:

print "

-";

print_r($searchData);

print "-

";

I want to see this work and you are probably not that far away from getting this solved.

Link to comment
Share on other sites

oops,

I forgot one valuable piece of information that I recall when I needed to do this. The '@' symbol is problems and the best way around it is to enclose the $email inside double quotes.

insert this code below $groupSize=1;

$email = '"'.$email.'"';

I have tested this on my databases and it works.

Link to comment
Share on other sites

If you get blank pages then there is some error that has crept in.

like I said the pages I sent you (with the addition of the $email = '"'.$email.'"';) work excellent on my system. I have a similar need to search for email addresses for clients that forget their userid.

I guess go with what works - but there may be something wrong with your configuration.

Good luck.

Link to comment
Share on other sites

This topic is 5753 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.