Solved

Basic echo from mysql query result

Posted on 2004-08-14
75
360 Views
Last Modified: 2013-11-18
What am I doing wrong:

This is a query string in the code looking for the ID,Email, and NickName to whom a message wil be sent within the system/app :

            $tmp_arr = db_arr("SELECT ID, NickName, Email FROM Profiles WHERE ID=".(int)$_POST[caff_id_to]);

 A little later in the code I am trying to change an echo/print from ID to NickName:

 Using the following, the ID echos fine:
           <td width=15%>&nbsp;<?php echo"<b>TO:$GET[ID]<b>"; ?>:&nbsp;</td><td width=85% align=left>&nbsp;

If I use the [NickName] instead, just a blank after TO::

            <td width=15%>&nbsp;<?php echo"<b>TO:$GET[NickName]<b>"; ?>:&nbsp;</td><td width=85% align=left>&nbsp;


Help?

0
Comment
Question by:Steve_Newbie
  • 42
  • 32
75 Comments
 
LVL 2

Expert Comment

by:afano
ID: 11803130
1) You need to have your code have quotes around non-variables
2) You need arrays outside of double quotes
3) Its not $GET but $_GET['whatever'] for stuff passed in via GET
4) assuming that db_arr is a function you are using correctly you probably need something like $tmp_arr['NickName']

So try
<?php echo"<b>TO:".$GET['NickName']."<b>"; ?>

<?php echo"<b>TO:".$_GET['NickName']."<b>"; ?>

<?php echo"<b>TO:".$tmp_arr['NickName']."<b>"; ?>


0
 

Author Comment

by:Steve_Newbie
ID: 11803196
Thanks, but still not working.  The 3rd point was my error.....it was $_GET all along.....
Tried the other options.  Do not work.  

?
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11803211
try something like...

$tmp_arr = db_arr("SELECT ID, NickName, Email FROM Profiles WHERE ID=".(int)$_POST[caff_id_to]);
list ($ID, $nick, $mail) = $tmp_arr;

then just use the variables $nick, etc... as you would normally
0
 

Author Comment

by:Steve_Newbie
ID: 11803241
Thanks. Tried that...still not  working...  Anything else in the setup that could be off?
0
 

Author Comment

by:Steve_Newbie
ID: 11803259
RE: the last suggestion, 'ID' stops working with that setup as well......

?
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11803275
Do you have console access o the database? Can you check the actual output of the database? and can you post the db_arr function? I'll have a little look see.

One I use which works is:

function getSettings($userid)
{
    $result = mysql_query("select * from boincsettings where userid='$userid'", getLink()) or cleanUp("MySQL Query Failed: ".mysql_error($link));

    if ($result) $row = mysql_fetch_row($result);

    mysql_free_result($result);

    if ($row)
        return $row;
    else
        return null;
}



(I also use the following functions for handling connections)

$link = null;

function getLink()
{
    global $link;

    if ($link != null) return $link;

    $server="localhost";
    $database="database";

    $username="username";
    $password="password";

    $link = mysql_connect($server, $username, $password) or cleanUp("Could not connect to MySQL server");
    mysql_select_db($database, $link) or cleanUp("Could not select database $database: ".mysql_error($link));

    return $link;
}

function closeLink()
{
    global $link;

    if ($link != null)
    {
        mysql_close($link);
        $link = null;
    }
}


Cleanup is my generic error handler
0
 

Author Comment

by:Steve_Newbie
ID: 11804529
Thanks.
Here is the function:

function db_arr( $query )
{
      global $BUG_REPORT_EMAIL;
      global $MySQL;

         $res = mysql_query( $query, $MySQL->link  );
         if ( !$res )
         {
          
            echo PrintErr( "Database access error" );
        mail( $BUG_REPORT_EMAIL, "Error", "Error in $_SERVER[PHP_SELF]: " . mysql_error() . "\nQuery: '$query'" );
            exit;      
    }
         $arr = mysql_fetch_array( $res );      
         return $arr;
}


A little stuck on the dbase output........don't normally work with that all that much in my newbie state of tweaking......

Steve
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11804934
Ok no worries...

Let's see what we can get out of this...

Ok you SHOULD get back:

array[
    "ID" => "someID",
    "Nick" => "someNick",
    "Email" =>  "someEmail"
]

Because you're rturning an associative array, list won't work as I suggested above.

Ok, 1st - check that the names of your gields in the MySQL Database match the case you're using in your code. ie id is not the same as ID
2nd - Before doing anything with it, print the output from your function so we can see what's in it:

print_r (db_arr("SELECT ID, NickName, Email FROM Profiles WHERE ID=".(int)$_POST[caff_id_to]));

which will tell us whether the error is in getting the info from the database or in processing the returned variable.

Also, check that there is some information in the database itself.
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11804955
Oh, do you have a version of phpMyAdmin/similar? Very very good for problems like this. - A web front-ennd to your database so you can "Click" and it generates the commands for your, as well as showing you the command it made.

also, try changing your query to:

intval ($_POST['caff_id_to'])

ie use intval instead of typecasting (int) and also add ' to the $_POST variable array
0
 

Author Comment

by:Steve_Newbie
ID: 11805072
IF I am doing this correctly, there is no output.  The dbase does contain the info requested and correct cases etc are used, and it is accessed from other code in the app just fine.  So......now what?  
0
 

Author Comment

