Problem passing variable with mysql SELECT

7 posts by 2 authors in: Forums > CMS Builder
Last Post: February 2, 2015   (RSS)

Hi all,

I'm having a problem with the mysql SELECT not passing the variable I'm using.  Here's the code:

foreach ($scheduledRecords as $record){
    $readr = htmlencode($record['reader']);      
    $check = mysql_query("SELECT email, phone FROM cms_readers WHERE full_name = '" . mysql_real_escape_string($readr) . "'") or die(mysql_error());
      $check2 = mysql_num_rows($check);
      // if reader exists get email address
      if($check2 > 0){
          while($ifo = mysql_fetch_array( $check )){
          $r_em = $ifo['email'];
          $r_ph = $ifo['phone'];
        }
       }else{
            $r_em = '';
            $r_ph = '';
      }
}

$readr is the variable that is not accepted and is taken from another table.  If I put the actual reader name in, it finds the record ($check2 is > 0).  This same code works in other files but no matter how I try to duplicate it, it still will not pass the $readr variable.

Any ideas?

Please help to preserve my sanity!

Thanks in advance,

Eric

By claire - February 2, 2015

Hi Eric

The first thing that I'd suggest is adding a var_dump($readr) to the code just after the variable assignment, then run the code when it doesn't work. You'll need to establish exactly what's being inserted into the SQL statement.

You can also try var_dump(mysql_real_escape_string($readr)) if nothing obvious shows up in the first var_dump, just to see if something is being changed by the escape function.

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By claire - February 2, 2015

Hi Eric

This stuff is always a little tricky to debug. Can you check the source of the page when you do the var_dumps? It's possible that there's an extra character there that doesn't show up in the browser itself.

Is there a reason you need to use htmlencode there?

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Hi again Claire,

I was using the htmlencode because it's what is generated when I use the "Code Generator" in CMSB.  I subsequently have taken out that reference but alas, still no luck. BTW, the 'test' var subjects all have email and phone numbers...

I've attached the test file for you to look at that I've been using to try to narrow down what's happening.  Maybe another set of eyes (yours) can see what I'm sure I've been missing.

I forgot to mention in my info that I'm using version 2.63 (Build 1092) of CMSB; not sure that matters.

Again, thanks for your time!

Eric

Attachments:

testGetEmail.php 3K

By claire - February 2, 2015

I get the feeling that there's something else going on here - perhaps some wrong info is being saved to the database?

I think I'd like to get a closer look at this. Can you open a support ticket please? https://www.interactivetools.com/support/email_support_form.php

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Support ticket submitted...

Thanks again!