Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

If /else Statement

Featured Replies

Hi,

I am new at PHP, I am having a problem to bring the error message to my page if in case no record were found during the search, but for some reason the message is not showing up at the page. Does anyone have any idea what is missing at the code?

here are the code I am having at the page:

index.php

---------

 



<form action="summer_result.php" method="post" >

<input name="title" type="text"  size="24" border="0">

<input name="author" type="text"  size="24" border="0">

<input type="text" name="school" size="24" border="0">

<input name="submit" type="submit" value="SEARCH" border="0">

</form>

 
 





-------------

summer_result.php

 


 



<?PHP

include_once($HTTP_SERVER_VARS['DOCUMENT_ROOT'] . "/FX/FX.php");

include_once($HTTP_SERVER_VARS['DOCUMENT_ROOT'] . "/FX/server_data.php");

include_once($HTTP_SERVER_VARS['DOCUMENT_ROOT'] . "/FX/FMErrors.php");



$search_result = new FX($serverIP,$webCompanionPort);



$title = $_POST[title];

$author = $_POST[author];

$school = $_POST[school];



$search_result->SetDBData('Summer Reading.fp7','Form');

$search_result->SetDBPassword('passfree','Admin');



$search_result->AddDBParam("title","$title");

$search_result->AddDBParam("author","$author");

$search_result->AddDBParam("school","$school");



$result = $search_result->FMFind();   

?>



<body>



<?php if ($result['foundCount'] == 0) { ?>



   Sorry, no matches for your request



<?php } else { ?>



<?php

foreach ($result['data'] as $recordKey => $returnedData)

 { ?>



<?php echo $returnedData['title'][0]; ?>

<?php echo $returnedData['author'][0]; ?>

<?php echo $returnedData['school'][0]; ?>

<?php } ?>

<?php } ?>

 </body>

 

----------

thank you,

:confused:

[email protected]

You could add this line for testing:

echo $result['foundCount'];

Does the rest of the page display ok when records are found?

Good Luck.

Garry

  • Author

Hi Gary,

thank you in try to help me.

Yes, I did tried to use the <?php echo $result['foundCount']; and it showed the number of records I have at the database, but my problem is with the if/else statement which is not bringing me the message "Sorry, no matches for your request" when I do not enter any information at the search box or enter something not at the database to do the search.

Any idea what am I doing wrong?

thank you,

:confused:

[email protected]

when you enter no data into your search, the found count will be all records.

You need to have a Javascript FormValidator on your form page, which can check to see if the required fields have data.

Then in your result page:

if($title=='' && $author=='' && $school=='') {$error=1; }

if($error==1) {

echo "you have entered no search";

}

What I do is if the error = 1, I use the header command to send them back to the form page where I put the error statement to enter some data in the form and try again.

Good Luck

So, with this line:

echo $result['foundCount'];

What displays when:

1. No values are entered by the user (is it the number of all records), hence test with Javascript (as mlindal suggested) or PHP for empty values?

2. Wrong values are entered (is it 0, -1 or something else)?

All the best.

Garry

Create an account or sign in to comment

Important Information

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.