by:Steve_Newbie
ID: 11805119
Get a parse error with :
                     $tmp_arr = db_arr("SELECT ID, NickName, Email FROM Profiles WHERE ID="intval($_POST['caff_id_to']);

Parse error: parse error, unexpected ';' in /home/domainx/public_html/compose.php on line 229

What am I not closing and/or screwing up in the syntax?
S
0
 

Author Comment

by:Steve_Newbie
ID: 11805174
BTW, yses, using phpmyadmin...for a variety of things but have not used it for that functionality yet..  
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11805346
sorry, you needed a . in there ie

WHERE ID=" . intval($_POST['caff_id_to']);
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11805353
I'm guessing that for some reason, the wring ID is being queried and is, therefore, returning 0 results, then all the variables will be blank. Try the code change and tell me what happens-
0
 

Author Comment

by:Steve_Newbie
ID: 11805495
still get a parse error:

Parse error: parse error, unexpected ';' in /home/naughtyl/public_html/compose.php on line 229

The strange thing about the wrong ID idea is that the ID that comes out of that......somehow.....is accessible and is called up correctly with $_GET[ID]  whereas the NickName is not.....

0
 

Author Comment

by:Steve_Newbie
ID: 11805507
OK, fixed the parse error.......added a  ")" to the end......but the return is still nothing.....

??
0
 

Author Comment

by:Steve_Newbie
ID: 11805548
I tried to just do a simple query printout...not sure if this helps or makes sense, but in response to :

print_r ($query="SELECT NickName FROM Profiles WHERE ID=".intval($_POST['caff_id_to']));


I got :

SELECT NickName FROM Profiles WHERE ID=0
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11805851
the $_GET[ID] is what is passed ot the script by the browser using the GET method (ie in the URL) wherease the $nickName is what you're generating in your script
The print_r is showing that the query is looking for ID 0 in the database. What is sending the variable caff_id_to to the script? is it being posted from a previous form?

I think we're getting confused over what is in each variable (at least I am!)

If you go to www.somewhere.com/script.php?ID=7654&test=1

then in script.php, $_GET['ID'] = 7654, etc...

If you have a form on your page that calls script.php and has a field alled ID

then in script.php, $_POST['ID'] = 7654, etc...

so $_GET and $_POST contain what is sent to your script from outside, before it starts.


What ID are you trying to search for in your database?
try changing your query to remove the $_POST completely - type the ID number into the query by hand and see what that returns.

Also, if you want to, post the complete script here (minus your username/password for the database) and I'll run a copy on my Database and see what I can get
0
 

Author Comment

by:Steve_Newbie
ID: 11806007
Yeah, afraid of that.  This app has a lot of different feeds from various files, gets confusing,...including a billing module which is what the "caiif" is all about (means contact anyone for free).    This is supposed to pull up IDs which are able to send and received messages(all are enabled at the moment).  That is all working as far as I can tell, since all other functionality is no impaired.  I will post the rest of the script here below the message.  It's long...hope no one gets upset.  

I would do waht your suggested via somewhere.com, but their site says that they are offline due to server fire.

S
<?


require_once( "inc/header.inc.php" );

require_once( "$dir[inc]db.inc.php" );

require_once( "$dir[inc]design.inc.php" );

require_once( "$dir[inc]profiles.inc.php" );



// --------------- page variables and login



$_page[name_index] = 19;



$logged[member] = member_auth(0);



$_page[header] = _t( "_COMPOSE_H" );

$_page[header_text] = _t( "_COMPOSE_H1" );



// --------------- page components



$_ni = $_page['name_index'];

$_page_cont[$_ni]['hot_list'] = "";

$_page_cont[$_ni]['block_list'] = "";

$_page_cont[$_ni]['kiss_list'] = "";

$_page_cont[$_ni]['view_list'] = "";

$_page_cont[$_ni]['contact_list'] = "";

$_page_cont[$_ni]['contact_free_list'] = "";

$_page_cont[$_ni]['inbox_content'] = "";

$_page_cont[$_ni]['compose_content'] = DesignBoxContent( $_page[header_text], $content_w, PageCompPageMainCode() );



$func = "MenuLoggedMemberCustom_$tmpl";

$func2 = "CustomMenuFuncCC_$tmpl";

$_page_cont[$_ni]['custom_menu'] = $func( $func2() );



// --------------- [END] page components



PageCode();



// --------------- page components functions



/**

 * page code function

 */

function PageCompPageMainCode()

{

    global $content_w;

    global $site;

      global $max_caff_day_messages;

    global $memb_arr;

    global $site;

    global $p_arr;

    global $error;

    global $max_l;

    global $member;

    global $is_caff_member;

    global $days_forall_caff;



      $days_forall_caff = getParam("days_forall_caff");

      $no_cart = getParam("no_cart");





      $member[ID] = $_COOKIE[memberID];

      $member[Password] = $_COOKIE[memberPassword];
      




      $max_caff_day_messages      = GetParam("max_caff_day_messages");

      $caff_arr = db_arr("SELECT ((ExtraAddons+0)&2) as is_caff FROM Profiles WHERE ID = $member[ID]");



      

      $is_caff_member = ( $caff_arr[is_caff] || $days_forall_caff || $no_cart);



      $c  = fill_array( db_res( "SELECT Profile AS ID, Date, Profiles.NickName, Profiles.Email FROM Transactions LEFT JOIN Profiles ON Transactions.Profile = Profiles.ID WHERE Member = $member[ID] ORDER BY Date DESC" ) );

      $wc = fill_array( db_res( "SELECT Member AS ID, Date, Profiles.NickName, Profiles.Email FROM Transactions LEFT JOIN Profiles ON Transactions.Member = Profiles.ID WHERE Profile = $member[ID] ORDER BY Date DESC" ) );

      $max_l  = GetParam( "max_inbox_message_size" );

      $max_m  = GetParam( "max_inbox_messages" );



      $arr = array_merge( $c, $wc );





      // user can not send message if he is not active member

      $not_active = db_arr("SELECT ID FROM Profiles WHERE ID = $member[ID] AND Status != 'Active'");

      if ( $not_active )

      {

            $ret = "<table width=".($content_w-20)." cellpadding=4 cellspacing=4><td align=center class=text>";

            $ret .= _t("_COMPOSE_REJECT2");

            $ret .= "</td></table>";



            return $ret;

      }



      // user can not send message if he is not paid member

      if ( (!count($arr) && !$is_caff_member) || $not_active )

      {

            $ret = "<table width=".($content_w-20)." cellpadding=4 cellspacing=4><td align=center class=text>";

            $ret .= _t("_COMPOSE_REJECT");

            $ret .= "</td></table>";



            return $ret;

      }



      ob_start();



if ( $_POST[SEND_MESSAGE] == "YES" && $_POST[text] )

{

  $p_arr = db_arr( "SELECT ID,NickName,Email FROM Profiles WHERE ID = $member[ID]" );




  if ( $is_caff_member && strlen($_POST[caff_id_to]) > 0 )

  {


                  $memb_arr[ID] = $_POST[caff_id_to];
                       $tmp_arr = db_arr("SELECT ID, NickName, Email FROM Profiles WHERE ID=".intval($_POST['caff_id_to']));



                  if ( count($tmp_arr) > 0 )

                  {

                        $memb_arr[Email] = $tmp_arr[Email];
                $memb_arr[NickName] = $tmp_arr[NickName];
             


                        MemberSendMessage();

                  }

                  else

                  {

                        $error = 1;

                  }

  }

  else

  {      

    while( list( $key, $val ) = each( $_POST ) )

    {

        if ( (int)$key && $val )

        {

                  for ( $i = 0; $arr[$i]; $i++ )

                  {

                        if ( $arr[$i][ID] == $key )

                        {

                              $memb_arr = $arr[$i];

                              break;

                        }

                  }

      

                  if ( !$memb_arr )

                  {

                        $result = _t( "_PROFILE_NOT_AVAILABLE" ) . "<br>";

                        $error = 1;

                        break;

                  }

      

                  MemberSendMessage();

            }

    }



  }



    switch ( $error )

    {

      case 1:

              $result .= _t_err( "_FAILED_TO_SEND_MESSAGE" );

            break;

      case 2:

              $result .= _t_err( "_FAILED_TO_SEND_MESSAGE", $max_caff_day_messages );

            break;

      case 5:

              $result .= _t_err( "_FAILED_TO_SEND_MESSAGE_BLOCK" );

            break;

      default:

                   $result .= _t_err( "_MESSAGE_SENT" );

            break;

    }



}



$sel_arr = array_unique( explode( ",", $_GET[to] ) );



$m_per_row = 5;



if ( $m_per_row > count( $arr ) )

    $m_per_row = count( $arr );



echo "<table width=".($content_w-20)." cellpadding=4 cellspacing=4><td align=center class=text>";



if ( $result )

    echo "<b>$result</b><br><br>";

?>

<form method=post action="<? echo $_SERVER[PHP_SELF]; ?>">



<?

if (!$is_caff_member)

{

      if ( $ID_ADD > 0 ) echo "<input type=hidden name=ID_SAVE value=$ID_ADD>";

}



if ($is_caff_member)

{

?>

<table cellspacing=1 cellpadding=2 class=small width=100%>

<tr class=panel>

  <!-- commented out redundant line above who to send it to
   <td colspan=2>&nbsp;<? echo _t( "_YOU_ARE_CAFF_SEND_MSG_TO" ); ?></td> -->

</tr>

<tr class=panel>
 

 
    <td width=15%>&nbsp;<?php echo $_GET[NickNAme]; ?>&nbsp;</td><td width=85% align=left>&nbsp;



   
<input class=no size=15 type=hidden name=caff_id_to value="<?php echo ( $_GET[to] ? $_GET[to] : $_GET[ID]);?>  


"></td>

</tr>

</table>

<?

}

?>



<table cellspacing=1 cellpadding=0 class=small width=100%>

<tr class=panel>

<?php

if ( $arr[$i] > 0 ) { ?>

    <td colspan="<? echo $m_per_row; ?>" ?>>&nbsp;<? echo _t( "_Send a message to" ); ?></td>

<?

}

for ( $i = 0; $arr[$i]; $i++ )

{

    if ( ( $i / $m_per_row ) == floor( $i / $m_per_row ) )

    {

?>

</tr>

<tr class=table>

<?

    }

?>

    <td width=20%>

      <table class=text cellspacing=0 cellpadding=0>

      <td>&nbsp;</td>

      <td><input type=checkbox <?

      if ( in_array( $arr[$i][ID], $sel_arr ) )

            echo "checked ";

?> name=<? echo $arr[$i][ID]; ?>></td>

      <td>&nbsp;<a href="profile.php?ID=<? echo $arr[$i][ID]; ?>"><? echo $arr[$i][NickName]; ?></a>&nbsp;</td>

      </table>

    </td>

<?

}

?>

</tr>



<tr><td>&nbsp;</td></tr>



<tr><td colspan="<? echo $m_per_row; ?>" >

    <table cellspacing=0 class=text width=100%>

      <td class=panel><img src="<? echo $site[images]; ?>write_message.gif"></td>

      <td width=100% class=panel align=right>&nbsp;<b><? echo _t( "_Message text" ); ?></b>&nbsp;(<? echo _t( "_MAX_CHARS_TO_CC_UNLIM_TO_EMAIL", $max_l ); ?>)</td>

    </table>

</td></tr>



<tr class=panel><td colspan="<? echo $m_per_row; ?>" >

    <table cellspacing=1 cellpadding=5 width=100% class=text><td class=table1 align=center>

      <textarea name=text rows=10 cols=70></textarea>

    </td></table>

</td></tr>



<tr class=panel><td colspan="<? echo $m_per_row; ?>" >

    <table width=100% cellspacing=2 cellpadding=0 class=text><td>&nbsp;</td>

<?

    switch( $_POST[sendto] )

    {

      case 'email':

          $email_sel          = "checked";

          $lovemail_sel   = "";

          $both_sel          = "";

      break;

      case 'lovemail':

          $email_sel          = "";

          $lovemail_sel   = "checked";

          $both_sel          = "";

      break;

      default:

          $email_sel          = "";

          $lovemail_sel   = "";

          $both_sel          = "checked";

      break;

    }

?>

      <td><input type=radio name=sendto value=email <? echo $email_sel; ?>></td>

      <td nowrap>&nbsp;<? echo _t( "_Send to e-mail" ) . "$tab$tab"; ?></td>

      <td><input type=radio name=sendto value=lovemail <? echo $lovemail_sel; ?>></td>

      <td nowrap>&nbsp;<? echo _t( "_Send to communicator" ) . "$tab$tab"; ?></td>

      <td><input type=radio name=sendto value=both <? echo $both_sel; ?>></td>

      <td nowrap>&nbsp;<? echo _t( "_Both" ) .  "$tab$tab"; ?></td>

      <td align=right width=100%>

      <input class=no type=submit value="<? echo _t( "_Send" ); ?>"></td>

    </table>

</td></tr>

</table>

<input type=hidden name=SEND_MESSAGE value=YES></form>



</td></table>

<?  



    $ret = ob_get_contents();

    ob_end_clean();



    return $ret;

}









/**

 * Check for max of caff messages per day

 */

function MemberCaffCheckMaxMsg ( $ID )

{

    global $max_caff_day_messages;

    $tmp_arr = db_arr("SELECT (msgNum >= $max_caff_day_messages AND (TO_DAYS(msgTimeToday) = TO_DAYS(NOW()))) as caff_if FROM Mem_caff WHERE ID=$ID");

    return !$tmp_arr[caff_if];

}



/**

 * Update number of sent messages

 */

function MemberCaffUpdateMaxMsg ( $ID )

{



    $tmp_arr = db_arr("SELECT (TO_DAYS(msgTimeToday) = TO_DAYS(NOW())) as day_if FROM Mem_caff WHERE ID=$ID");



    if ( $tmp_arr[day_if] )

        db_res("UPDATE Mem_caff SET msgTimeToday = NOW(), msgNum=msgNum+1 WHERE ID=$ID");

    else

        db_res("UPDATE Mem_caff SET msgTimeToday = NOW(), msgNum=1 WHERE ID=$ID");

}







/**

 * Send message

 */

function MemberSendMessage()

{

      global $memb_arr;

      global $site;

      global $p_arr;

      global $error;

      global $max_l;

      global $member;

      global $is_caff_member;

      global $days_forall_caff;



      $no_cart = getParam("no_cart");



      $member[ID] = (int)$member[ID];

      $memb_arr[ID] = (int)$memb_arr[ID];



      if ( !db_arr("SELECT ID FROM Profiles WHERE ID = $member[ID] AND Status = 'Active'") )

    {

        $error = 1;

        return;

    }


// SV added NickName in effort to make blocklist function by NickName not ID...or both...pulled back out after removed the dbase NickName field for now
      if ( db_arr("SELECT ID, Profile FROM BlockList WHERE Profile = $member[ID] AND ID = $memb_arr[ID]") )

      {

            $error = 5;

            return;

      }



      if ( !$no_cart )

      {

          if (

                        !db_arr("SELECT ID FROM Profiles WHERE ID = $member[ID] AND ((ExtraAddons+0) & 2) > 0 ")

                        &&

                        !db_arr("SELECT ID FROM Profiles WHERE ID = $memb_arr[ID] AND ((ExtraAddons+0) & 1) > 0 ")

                  )

            {

                  $error = 8;

              return;

            }

      }





      if ( $is_caff_member  && !MemberCaffCheckMaxMsg($member[ID]))

      {

            $error = 2;

            return;

      }





      if ( $_POST[sendto] == "email" || $_POST[sendto] == "both" )

      {

            $msg = getParam("t_Message");



            $msg = str_replace( "<SiteName>", $site['title'], $msg );

            $msg = str_replace( "<Domain>", $site['url'], $msg );

//            $msg = str_replace( "<YourRealName>", $memb_arr[RealName], $msg );
        $msg = str_replace( " <YourNickName>", $memb_arr[NickName], $msg);

            $msg = str_replace( "<NickName>", $p_arr[NickName], $msg );

            $msg = str_replace( "<StrID>", $p_arr[ID], $msg );

            $msg = str_replace( "<ID>", $p_arr[ID], $msg );

            $msg = str_replace( "<TEXT>", $_POST[text], $msg );





            if ( !mail( $memb_arr[Email], "$site[title]: "._t("_Message from")." $p_arr[NickName]", $msg, "From: $site[email_notify]", "-f$site[email_notify]" ) )

                  $error = 1;

      }





      if ( ($_POST[sendto] == "lovemail" || $_POST[sendto] == "both") /* && !$days_forall_caff */ )

      {

            $towrite = strlen( $_POST[text] ) > $max_l ? "LEFT ( '$_POST[text]', $max_l )" : "'$_POST[text]'";



            $res = db_res( "INSERT INTO Messages ( Date, Sender, Recipient, Text, New ) VALUES ( NOW(), $member[ID], $memb_arr[ID], $towrite, '1' )" );





            if ( $max_m )

            {

                  $res = db_res( "SELECT Date FROM `Messages` WHERE Recipient = $memb_arr[ID] ORDER BY Date ASC" );

                  if ( mysql_num_rows( $res ) > $max_m )

                  {

                        $date_arr = mysql_fetch_array( $res );

                        db_res( "DELETE FROM `Messages` WHERE Recipient = $memb_arr[ID] AND Date = '$date_arr[Date]' LIMIT 1" );

                  }

            }



      }

      if ( $is_caff_member /* && !$days_forall_caff */ ) MemberCaffUpdateMaxMsg ($member[ID]);

}





?>
0
 

Author Comment

by:Steve_Newbie
ID: 11806946
Little mor complex than anticipated I guess.  Here's another 100 points.....
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11806969
Ok, it'll take me a while to work through this... I'll get back to you

On a different note, you might want to comment more in your future scripts - It helps at times like this, although I have to admit I'm just as bad when I'm not forcing myself:- I know what it does. Why does anyone else need to? :-D
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11807090
Gah to be honest I can't make sense of this code esp. since most of the functions aren't in it. I hjave to admit I'm stuck for the moment. I'll keep looking but I'm not optimistic for the moment

Also, I didn't make myself clear - somewhere.com was en example URL not a specific one.

Let's try this one more way...

try doing

print_r (db_arr($query="SELECT NickName FROM Profiles WHERE ID=100"))); //Where 100 is a VALID ID

