Jump to content

If /else Statement


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

Recommended Posts

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]

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This topic is 6985 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
×
×
  • Create New...

Important Information

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