Connecting Tech Pros Worldwide Help | Site Map

Return value of 1 instead of -1

Newbie
 
Join Date: Nov 2007
Posts: 1
#1: Nov 7 '07
How can i get a return value of 1 if the user exists in the table instead of it returning a -1?

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require("config.php");
  3. if($_GET['action'] == 'post')
  4. {
  5.    if(empty($_POST['Employee_ID']) || empty($_POST['Date']) || empty($_POST['Activity']) || empty($_POST['Miles']))
  6.     {
  7.       //if everything is not filled in than prints out error message
  8.       error("blank");
  9.       exit;
  10.       }
  11.       if(!empty($_POST['Employee_ID']))
  12.       {
  13.        $query="SELECT Employee_ID FROM analyzer_query WHERE Employee_ID = '{$_POST['Employee_ID']}'";
  14.        $rs = $conn->execute($query);
  15.        $num_columns = $rs->RecordCount();
  16.        echo $num_columns . "<br>";
  17.                     if($num_columns <= 0)
  18.                         {
  19.                           echo error ("user");
  20.                           exit;
  21.                         }
  22.                         else
  23.                         {
  24.                         $conn->execute("INSERT INTO Activity_Log (`Employee_ID`, `Date`, `Activity`, `Miles`) VALUES ('{$_POST['Employee_ID']}', '{$_POST['Date']}', '{$_POST['Activity']}', '{$_POST['Miles']}')");
  25.                         header("Location: success.php?action=success");
  26.                         }
  27.  }
  28. }
  29. function error($error)
  30. {
  31.    //if error is equal to blank
  32.    if($error == 'blank')
  33.       {
  34.       echo "Please fill in all the required fields before submitting";
  35.       }
  36.  //if error is equal to blank
  37.    if($error == 'user')
  38.       {
  39.       echo "Please fill in the correct Employee ID";
  40.       }
  41. }
  42. ?>
here is my config.php file
Expand|Select|Wrap|Line Numbers
  1. <?php  $conn = new COM ("ADODB.Connection") or die("Cannot start ADO");
  2. $connStr = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=F:\Wellness Program\Copy of HR Employee Wellness Program.mdb;";
  3. $conn->open($connStr); //Open the connection to the database
  4. ?>
  5.  
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,741
#2: Nov 10 '07

re: Return value of 1 instead of -1


Hi. Welcome to TSDN!

I assume this has something to do with the $rs->RecordCount() method?
Please explain a little better what you are talking about.

You could of course always simply change the value:
Expand|Select|Wrap|Line Numbers
  1. if($value == -1) $value = 1;
  2.  
Newbie
 
Join Date: Nov 2007
Posts: 4
#3: Nov 10 '07

re: Return value of 1 instead of -1


Or you can get the absolute value:

[PHP]$value = abs($value);[/PHP]
Reply