and tell me what it says
0
 

Author Comment

by:Steve_Newbie
ID: 11807187
It gives the appropriate NickName for the given ID
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11807383
Stunning! Ok, we have the problem solved pretty much... You've already said that $_GET['ID'] has the correct ID in it, so the problem was in passing the ID to the query.

so now do:

$tmp_array=db_arr($query="SELECT NickName, Email FROM Profiles WHERE ID=" . $_GET['ID']));

then

$Email = $temp_array['Email'];
$NickName = $temp_array['NickName'];

This should solve your problem. You can now use $Email and $NickName in oyur script

*tada*
0
 

Author Comment

by:Steve_Newbie
ID: 11807449
Testing it.....not quite working.......hold on......not that this is IM, but.....
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11807474
DAMNED TYPOS!

$tmp_array is different to $temp_array
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11807478
and one too many closing brackets...
0
 

Author Comment

by:Steve_Newbie
ID: 11807495
OK, that does not work.....get a dbase access error and does not print/echo the NickName.....but hold on, something interesting in my attempts at applying what I read in a book:

This code works, but ONLY AFTER message is sent...  In other words, while composing the message, the spot where the echo is supposed to shoe the NickName is blank...but when you click to send, and the message afterwards reads" mail sent succesfully"....in that echo area, the right NickNAme is displayed.


      $result = mysql_query("SELECT ID, NickName, Email FROM Profiles WHERE ID=".(int)$_POST[caff_id_to]);

