Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
validate using true false
Old 03-28-2009, 06:10 AM validate using true false
jd57's Avatar
Average Talker

Posts: 16
Name: Joe
Location: Italy
Trades: 0
Hi everyone
This is the first time I'm posting in this group, I hope someone can help me.
I would like to use one of mysql field ("approve") and have it validated using
true or false code.
the field (approve) default is false, therefore I would like to add a string of text "Registration Pending" and end the script.
if the field is true, then it goes and display all other data.
I hope I have explained myself well enough for you to help me



PHP Code:
<?PHP
$link 
mysql_connect('localhost''xxxxx, 'jdxxxx');
if (!$link) {   die('
Could not connect' . mysql_error()); }
mysql_select_db('
xxxx');
// Fetch total number of records
$result = mysql_query("SELECT COUNT(*) AS recordCount FROM ihsreg");
$row = mysql_fetch_assoc($result);
$recordCount = $row['
recordCount'];

// Perform Search
$results = array();
if(isset($_REQUEST['
search'])){
 
 $limit = 20;
 if($_GET['
offset']){ $offset = $_GET['offset']; } else { $offset = 0; }
 $SQL = "SELECT * FROM ihsreg ";
 //$term = strtoupper(addslashes($_REQUEST['
search']));
 $term = strtoupper($_REQUEST['
search']);
 if(stristr($term,"'") && !stristr(
$term,"\'")){
  $term = addslashes($term);
 }
 if($_REQUEST['
radiobutton']){
  switch($_REQUEST['
radiobutton']){
  case '
1': $SQL.=" WHERE Bloom_Name LIKE \"$term\""; break;
  case '
2': $SQL.=" WHERE Pod_Name LIKE \"$term\""; break;
  case '
3': $SQL.=" WHERE Pollen_Name LIKE \"$term\""; break;
  case '
4': $SQL.=" WHERE Hybridiser LIKE \"$term\""; break;
  case '
5': $SQL.=" WHERE Origin LIKE \"$term\""; break;
  case '
6': $SQL.=" WHERE Grower LIKE \"$term\""; break;
  case '
7': $SQL.=" WHERE Color_Group LIKE \"$term\""; break;
  case '
8': $SQL.=" WHERE Bloom_Type LIKE \"$term\""; break;
  case '
9': $SQL.=" WHERE Reg_Mini LIKE \"$term\""; break;
  case '
10': $SQL.=" WHERE Size_Range LIKE \"$term\""; break;
  case '
11': $SQL.=" WHERE Propagation LIKE \"$term\""; break;
  case '
12': $SQL.=" WHERE Bloom_Color LIKE \"$term\""; break;
  case '
13': $SQL.=" WHERE Bloom_Characteristics LIKE \"$term\""; break;
  case '
14': $SQL.=" WHERE Leaf_Characteristics LIKE \"$term\""; break;
  case '
15': $SQL.=" WHERE Bush_Characteristics LIKE \"$term\""; break;
  case '
24': $SQL.=" WHERE Cross_Made LIKE \"$term\""; break;
                default: $SQL.=" WHERE Bloom_Name LIKE \"$term\""; break;
  } // switch
 } else {
  // If they didnt' 
select a radio button... 
  
$SQL.=" WHERE Bloom_Name LIKE \"$term\"";
 }
 
$result mysql_query($SQL);
 
$resultCount mysql_num_rows($result);
 
 
$SQL.= " LIMIT $offset$limit";
 
$result mysql_query($SQL);
 
 if(
$resultCount 0){
  while(
$row mysql_fetch_assoc($result)){
   
$results[$row['id']] = $row;
  } 
// while
 
// if there are results
// if user performed a search
?>
jd57 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-28-2009, 07:45 AM Re: validate using true false
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Hello Jd, and welcome to wmt.
This can be done easily.
But, as mysql doesn't provide a boolen type, we usually use a smallint with value 0 for false, and 1 for true (at least, I did)

Simply add an
PHP Code:
if($row['approved']==0){
  
//display the error

while you parse your query result.

PHP Code:
<?PHP
$link 
mysql_connect('localhost''xxxxx''jdxxxx');
if (!
$link) {   die('Could not connect: ' mysql_error()); }
mysql_select_db('xxxx');
// Fetch total number of records
$result mysql_query("SELECT COUNT(*) AS recordCount FROM ihsreg");
$row mysql_fetch_assoc($result);
$recordCount $row['recordCount'];

// Perform Search
$results = array();
if(isset(
$_REQUEST['search'])){
 
 
$limit 20;
 
//if($_GET['offset']){ $offset = $_GET['offset']; } else { $offset = 0; }
 //You can replace the above with a ternary operator
 
$offset=(isset($_GET['offset']))?$_GET['offset']:0;
  
 
$SQL "SELECT * FROM ihsreg ";
 
//$term = strtoupper(addslashes($_REQUEST['search']));
 
$term strtoupper($_REQUEST['search']);
 if(
stristr($term,"'") && !stristr($term,"'")){
  
$term addslashes($term);
 }
 if(
$_REQUEST['radiobutton']){
  switch(
$_REQUEST['radiobutton']){
  case 
'1'$SQL.=" WHERE Bloom_Name LIKE '$term'"; break;
  case 
'2'$SQL.=" WHERE Pod_Name LIKE '$term'"; break;
  case 
'3'$SQL.=" WHERE Pollen_Name LIKE '$term'"; break;
  case 
'4'$SQL.=" WHERE Hybridiser LIKE '$term'"; break;
  case 
'5'$SQL.=" WHERE Origin LIKE '$term'"; break;
  case 
'6'$SQL.=" WHERE Grower LIKE '$term'"; break;
  case 
'7'$SQL.=" WHERE Color_Group LIKE '$term'"; break;
  case 
'8'$SQL.=" WHERE Bloom_Type LIKE '$term'"; break;
  case 
'9'$SQL.=" WHERE Reg_Mini LIKE '$term'"; break;
  case 
'10'$SQL.=" WHERE Size_Range LIKE '$term'"; break;
  case 
'11'$SQL.=" WHERE Propagation LIKE '$term'"; break;
  case 
'12'$SQL.=" WHERE Bloom_Color LIKE '$term'"; break;
  case 
'13'$SQL.=" WHERE Bloom_Characteristics LIKE '$term'"; break;
  case 
'14'$SQL.=" WHERE Leaf_Characteristics LIKE '$term'"; break;
  case 
'15'$SQL.=" WHERE Bush_Characteristics LIKE '$term'"; break;
  case 
'24'$SQL.=" WHERE Cross_Made LIKE '$term'"; break;
                default: 
$SQL.=" WHERE Bloom_Name LIKE '$term'"; break;
  } 
// switch
 
} else {
  
// If they didnt' select a radio button... 
  
$SQL.=" WHERE Bloom_Name LIKE '$term'";
 }
 
$result mysql_query($SQL);
 
$resultCount mysql_num_rows($result);
 
 
$SQL.= " LIMIT $offset$limit";
 
$result mysql_query($SQL);

 
$error=null;
 
$results=array(); //empty resultset
 
 
if($resultCount 0){
  while(
$row mysql_fetch_assoc($result)){
    if(
$row['approve']==0){
      
$error="You have not approved something";
    }
    else{
      
$results[$row['id']] = $row;
    }
  } 
// while
 
// if there are results
// if user performed a search
  
//display the error if it differs from the default (null)
if($error!==null){
  echo 
$error;
{
?>
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 03-28-2009 at 07:49 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 03-28-2009, 09:35 AM Re: validate using true false
jd57's Avatar
Average Talker

Posts: 16
Name: Joe
Location: Italy
Trades: 0
Hi Tripy
I get the following error

Parse error: syntax error, unexpected $end in /home1/internb7/public_html/SEindex2.php on line 785
jd57 is offline
Reply With Quote
View Public Profile
 
Old 03-28-2009, 11:26 AM Re: validate using true false
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
**** netbook keys, too small
replace
PHP Code:
{
?> 
with
PHP Code:
}
?> 
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 03-28-2009, 01:27 PM Re: validate using true false
jd57's Avatar
Average Talker

Posts: 16
Name: Joe
Location: Italy
Trades: 0
Hi Tripy

the error is gone so we you got that fix, but I'm having a problem when the code is true, it should show me a table with images. Can you please help
jd57 is offline
Reply With Quote
View Public Profile
 
Old 03-28-2009, 02:40 PM Re: validate using true false
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Not with what you showed us.
And in that case, the problem is not in the test, but in the way you have implemented the exception.

If you cannot get paste it, paste your script here, and I'll explain you what you should do.
But I'm no freelancer. I won't go further than what I already did, and I'll just give you pointer to understand what need to be corrected.

I'm all for education, you see. Give a man a fish, you feed him for a day, teach him fishing, and you'll feed him for years.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 03-28-2009, 02:45 PM Re: validate using true false
jd57's Avatar
Average Talker

Posts: 16
Name: Joe
Location: Italy
Trades: 0
thanks! sorry to take away precious time from you
jd57 is offline
Reply With Quote
View Public Profile
 
Old 03-28-2009, 02:54 PM Re: validate using true false
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
sorry to take away precious time from you
No, that's not the point...
I'm happy spending time here helping and coaching peoples, I won't stay otherwise.

Just, like for my daughter, I prefer to explain what is to be done and help her doing it rather than doing it completely for her.
She won't ever learn anything if I do everything for her.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to validate using true false
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.27338 seconds with 12 queries