[Solved]Miss matching my " and ' ?

Discussion forum for MOD Writers regarding MOD Development.
Locked
User avatar
ThunderCrew
Registered User
Posts: 1438
Joined: Sat Jun 30, 2007 6:26 pm
Location: Ill, Usa
Contact:

[Solved]Miss matching my " and ' ?

Post by ThunderCrew » Mon Apr 04, 2011 6:24 am

I know I had this problem before and cant seem to find my post where I had help in the past on a mod,

I get
Unknown column '$liked' in 'where clause' [1054]

SQL

SELECT s.*, u.* FROM (phpbb_socialnet_status s) LEFT JOIN phpbb_users u ON (s.poster_id = u.user_id) WHERE status_id = $liked

Code: Select all

// grab ID for the case liked
$liked = request_var('liked', 0);

if( $liked )
{
   // as long as id is none zero this will be executed
    $sql = 'SELECT s.*, u.*
    FROM (phpbb_socialnet_status s)
    LEFT JOIN phpbb_users u ON (s.poster_id = u.user_id)
    WHERE status_id = $liked';
        $result = $db->sql_query($sql);
      // the stuff to do once grabbing the id variable from the requested var?      
      while ($row = $db->sql_fetchrow($result))
      {
         $liked = $row['status_id'];
    $template->assign_block_vars('liked', array(
                'AVATAR'            => ($row['user_avatar']),
                'TEXT'            => ($row['status_text']),
                'USERNAME'            => ($row['username']),
         ));


      } // end while loop
      $db->sql_freeresult($result);


} // end the if
I am wanting to use the VARIABLE from the

Code: Select all

$liked = request_var('liked', 0);
and I know it does work because in this code it works

Code: Select all

// grab ID for the case liked
$liked = request_var('liked', 0);

if( $liked )
{
   // as long as id is none zero this will be executed
   $sql = "SELECT *
        FROM " . SN_STATUS_TABLE . " 
        WHERE status_id = " . $liked;
      $result = $db->sql_query($sql);
      // the stuff to do once grabbing the id variable from the requested var?      
      while ($row = $db->sql_fetchrow($result))
      {
         $liked = $row['status_id'];
         $template->assign_block_vars('liked', array(
            'STATUS'            => ($row['status_text']),
            'ID'            => ($row['status_id']),
         ));


      } // end while loop
      $db->sql_freeresult($result);


} // end the if
So how do I make my " and ' right in the first code of this post?
I know that in the sql area if I have my " and ' sorted properly it will work...

What is your advice or tips for understanding this issue better?
Thanks in advance and more thanks later when I see some help hopefully and understand it better :D
Last edited by ThunderCrew on Mon Apr 04, 2011 9:02 am, edited 1 time in total.
Ugg im a t0tal newb again ...... 2 years off cant remember jack ... time to get to it

User avatar
AmigoJack
Registered User
Posts: 5613
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Miss matching my " and ' ?

Post by AmigoJack » Mon Apr 04, 2011 8:01 am

If $liked is a string:

Code: Select all

    $sql= 'SELECT s.*, u.*
    FROM phpbb_socialnet_status s LEFT 
    JOIN phpbb_users u ON( s.poster_id= u.user_id )
    WHERE status_id= \''. $db-> sql_escape( $liked ). '\''; 
If $liked is an integer:

Code: Select all

    $sql= 'SELECT s.*, u.*
    FROM phpbb_socialnet_status s LEFT 
    JOIN phpbb_users u ON( s.poster_id= u.user_id )
    WHERE status_id= '. (int)$liked; 
The worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
The problem is probably not my English but you do not want to understand correctly.
...
We will not come anybody anyway, nevertheless, it's best to shit this.

User avatar
ThunderCrew
Registered User
Posts: 1438
Joined: Sat Jun 30, 2007 6:26 pm
Location: Ill, Usa
Contact:

Re: [Solved]Miss matching my " and ' ?

Post by ThunderCrew » Mon Apr 04, 2011 8:18 am

AmigoJack wrote:If $liked is a string:

Code: Select all

    $sql= 'SELECT s.*, u.*
    FROM phpbb_socialnet_status s LEFT 
    JOIN phpbb_users u ON( s.poster_id= u.user_id )
    WHERE status_id= \''. $db-> sql_escape( $liked ). '\''; 
If $liked is an integer:

Code: Select all

    $sql= 'SELECT s.*, u.*
    FROM phpbb_socialnet_status s LEFT 
    JOIN phpbb_users u ON( s.poster_id= u.user_id )
    WHERE status_id= '. (int)$liked; 
ok I did this while finding some post of mine from over 1 1/2 years or older ag by browsing every single post ive started lol and got no error now...

Code: Select all

// grab ID for the case liked
$liked = request_var('liked', 0);

if( $liked )
{
   // as long as id is none zero this will be executed
    $sql = 'SELECT s.*, u.*
    FROM (phpbb_socialnet_status s)
    LEFT JOIN phpbb_users u ON (s.poster_id = u.user_id)
    WHERE status_id = ' . $liked;
        $result = $db->sql_query($sql);
      // the stuff to do once grabbing the id variable from the requested var?      
      while ($row = $db->sql_fetchrow($result))
      {
         $liked = $row['status_id'];
    $template->assign_block_vars('liked', array(
                'AVATAR'            => ($row['user_avatar']),
                'TEXT'            => ($row['status_text']),
                'USERNAME'            => ($row['username']),
         ));


      } // end while loop
      $db->sql_freeresult($result);


} // end the if    
$liked is a variable from the page address IE blah.php?liked=
now go go mess with the template area to see if it works then Ill come read this again if I am coming up with ill results. Thank you

EDIT:
Ok the example I posted seems to be working fine, need some template work and otehr stuff sorted but seem to be good now thanx.
Ugg im a t0tal newb again ...... 2 years off cant remember jack ... time to get to it

Locked

Return to “[3.0.x] MOD Writers Discussion”