No announcement yet.

Redirecting a form

  • Filter
  • Time
  • Show
Clear All
new posts

  • Redirecting a form

    Why is this code not working?
    If I put in a userid that has an email it gets redirected to grid_yard. If I put in a userid that doesn't have a email I get a Record Not Found message rather than being redirected to form_profile.

    * Check for an existing record

    // SQL statement parameters
    $check_table = 'Profile'; // Table name
    $check_where = "Email <> '' "; // Where clause

    // Check for record
    $check_sql = 'SELECT *'
    . ' FROM ' . $check_table
    . ' WHERE ' . $check_where;
    sc_select(dataset, $check_sql);

    if (false == {dataset})
    // Error while accessing database

    elseif ({dataset}->EOF)
    // No record found
    // Record found

  • #2
    Some notes:

    1. Use if (false === {dataset}) instead (3 equal signs). In PHP you need to compare the datatype too. Let me explain it with an example:

    PHP Code:
    $foo = []; // empty array
    ($foo == false// This is true, cause the array is empty
    ($foo === false// This is false, because you are comparing that $foo should be a boolean (datatype), and should be false (value) 
    Read more about comparison operators in php docs.

    2. Also, {dataset}->EOF is a helper function to know if you have reach the dataset's registers. In you code this carry unexpected results from empty datasets. I do prefer using sc_lookup instead of sc_select.
    3. I know that ScriptCase macro's example is telling you to use vars to build your sql query, but in your code looks so unnecessary.

    Try this code:
    PHP Code:
    // sql query
    $sql "SELECT * FROM Profile WHERE Email <> ''";

    // trigger the sql

    if (
    false === {dataset}){
    // Error while accessing database
    else if ( isset({
    dataset[0][0]}) ){
    // Record found
    // No record found

    Last edited by manfred; 04-15-2016, 11:39 AM.


    • #3
      I used your code and I still get No Record Found. If it finds the record is does sc_redir(grid_yard); but if no record found I get the message rather than redir(form_Profile);

      I ma putting the code in the onApplicationInt Event. Is that the correct Event?
      Last edited by gehrenfeld; 04-15-2016, 12:14 PM.


      • #4
        do exists profiles with empty email in you db? could you verify it? And yes, onApplicationInt is a good place to do this validation.


        • #5
          Yes I have records that do not have emails and some that do.