Jump to content

Setting a blank form flag!??! and if results are not found!?


suess0r

Recommended Posts

OK,

i have pg1.php which has 3 dropdowns they can choose from with a button 'submit.' I have all of my queries running smoothly and correctly, i'm just having the following problems...

1. If they don't select anything and hit submit, it takes them to pg2.php - instead of displaying a message saying "Please select from atleast one of the following options" and not leaving the page.

2. If they do choose something and it runs the query and doesn't find anything, it doesn't say "Search Results not found..."
  ---i tried doing this if outside of my for loop
[quote]
if (mysql_num_rows > 0) {

  for ($i = 0; $i < mysql_num_rows($result_set); $i++)
  { -queries-}
} else {
echo 'Search Results not found...';
[/quote]
*but unfortunately this kept returning Search Results not found... no matter what.*

hopefully someone can shed some light on these minor 2 problems. thanks!! 

-Someone had suggested something like this, but I'm POSTing the variables to a second page, so there's no way for me to check if isset() without going to the other page is there??-

[quote]
<?php

$errMsg = "";

//get infor from dropdown

if(!empty($_POST['mydropdown'])) {
  $value1 = $_POST['mydropdown];
} else {
  $errMsg .= "You forgot to select an option";
}

if($errMsg == "") {
  // No errors continue to page 2
} else {
  // There were errors display them:
  echo $errMsg;
}

?>[/quote]
first problem... don't you have to use a result code with mysql_num_rows? like mysql_num_rows($result) ???

The second problem would javascript form validation -- I'll dig on the site and post a tutorial if I find one.

[b]here we go[/b] http://www.phpfreaks.com/quickcode/JavaScript-Simple-Form-Validation-Script/276.php
OK, i do use a result code in my for loop and i have no problem running a query to get my results... it's just when there is no results i want to say "Sorry, no results found.." instead of just being an empty table. thanks for the help
[quote]if (mysql_num_rows > 0) {

  for ($i = 0; $i < mysql_num_rows($result_set); $i++)
  { -queries-}
} else {
echo 'Search Results not found...';[/quote]

You've got the gist of it, but the first line of code there doesn't specify a result -- I'm thinking it will be permanently false (in fact I'm surprised there isn't a parse error).

Archived

This topic is now archived and is closed to further replies.

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