while($row = mysql_fetch_array($result)) {
  $NickName = $row["NickName"];

  echo "<td width=15%> <b>TO:" . $NickName . "<b>: </td>";

}


What's up with that???? Wierd.
0
 

Author Comment

by:Steve_Newbie
ID: 11807497
OK, I did not try the temp_array...will try while you think about my last post......  :-)
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11807529
Sounds like the database query taking time to execute and the script not waiting, which I didn't think was default behaviour (or even possible).

So, you get an error, the variable is initally empty, and then a few lines later it is set? Am I understanding correctly?
0
 

Author Comment

by:Steve_Newbie
ID: 11807539
Just using the code I sent you, I get no error....just a blank in the place where NickName should be.  But when the message is sent  (it is still displayed while the "message sent successfully" sign pops up)....all of a sudden the NickName pops up in the place where is should be echoing in the first place.  That is without the code mods you sent.....just what I sent to you...

0
 

Author Comment

by:Steve_Newbie
ID: 11807563
With your code, leaving mine out of it.....the following error is generated, although the message is sent......but can't see the NickNAme echoing at any point.

Error in /compose.php: You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Query: 'SELECT NickName, Email FROM Profiles WHERE ID='
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11807566
Hmmm. I don't have your MemberSendMessage function to look at but that does seem strange. How does it go with the code mods I mentioned?
0
 

Author Comment

by:Steve_Newbie
ID: 11807595
Message is sent, but goes immediately to the dbase access error re: SL syntax.......   So, can't see the effect  on the NickName display area after the message is sent....
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11807631
For some reason, it seems that the ID isn't being passed again (still?). The error message is a generic MySQL Syntax Error and the code it output looks fine as far as it goes.

So far we have:

A query with WHERE ID=100 works
A query with WHERE ID=<data from $_GET['ID']> doesn't
querying $_GET['ID'] returns a valid ID number

Hmm. This is getting frustrating (although a good challenge so it's not a problem). Sorry that we seem to be going in circles here. Does the email go to the correct address? That'll show us whether or not the database query is actually working.

It MAY be that the ID is the wrong type (or has extraneous characters of some sort) but this seems unlikely.

What is the output (exactly) from the code below?
print_r(db_arr("SELECT NickName, Email FROM Profiles WHERE ID=" . $_GET['ID']));

I think I made a 3rd mistake in that very short code snippet I sent you - there is no need for a $query= in the db_array function.
0
 

Author Comment

by:Steve_Newbie
ID: 11807646
Mail goes to the right address.  Let me check the output.
0
 

Author Comment

by:Steve_Newbie
ID: 11807667
The output from that snippet is :

You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Query: 'SELECT NickName, Email FROM Profiles WHERE ID='

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Expert Comment

by:basiclife
ID: 11807710
ok, now do

print "-" . $_GET['ID'] . "-";

and show me the output from that
0
 

Author Comment

by:Steve_Newbie
ID: 11807755
OK, not to look like an idiot, but you meant that print string literally right?   If so, then the output is only  "--"
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11807787
Not idiotic - that's exactly what I meant. For some reason $_GET['ID'] has now gone back to being blank. The -'s on either side were to check for spaces/other "white" characters if they were there.

In your original post, you said:

 Using the following, the ID echos fine:
           <td width=15%>&nbsp;<?php echo"<b>TO:$_GET[ID]<b>"; ?>:&nbsp;</td><td width=85% align=left>&nbsp;

now we're not getting the $GET['ID'] anymore. Do you know of any variable that holds the ID before we do the database query? If so, substitute it into the db_arr instead of $_GET['ID'] and it should work.
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11807792
(I meant the print string to be executed in place of the db_arr funciton or just before it, so we can test the variable at that point in the execution)
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11807826
Need to get a few hours sleep but will be back after that, so leave the outcome of the latest test and any thoughts you have and I'll attack it ASAP
0
 

Author Comment

by:Steve_Newbie
ID: 11807841
OK....thanks......
0
 

Author Comment

by:Steve_Newbie
ID: 11808021
OK....still working on being a bit on the idiot side I suppose..   The only ways I know how to test php code is by using a separate testing file and adding the code of interest between <?php ?> tags and seeing what happens to the output.....and/or by turning on error_reporting output for the whole page if there seem to be errors  coming up that are not fatal.    Perhaps I have been misleading you in the output using the former approach, but it seems like it was doing what it was supposed to.  If I have given you gray hairs on this.....apologies.  Otherwise, please advise.  
As far as $_GET[ID] output within the app code as a whole, it outputs the ID to the html template (i.e. in the working app) correctly.  Does that make any sense?
Thanks.
S  
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11811382
Ok, the problem with your testibng method is that it will have a clean environment - ie The variables will not be set, etc... What you need to do is test code in-situ. So, at the point before and after where you're having a problem in your main code, put a little extra bit of code to tell you what the scripts thinking at that time. Then, compare the answers from before and after the problem and see if what's supposed to change has, or what could've caused the change to fail. Make sense?

Don't worry about grey hairs - everyone needs to start somewhere and I've been where you are.

As to the _GET[ID] bit - that's positive, but now we need to retest the previous ideas in the main script.

So, replace the normal db_arr query with:

print_r(db_arr("SELECT NickName, Email FROM Profiles WHERE ID=" . $_GET['ID']));

and see what it outputs (you'll get some errors afterwards, as the variables it's trying to use won't be set correctly, but what we need is the output form the array itself)

The problem with testing this line in a file on its own is that the $_GET['ID'] won't be set to a user ID, so it won't perform a valid MySQL query, hence the MySQL Syntax Error.

Sound good?
0
 

Author Comment

by:Steve_Newbie
ID: 11812257
OK, in the native code, if I insert the query as above, I get a dbase access error, as before:

 Error in /compose.php: You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Query: 'SELECT NickName, Email FROM Profiles WHERE ID='

I am just plugging in the code snippet and running the file.....is there another way?

S
0
 

Author Comment

by:Steve_Newbie
ID: 11812485
BTW, the code I came up with that made the echo display late......that was ADDITIONAL code, inserted right before the echo request.  The original dbase query code that comes earlier (which we have been working on)  I left alone.  That code (the original) seems to correctly call for  the hidden input value (the ID) to send the mail to the right person.  The echo output is right above the hidden value input code area (as per the overall code I posted). That is where I put in the code that I had posted earlier  (copy below with the echo for $NickName included):

  $result = mysql_query("SELECT ID, NickName, Email FROM Profiles WHERE ID=".(int)$_POST[caff_id_to]);

while($row = mysql_fetch_array($result)) {
  $NickName = $row["NickName"];

  echo "<td width=15%> <b>TO:" . $NickName . "<b>: </td>";

Again, the mail goes to the right place with this combo, and the echo is displayed.........albeit way late.  

As far as your code snippets, I had simply replaced the original earier db query code area with those.  I also tried to do that with my code changes posted above (in this post), but when it replaces the original db query code area, it does not work either.  The above only works when added on and the original dbase query code is left intact.  

S
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11813087
Do you have more than one person with the same ID? The code above is parsing through a list of results
0
 

Author Comment

by:Steve_Newbie
ID: 11813387
No, all unique IDs.
0
 

Author Comment

by:Steve_Newbie
ID: 11813404
The ID=caff_id_to should be a list of unique IDs who are eligible to receive or send mail messages.  But they are all unique.
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11813982
I may have been being very stupid. Are you trying to send email to one person or many?
0
 

Author Comment

by:Steve_Newbie
ID: 11814797
No, only one at a time at this point.  That is actually part of the change.  The way the code was written originally, the input was text, not hidden, and the sender could punch in multiple IDs into the entry box in the following code (which still exists in the above post and in the app, except now the field is hidden):

<input class=no size=15 type=hidden name=caff_id_to value="<?php echo ( $_GET[to] ? $_GET[to] : $_GET[ID]);?>  

The echo part I added as is noted in the code just above this line.  So, the intent was to limit the user to send ONLY to one person behind the scened using unique user IDs. They click on a "contact" icon associated with the profile of interest, and get sent to the file this code is located in  (compose.php), which again, is the code I posted previously.

The idea was to echo the NickName to whom they were sending the mail to, but not be able to influence that or enter multiple NickNAmes or IDs.  

Hope that clarifies.
S
0
 

Author Comment

by:Steve_Newbie
ID: 11814843
Again, everything works perfectly behind the scences, including the blocking function and billing module, using unique ID.  So, the ID is passed on properly to the hidden value entry.  The only thing that is off is that the NickName echo is either missing or is delayed with the addition of the code I added.

S
0
 

Author Comment

by:Steve_Newbie
ID: 11817844
Did I say something wrong??  Please advise.
Thanks.
Steve  
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11820010
Sorry. Am living in the UK and working in a pub ATM - Makes keeping regular hours difficult. I'll look onw.
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11820161
In the code snippet above, the value of caff_id_to is set to either $_GET['to'] (if there is one) or $_GET['id'] if there isn't. Sound correct?

Se on the next form (the one oyu posted the code for), $_POST['caff_id_to'] is not neccesarily an ID, it could be whatever was in $_GET['to'] on the previous page. Is that a number as well or is it a nickname?

In the posted code:

  if ( $is_caff_member && strlen($_POST[caff_id_to]) > 0 )

  {


               $memb_arr[ID] = $_POST[caff_id_to];
                       $tmp_arr = db_arr("SELECT ID, NickName, Email FROM Profiles WHERE ID=".intval($_POST['caff_id_to']));



               if ( count($tmp_arr) > 0 )

               {

                    $memb_arr[Email] = $tmp_arr[Email];
                $memb_arr[NickName] = $tmp_arr[NickName];

                ...
}

$is_caff_member = ( $caff_arr[is_caff] || $days_forall_caff || $no_cart);           (earlier in the script)

So as far as I can tell, there is no testing whether or not the caff_id_to is actually an ID.

Using the code you posted (or the latest version of it), try changing the previous page and putting a valid ID in the hidden field as opposed to a nickname. I'm not 100% sure about the intricacies of your code but it seems possible that if caff_id_to is a nickname, you'll get a query searching for ID 0 in the database.
0
 

Author Comment

by:Steve_Newbie
ID: 11823135
Hi.
Thanks, as far as the "to" and "id" part, I don't know for sure, but it looks like it was looking for the id that the message was being sent to......the mail would not be sent to the sending person (to themselves), so I don't think that is the logic behind the code.

AS far as the code pages......maybe I miscommunicated something, but this is all from one php page (compose.php).  The code execution carries out two functions (1) send an interernal mail message  (2) using an external email address, sends a notification to the receipient that an internal (app's system) message has been sent to them.   That is  why there is a  $tmp_arr[Email] in there.  

As far as testing is concerned, you may be right.  I had used NickName hard coded for a while and it seemed to send the messages, but since the ID driven part of the code was then broken, the block function stopped working.  So, that is why I embarked on leaving the background mail sending to be ID driven and then insert the echo so the sender is reassured re: to whom the message is going.

I know that the caff_id_to is not a nickname inherently.  The code was built to be heavily driven by ID.  NickName seems like an afterthought in the entire app.  

You may be worndering why I don't ask to the people from whom I purchased the original code license from(including right to modify).  Absolutely positively terrible tech support with cursory "you guess what I said" type answers.  I have tried.  Anything beyond a minimal insertion or deletion is not answered and they have not been responsive to work bids either....so here I am.

Thanks.
Steve

0
 
LVL 5

Expert Comment

by:basiclife
ID: 11826228
Damn. Thought I'd posted a reply about 4 hours ago.

If you put a
print "-" . $_POST[caff_id_to] . "-";
before the db_arr query, what does it output?
0
 

Author Comment

by:Steve_Newbie
ID: 11826271
It posts the correct  ID to whom the messgage is going.

S
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11826325
Ok, now try seperately,

1) print "SELECT ID, NickName, Email FROM Profiles WHERE ID=".intval($_POST['caff_id_to'];

2) print_r (db_arr("SELECT ID, NickName, Email FROM Profiles WHERE ID=".intval($_POST['caff_id_to']));

3)

$temp = db_arr("SELECT ID, NickName, Email FROM Profiles WHERE ID=".intval($_POST['caff_id_to']);

print $temp['Email'];

and tell me what each says
0
 

Author Comment

by:Steve_Newbie
ID: 11826334
Also, if I do this:
     print   $memb_arr[NickName] = $tmp_arr[NickName];

Right after the query....it posts the correct name to whom it is going.....but again.......late.....at the same time as my code mod does.    IT is as if it is going to another page after the "mesage has been sent" comes up.  But not really.......

??
Steve
0
 

Author Comment

by:Steve_Newbie
ID: 11826351
Get parse errors, unexpected ";"  for all..  Do you mean instead of the query or after or before or?

S
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11826354
What do you mean by late? If that's right after the query.... ?
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11826400
I meant instead of (and oyu need to add one closing bracket at the end of every line before the ;)
0
 

Author Comment

by:Steve_Newbie
ID: 11826424
OK, sorry, have to run for a few hours....will repost a bit later....Thanks!! again..
Steve
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11826450
OK. bye
0
 

Author Comment

by:Steve_Newbie
ID: 11827989

For #1 : SELECT ID, NickName, Email FROM Profiles WHERE ID=4

For #2 :  Array ( [0] => 4 [ID] => 4 [1] => TahCps [NickName] => TahCps [2] => steve@xxxx.com [Email] => steve@xxxx.com )  

For #3:  steve@xxxx.com

Which are all the correct:  nickname, ID, and email address to whom the message and external email is going to.
They ALL appear LATE on the screen.  In other words when compose.php is first put up, the browser html output  does not include any of the above. There is just a message box, blank, ready to accept input and no echo of the above visible anywhere.    As soon as send (sennd message)  is clicked on that page however......the above all come up in executing the send command.....of course not in the right place, but on the screen anyway.

This is DIFFERENT from the original code output.  When using the original ID driven code which put the ID (to whom the message is going) in the text entry area of the message box (the value that is now hidden as per above post explanation), that ID appeared in the text entry box BEFORE the message was sent.  

Hope that helps.  Clear as mud to me.....LOL.
Steve  
0
 

Author Comment

by:Steve_Newbie
ID: 11837994
Sorry I had to run quickly last night.....my "day job" is doing a little surgery......so was an emergency.  LEt me know when you get a chance to review the above.
Thanks.
S
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11838491
That is SO confusing. To be honest, I can't think why it's doing that. I'll keep looking though, give me a day to look into it.
0
 

Author Comment

by:Steve_Newbie
ID: 11838519
OK....thanks for hanging in there with the help!!  Appreciate it.
Steve
0
 

Author Comment

by:Steve_Newbie
ID: 11845468
OK, getting closer but have a SQL syntax error .....have finally have some clues from the code author as follows:

$_GET[NickName] is undefined. Use the following code

Code:

<td width=15%>&<?php
$nick = db_arr("SELECT NickName FROM Profiles WHERE ID = ".( $_GET[to] ? $_GET[to] : $_GET[ID]) );
echo $nick[0];
?>&</td><td width=85% align=left>&
 

instead of
Code:

<td width=15%>&<?php echo $_GET[NickName]; ?>&</td><td width=85% align=left>&
 
This, with all of our changes removed, does echo the correct NickName in the correct place at the correct time........GREAT!!
BUT.....now I get a syntax error ::

Error in /compose.php: You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Query: 'SELECT NickName FROM Profiles WHERE ID = '

If we can beat this last hurdle, the final fix is upon us..........wheew.......jjeeeeeezzzz.......
??
Steve
0
 

Author Comment

by:Steve_Newbie
ID: 11846880
OK, this about wraps it up....it works with the following changes.  Yay!  The only annoying thing is that the window stays open after the message successfully sent appears with an empty text entry area and now empty echo to whom the message was sent.

 <td width=15%><?php
$nick = db_arr("SELECT NickName FROM Profiles WHERE ID=\"".($_GET[to]? $_GET[to] : $_GET[ID]) . "\"");
echo "<b>TO:<font color=red>$nick[0]</font></b>";
?></td><td width=85% align=left>  

If I add points, since you now know this part of the code, do you have an angle at a javascript or something closure of this window when the message is sent ????

Thanks for your help either way.  I 'll wait for your reply before assigning the points....due to the final question above.

Steve
0
 
LVL 5

Expert Comment

by:basiclife
ID: 11857010
Let me look into it... Give me 10 minutes
0
 
LVL 5

Accepted Solution

by:
basiclife earned 200 total points
ID: 11857065
Putting this in your code SHOULD close your window when the page has loaded but I'm noy a Java programmer so I can't guarantee it. Sorry you had to solve the problem yourself. If you want to ask for a refund on the points, I won't object. If you want to give me them, then thanks :-D Glad your code is working either way.


<head>
<script language="JavaScript">
function closeMe()
{
     window.close();
}
</script>
</head>
<body onload="closeMe()">
0
 

Author Comment

by:Steve_Newbie
ID: 11857234
It was a helluva collaborative effort.  Got me to where I could decipher some things and ask appropriate questions.  So. thanks a lot!
Steve
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now