php variable in sql string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • user

    php variable in sql string

    Have require file with several query stings in it.

    Depending on user input one of strings is selected. Everything going
    along smoothly until I wanted to also input a variable in string. If I
    put string in program works ok, but, if I use string from require file I
    can not seem to insert string.

    $cccb_id is sting..... to be inserted into $query4 and changes depending
    on user input.

    $query4 = "select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
    ',member_lname) as 'member' from member_cccb_lnk join member on
    (member.member_ no = member_cccb_lnk .member_no) join cccb on
    member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id = "$cccb_id"
    order by member";

    output is: select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
    ',member_lname) as 'member' from member_cccb_lnk join member on
    (member.member_ no = member_cccb_lnk .member_no) join cccb on
    member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id = order by
    memberError 1064

    as you can see, "$cccb_id" is not in query string.

    any help will be appreciated.
  • ZeldorBlat

    #2
    Re: php variable in sql string


    user wrote:
    Have require file with several query stings in it.
    >
    Depending on user input one of strings is selected. Everything going
    along smoothly until I wanted to also input a variable in string. If I
    put string in program works ok, but, if I use string from require file I
    can not seem to insert string.
    >
    $cccb_id is sting..... to be inserted into $query4 and changes depending
    on user input.
    >
    $query4 = "select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
    ',member_lname) as 'member' from member_cccb_lnk join member on
    (member.member_ no = member_cccb_lnk .member_no) join cccb on
    member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id = "$cccb_id"
    order by member";
    >
    output is: select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
    ',member_lname) as 'member' from member_cccb_lnk join member on
    (member.member_ no = member_cccb_lnk .member_no) join cccb on
    member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id = order by
    memberError 1064
    >
    as you can see, "$cccb_id" is not in query string.
    >
    any help will be appreciated.
    Count your double quotes:

    $query4 = "select cccb.cccb ... and cccb.cccb_id = "$cccb_id" order by
    member";

    So your $cccb_id isn't inside the quotes. You probably want to either
    remove those quotes so the variable is inserted into the string
    automatically or add .'s on both sides of $cccb_id.

    Comment

    • user

      #3
      Re: php variable in sql string

      Tried those already.....

      '$cccb_id' cccb.cccb_id = ('') order by memberError 1064
      ..'$cccb_id'. gets cccb.cccb_id = (.''.) order by memberError 1064
      and $cccb_id and [cccb_id] and ........



      ZeldorBlat wrote:
      user wrote:
      >
      >>Have require file with several query stings in it.
      >>
      >>Depending on user input one of strings is selected. Everything going
      >>along smoothly until I wanted to also input a variable in string. If I
      >>put string in program works ok, but, if I use string from require file I
      >>can not seem to insert string.
      >>
      >>$cccb_id is sting..... to be inserted into $query4 and changes depending
      >>on user input.
      >>
      >>$query4 = "select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
      >>',member_lnam e) as 'member' from member_cccb_lnk join member on
      >>(member.membe r_no = member_cccb_lnk .member_no) join cccb on
      >>member_cccb_l nk.cccb_id = cccb.cccb_id and cccb.cccb_id = "$cccb_id"
      >>order by member";
      >>
      >>output is: select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
      >>',member_lnam e) as 'member' from member_cccb_lnk join member on
      >>(member.membe r_no = member_cccb_lnk .member_no) join cccb on
      >>member_cccb_l nk.cccb_id = cccb.cccb_id and cccb.cccb_id = order by
      >>memberError 1064
      >>
      >>as you can see, "$cccb_id" is not in query string.
      >>
      >>any help will be appreciated.
      >
      >
      Count your double quotes:
      >
      $query4 = "select cccb.cccb ... and cccb.cccb_id = "$cccb_id" order by
      member";
      >
      So your $cccb_id isn't inside the quotes. You probably want to either
      remove those quotes so the variable is inserted into the string
      automatically or add .'s on both sides of $cccb_id.
      >

      Comment

      • iulian.ilea

        #4
        Re: php variable in sql string


        user wrote:
        Tried those already.....
        >
        '$cccb_id' cccb.cccb_id = ('') order by memberError 1064
        .'$cccb_id'. gets cccb.cccb_id = (.''.) order by memberError 1064
        and $cccb_id and [cccb_id] and ........
        >
        >
        >
        ZeldorBlat wrote:
        >
        user wrote:
        >Have require file with several query stings in it.
        >
        >Depending on user input one of strings is selected. Everything going
        >along smoothly until I wanted to also input a variable in string. If I
        >put string in program works ok, but, if I use string from require file I
        >can not seem to insert string.
        >
        >$cccb_id is sting..... to be inserted into $query4 and changes depending
        >on user input.
        >
        >$query4 = "select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
        >',member_lname ) as 'member' from member_cccb_lnk join member on
        >(member.member _no = member_cccb_lnk .member_no) join cccb on
        >member_cccb_ln k.cccb_id = cccb.cccb_id and cccb.cccb_id = "$cccb_id"
        >order by member";
        >
        >output is: select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
        >',member_lname ) as 'member' from member_cccb_lnk join member on
        >(member.member _no = member_cccb_lnk .member_no) join cccb on
        >member_cccb_ln k.cccb_id = cccb.cccb_id and cccb.cccb_id = order by
        >memberError 1064
        >
        >as you can see, "$cccb_id" is not in query string.
        >
        >any help will be appreciated.

        Count your double quotes:

        $query4 = "select cccb.cccb ... and cccb.cccb_id = "$cccb_id" order by
        member";

        So your $cccb_id isn't inside the quotes. You probably want to either
        remove those quotes so the variable is inserted into the string
        automatically or add .'s on both sides of $cccb_id.
        You can try this also:
        $query4 = "select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
        ',member_lname) as 'member' from member_cccb_lnk join member on
        (member.member_ no = member_cccb_lnk .member_no) join cccb on
        member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id =
        '".$cccb_id. "'
        order by member";

        or, I think this shoul work too:

        $query4 = "select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
        ',member_lname) as 'member' from member_cccb_lnk join member on
        (member.member_ no = member_cccb_lnk .member_no) join cccb on
        member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id =
        \"{$cccb_id} \"
        order by member";

        Comment

        • Jerry Stuckle

          #5
          Re: php variable in sql string

          user wrote:
          Tried those already.....
          >
          '$cccb_id' cccb.cccb_id = ('') order by memberError 1064
          .'$cccb_id'. gets cccb.cccb_id = (.''.) order by memberError 1064
          and $cccb_id and [cccb_id] and ........
          >
          >
          >
          ZeldorBlat wrote:
          >
          >user wrote:
          >>
          >>Have require file with several query stings in it.
          >>>
          >>Depending on user input one of strings is selected. Everything going
          >>along smoothly until I wanted to also input a variable in string. If I
          >>put string in program works ok, but, if I use string from require file I
          >>can not seem to insert string.
          >>>
          >>$cccb_id is sting..... to be inserted into $query4 and changes depending
          >>on user input.
          >>>
          >>$query4 = "select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
          >>',member_lnam e) as 'member' from member_cccb_lnk join member on
          >>(member.membe r_no = member_cccb_lnk .member_no) join cccb on
          >>member_cccb_l nk.cccb_id = cccb.cccb_id and cccb.cccb_id = "$cccb_id"
          >>order by member";
          >>>
          >>output is: select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
          >>',member_lnam e) as 'member' from member_cccb_lnk join member on
          >>(member.membe r_no = member_cccb_lnk .member_no) join cccb on
          >>member_cccb_l nk.cccb_id = cccb.cccb_id and cccb.cccb_id = order by
          >>memberError 1064
          >>>
          >>as you can see, "$cccb_id" is not in query string.
          >>>
          >>any help will be appreciated.
          >>
          >>
          >>
          >Count your double quotes:
          >>
          >$query4 = "select cccb.cccb ... and cccb.cccb_id = "$cccb_id" order by
          >member";
          >>
          >So your $cccb_id isn't inside the quotes. You probably want to either
          >remove those quotes so the variable is inserted into the string
          >automaticall y or add .'s on both sides of $cccb_id.
          >>
          Is $cccb_id a numeric value? If so, it shouldn't be in quotes.
          Removing the double quotes around it will solve your problem.

          If it is not numeric, then you need single quotes around it, not double.

          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • Carl Pearson

            #6
            Re: php variable in sql string

            user wrote:
            Have require file with several query stings in it.
            >
            Depending on user input one of strings is selected. Everything going
            along smoothly until I wanted to also input a variable in string. If I
            put string in program works ok, but, if I use string from require file I
            can not seem to insert string.
            >
            $cccb_id is sting..... to be inserted into $query4 and changes depending
            on user input.
            >
            $query4 = "select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
            ',member_lname) as 'member' from member_cccb_lnk join member on
            (member.member_ no = member_cccb_lnk .member_no) join cccb on
            member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id = "$cccb_id"
            order by member";
            >
            output is: select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
            ',member_lname) as 'member' from member_cccb_lnk join member on
            (member.member_ no = member_cccb_lnk .member_no) join cccb on
            member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id = order by
            memberError 1064
            >
            as you can see, "$cccb_id" is not in query string.
            >
            any help will be appreciated.
            You need to concatenate, i.e.
            $query4 = "some stuff " . $cccb . " some more stuff";

            Make sure you allow for adequate spacing where the different parts meet,
            as the concatenation will literally attach whatever you put together
            into one new string.

            Comment

            • user

              #7
              Re: php variable in sql string

              Results below, had tried, none worked sorry to say, but thanks none the
              less.

              $query4 = "select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
              ',member_lname) as 'member' from member_cccb_lnk join member on
              (member.member_ no = member_cccb_lnk .member_no) join cccb
              on member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id =
              '".$cccb_id. "' order by member;";

              query4 is: select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
              ',member_lname) as 'member'
              from member_cccb_lnk join member on (member.member_ no =
              member_cccb_lnk .member_no) join cccb
              on member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id = '' order by
              member;

              and

              $query4 = "select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
              ',member_lname) as 'member'
              from member_cccb_lnk join member on (member.member_ no =
              member_cccb_lnk .member_no) join cccb
              on member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id =
              \"{$cccb_id} \" order by member;";

              query4 is: select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
              ',member_lname) as 'member'
              from member_cccb_lnk join member on (member.member_ no =
              member_cccb_lnk .member_no) join cccb
              on member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id = "" order by
              member;






              iulian.ilea wrote:
              user wrote:
              >
              >>Tried those already.....
              >>
              >>'$cccb_id' cccb.cccb_id = ('') order by memberError 1064
              >>.'$cccb_id' . gets cccb.cccb_id = (.''.) order by memberError 1064
              >>and $cccb_id and [cccb_id] and ........
              >>
              >>
              >>
              >>ZeldorBlat wrote:
              >>
              >>
              >>>user wrote:
              >>>
              >>>
              >>>>Have require file with several query stings in it.
              >>>>
              >>>>Depending on user input one of strings is selected. Everything going
              >>>>along smoothly until I wanted to also input a variable in string. If I
              >>>>put string in program works ok, but, if I use string from require file I
              >>>>can not seem to insert string.
              >>>>
              >>>>$cccb_id is sting..... to be inserted into $query4 and changes depending
              >>>>on user input.
              >>>>
              >>>>$query4 = "select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
              >>>>',member_ln ame) as 'member' from member_cccb_lnk join member on
              >>>>(member.mem ber_no = member_cccb_lnk .member_no) join cccb on
              >>>>member_cccb _lnk.cccb_id = cccb.cccb_id and cccb.cccb_id = "$cccb_id"
              >>>>order by member";
              >>>>
              >>>>output is: select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
              >>>>',member_ln ame) as 'member' from member_cccb_lnk join member on
              >>>>(member.mem ber_no = member_cccb_lnk .member_no) join cccb on
              >>>>member_cccb _lnk.cccb_id = cccb.cccb_id and cccb.cccb_id = order by
              >>>>memberErr or 1064
              >>>>
              >>>>as you can see, "$cccb_id" is not in query string.
              >>>>
              >>>>any help will be appreciated.
              >>>
              >>>
              >>>Count your double quotes:
              >>>
              >>>$query4 = "select cccb.cccb ... and cccb.cccb_id = "$cccb_id" order by
              >>>member";
              >>>
              >>>So your $cccb_id isn't inside the quotes. You probably want to either
              >>>remove those quotes so the variable is inserted into the string
              >>>automaticall y or add .'s on both sides of $cccb_id.
              >>>
              >
              >
              You can try this also:
              $query4 = "select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
              ',member_lname) as 'member' from member_cccb_lnk join member on
              (member.member_ no = member_cccb_lnk .member_no) join cccb on
              member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id =
              '".$cccb_id. "'
              order by member";
              >
              or, I think this shoul work too:
              >
              $query4 = "select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
              ',member_lname) as 'member' from member_cccb_lnk join member on
              (member.member_ no = member_cccb_lnk .member_no) join cccb on
              member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id =
              \"{$cccb_id} \"
              order by member";
              >

              Comment

              • user

                #8
                Re: php variable in sql string

                Nope but thanks anyway.

                $query4 = "select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
                ',member_lname) as 'member' from member_cccb_lnk join member on
                (member.member_ no = member_cccb_lnk .member_no) join cccb on
                member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id = '$cccb_id'
                order by member;";

                query4 is: select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
                ',member_lname) as 'member'
                from member_cccb_lnk join member on (member.member_ no =
                member_cccb_lnk .member_no) join cccb
                on member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id = '' order by
                member;

                Jerry Stuckle wrote:
                user wrote:
                >
                >Tried those already.....
                >>
                >'$cccb_id' cccb.cccb_id = ('') order by memberError 1064
                >.'$cccb_id'. gets cccb.cccb_id = (.''.) order by memberError 1064
                >and $cccb_id and [cccb_id] and ........
                >>
                >>
                >>
                >ZeldorBlat wrote:
                >>
                >>user wrote:
                >>>
                >>>Have require file with several query stings in it.
                >>>>
                >>>Depending on user input one of strings is selected. Everything going
                >>>along smoothly until I wanted to also input a variable in string. If I
                >>>put string in program works ok, but, if I use string from require
                >>>file I
                >>>can not seem to insert string.
                >>>>
                >>>$cccb_id is sting..... to be inserted into $query4 and changes
                >>>depending
                >>>on user input.
                >>>>
                >>>$query4 = "select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
                >>>',member_lna me) as 'member' from member_cccb_lnk join member on
                >>>(member.memb er_no = member_cccb_lnk .member_no) join cccb on
                >>>member_cccb_ lnk.cccb_id = cccb.cccb_id and cccb.cccb_id = "$cccb_id"
                >>>order by member";
                >>>>
                >>>output is: select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
                >>>',member_lna me) as 'member' from member_cccb_lnk join member on
                >>>(member.memb er_no = member_cccb_lnk .member_no) join cccb on
                >>>member_cccb_ lnk.cccb_id = cccb.cccb_id and cccb.cccb_id = order by
                >>>memberErro r 1064
                >>>>
                >>>as you can see, "$cccb_id" is not in query string.
                >>>>
                >>>any help will be appreciated.
                >>>
                >>>
                >>>
                >>>
                >>Count your double quotes:
                >>>
                >>$query4 = "select cccb.cccb ... and cccb.cccb_id = "$cccb_id" order by
                >>member";
                >>>
                >>So your $cccb_id isn't inside the quotes. You probably want to either
                >>remove those quotes so the variable is inserted into the string
                >>automatical ly or add .'s on both sides of $cccb_id.
                >>>
                >
                Is $cccb_id a numeric value? If so, it shouldn't be in quotes. Removing
                the double quotes around it will solve your problem.
                >
                If it is not numeric, then you need single quotes around it, not double.
                >

                Comment

                • Jerry Stuckle

                  #9
                  Re: php variable in sql string

                  user wrote:
                  Jerry Stuckle wrote:
                  >
                  >user wrote:
                  >>
                  >>Tried those already.....
                  >>>
                  >>'$cccb_id' cccb.cccb_id = ('') order by memberError 1064
                  >>.'$cccb_id' . gets cccb.cccb_id = (.''.) order by memberError 1064
                  >>and $cccb_id and [cccb_id] and ........
                  >>>
                  >>>
                  >>>
                  >>ZeldorBlat wrote:
                  >>>
                  >>>user wrote:
                  >>>>
                  >>>>Have require file with several query stings in it.
                  >>>>>
                  >>>>Depending on user input one of strings is selected. Everything going
                  >>>>along smoothly until I wanted to also input a variable in string. If I
                  >>>>put string in program works ok, but, if I use string from require
                  >>>>file I
                  >>>>can not seem to insert string.
                  >>>>>
                  >>>>$cccb_id is sting..... to be inserted into $query4 and changes
                  >>>>depending
                  >>>>on user input.
                  >>>>>
                  >>>>$query4 = "select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
                  >>>>',member_ln ame) as 'member' from member_cccb_lnk join member on
                  >>>>(member.mem ber_no = member_cccb_lnk .member_no) join cccb on
                  >>>>member_cccb _lnk.cccb_id = cccb.cccb_id and cccb.cccb_id = "$cccb_id"
                  >>>>order by member";
                  >>>>>
                  >>>>output is: select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
                  >>>>',member_ln ame) as 'member' from member_cccb_lnk join member on
                  >>>>(member.mem ber_no = member_cccb_lnk .member_no) join cccb on
                  >>>>member_cccb _lnk.cccb_id = cccb.cccb_id and cccb.cccb_id = order by
                  >>>>memberErr or 1064
                  >>>>>
                  >>>>as you can see, "$cccb_id" is not in query string.
                  >>>>>
                  >>>>any help will be appreciated.
                  >>>>
                  >>>>
                  >>>>
                  >>>>
                  >>>>
                  >>>Count your double quotes:
                  >>>>
                  >>>$query4 = "select cccb.cccb ... and cccb.cccb_id = "$cccb_id" order by
                  >>>member";
                  >>>>
                  >>>So your $cccb_id isn't inside the quotes. You probably want to either
                  >>>remove those quotes so the variable is inserted into the string
                  >>>automaticall y or add .'s on both sides of $cccb_id.
                  >>>>
                  >>
                  >Is $cccb_id a numeric value? If so, it shouldn't be in quotes.
                  >Removing the double quotes around it will solve your problem.
                  >>
                  >If it is not numeric, then you need single quotes around it, not double.
                  >>
                  Nope but thanks anyway.
                  >
                  $query4 = "select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
                  ',member_lname) as 'member' from member_cccb_lnk join member on
                  (member.member_ no = member_cccb_lnk .member_no) join cccb on
                  member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id = '$cccb_id'
                  order by member;";
                  >
                  query4 is: select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
                  ',member_lname) as 'member'
                  from member_cccb_lnk join member on (member.member_ no =
                  member_cccb_lnk .member_no) join cccb
                  on member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id = '' order by
                  member;
                  >
                  (Top posting fixed)

                  Whoops - I missed one important thing. It looks like $cccb_id is empty.

                  Try echoing this to the screen before you build your select statement.

                  P.S. Please don't top post. Thanks.


                  --
                  =============== ===
                  Remove the "x" from my email address
                  Jerry Stuckle
                  JDS Computer Training Corp.
                  jstucklex@attgl obal.net
                  =============== ===

                  Comment

                  • user

                    #10
                    Re: php variable in sql string


                    variable is not empty. As explained earlier this same sql script runs
                    fine if placed inside the php program. It is just when it is located
                    within the require "db.inc" file that the variable substitution does not
                    work.

                    Appreciate your top post request, but refuse to join the flat earth society.

                    Jerry Stuckle wrote:
                    user wrote:
                    >
                    >Jerry Stuckle wrote:
                    >>
                    >>user wrote:
                    >>>
                    >>>Tried those already.....
                    >>>>
                    >>>'$cccb_id' cccb.cccb_id = ('') order by memberError 1064
                    >>>.'$cccb_id '. gets cccb.cccb_id = (.''.) order by memberError 1064
                    >>>and $cccb_id and [cccb_id] and ........
                    >>>>
                    >>>>
                    >>>>
                    >>>ZeldorBlat wrote:
                    >>>>
                    >>>>user wrote:
                    >>>>>
                    >>>>>Have require file with several query stings in it.
                    >>>>>>
                    >>>>>Dependin g on user input one of strings is selected. Everything going
                    >>>>>along smoothly until I wanted to also input a variable in string.
                    >>>>>If I
                    >>>>>put string in program works ok, but, if I use string from require
                    >>>>>file I
                    >>>>>can not seem to insert string.
                    >>>>>>
                    >>>>>$cccb_id is sting..... to be inserted into $query4 and changes
                    >>>>>dependin g
                    >>>>>on user input.
                    >>>>>>
                    >>>>>$query4 = "select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
                    >>>>>',member_l name) as 'member' from member_cccb_lnk join member on
                    >>>>>(member.me mber_no = member_cccb_lnk .member_no) join cccb on
                    >>>>>member_ccc b_lnk.cccb_id = cccb.cccb_id and cccb.cccb_id = "$cccb_id"
                    >>>>>order by member";
                    >>>>>>
                    >>>>>output is: select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
                    >>>>>',member_l name) as 'member' from member_cccb_lnk join member on
                    >>>>>(member.me mber_no = member_cccb_lnk .member_no) join cccb on
                    >>>>>member_ccc b_lnk.cccb_id = cccb.cccb_id and cccb.cccb_id = order by
                    >>>>>memberErro r 1064
                    >>>>>>
                    >>>>>as you can see, "$cccb_id" is not in query string.
                    >>>>>>
                    >>>>>any help will be appreciated.
                    >>>>>
                    >>>>>
                    >>>>>
                    >>>>>
                    >>>>>
                    >>>>>
                    >>>>Count your double quotes:
                    >>>>>
                    >>>>$query4 = "select cccb.cccb ... and cccb.cccb_id = "$cccb_id" order by
                    >>>>member";
                    >>>>>
                    >>>>So your $cccb_id isn't inside the quotes. You probably want to either
                    >>>>remove those quotes so the variable is inserted into the string
                    >>>>automatical ly or add .'s on both sides of $cccb_id.
                    >>>>>
                    >>>
                    >>Is $cccb_id a numeric value? If so, it shouldn't be in quotes.
                    >>Removing the double quotes around it will solve your problem.
                    >>>
                    >>If it is not numeric, then you need single quotes around it, not double.
                    >>>
                    Nope but thanks anyway.
                    >
                    $query4 = "select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
                    ',member_lname) as 'member' from member_cccb_lnk join member on
                    (member.member_ no = member_cccb_lnk .member_no) join cccb on
                    member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id = '$cccb_id'
                    order by member;";
                    >
                    query4 is: select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
                    ',member_lname) as 'member'
                    from member_cccb_lnk join member on (member.member_ no =
                    member_cccb_lnk .member_no) join cccb
                    on member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id = '' order by
                    member;
                    >
                    >
                    (Top posting fixed)
                    >
                    Whoops - I missed one important thing. It looks like $cccb_id is empty.
                    >
                    Try echoing this to the screen before you build your select statement.
                    >
                    P.S. Please don't top post. Thanks.
                    >
                    >

                    Comment

                    • Jerry Stuckle

                      #11
                      Re: php variable in sql string

                      user wrote:
                      Jerry Stuckle wrote:
                      >
                      >user wrote:
                      >>
                      >>Jerry Stuckle wrote:
                      >>>
                      >>>user wrote:
                      >>>>
                      >>>>Tried those already.....
                      >>>>>
                      >>>>'$cccb_id ' cccb.cccb_id = ('') order by memberError 1064
                      >>>>.'$cccb_id' . gets cccb.cccb_id = (.''.) order by memberError 1064
                      >>>>and $cccb_id and [cccb_id] and ........
                      >>>>>
                      >>>>>
                      >>>>>
                      >>>>ZeldorBla t wrote:
                      >>>>>
                      >>>>>user wrote:
                      >>>>>>
                      >>>>>>Have require file with several query stings in it.
                      >>>>>>>
                      >>>>>>Dependi ng on user input one of strings is selected. Everything going
                      >>>>>>along smoothly until I wanted to also input a variable in string.
                      >>>>>>If I
                      >>>>>>put string in program works ok, but, if I use string from require
                      >>>>>>file I
                      >>>>>>can not seem to insert string.
                      >>>>>>>
                      >>>>>>$cccb_i d is sting..... to be inserted into $query4 and changes
                      >>>>>>dependi ng
                      >>>>>>on user input.
                      >>>>>>>
                      >>>>>>$query4 = "select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
                      >>>>>>',member_ lname) as 'member' from member_cccb_lnk join member on
                      >>>>>>(member.m ember_no = member_cccb_lnk .member_no) join cccb on
                      >>>>>>member_cc cb_lnk.cccb_id = cccb.cccb_id and cccb.cccb_id = "$cccb_id"
                      >>>>>>order by member";
                      >>>>>>>
                      >>>>>>output is: select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
                      >>>>>>',member_ lname) as 'member' from member_cccb_lnk join member on
                      >>>>>>(member.m ember_no = member_cccb_lnk .member_no) join cccb on
                      >>>>>>member_cc cb_lnk.cccb_id = cccb.cccb_id and cccb.cccb_id = order by
                      >>>>>>memberErr or 1064
                      >>>>>>>
                      >>>>>>as you can see, "$cccb_id" is not in query string.
                      >>>>>>>
                      >>>>>>any help will be appreciated.
                      >>>>>>
                      >>>>>>
                      >>>>>>
                      >>>>>>
                      >>>>>>
                      >>>>>>
                      >>>>>>
                      >>>>>Count your double quotes:
                      >>>>>>
                      >>>>>$query4 = "select cccb.cccb ... and cccb.cccb_id = "$cccb_id"
                      >>>>>order by
                      >>>>>member";
                      >>>>>>
                      >>>>>So your $cccb_id isn't inside the quotes. You probably want to
                      >>>>>either
                      >>>>>remove those quotes so the variable is inserted into the string
                      >>>>>automatica lly or add .'s on both sides of $cccb_id.
                      >>>>>>
                      >>>>
                      >>>Is $cccb_id a numeric value? If so, it shouldn't be in quotes.
                      >>>Removing the double quotes around it will solve your problem.
                      >>>>
                      >>>If it is not numeric, then you need single quotes around it, not
                      >>>double.
                      >>>>
                      > Nope but thanks anyway.
                      > >
                      > $query4 = "select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
                      > ',member_lname) as 'member' from member_cccb_lnk join member on
                      > (member.member_ no = member_cccb_lnk .member_no) join cccb on
                      > member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id = '$cccb_id'
                      > order by member;";
                      > >
                      > query4 is: select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
                      > ',member_lname) as 'member'
                      > from member_cccb_lnk join member on (member.member_ no =
                      > member_cccb_lnk .member_no) join cccb
                      > on member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id = ''
                      >order by
                      > member;
                      > >
                      >>
                      >(Top posting fixed)
                      >>
                      >Whoops - I missed one important thing. It looks like $cccb_id is empty.
                      >>
                      >Try echoing this to the screen before you build your select statement.
                      >>
                      >P.S. Please don't top post. Thanks.
                      >>
                      >>
                      >
                      variable is not empty. As explained earlier this same sql script runs
                      fine if placed inside the php program. It is just when it is located
                      within the require "db.inc" file that the variable substitution does not
                      work.
                      >
                      Appreciate your top post request, but refuse to join the flat earth
                      society.
                      >
                      (Top posting fixed - again)

                      As I said - did you actually try to echo the variable to the screen to
                      see what's in it?

                      And if you don't follow normal usenet conventions, don't expect to get a
                      lot of help from this newsgroup. You're the one asking for help. You
                      should follow the established conventions.

                      So please don't top post. Or don't expect much for answers.

                      --
                      =============== ===
                      Remove the "x" from my email address
                      Jerry Stuckle
                      JDS Computer Training Corp.
                      jstucklex@attgl obal.net
                      =============== ===

                      Comment

                      • Toby Inkster

                        #12
                        Re: php variable in sql string

                        user wrote:
                        variable is not empty. As explained earlier this same sql script runs
                        fine if placed inside the php program. It is just when it is located
                        within the require "db.inc" file that the variable substitution does not
                        work.
                        Google: scoping.
                        Appreciate your top post request, but refuse to join the flat earth society.
                        Do you tell jokes punch-line first too?

                        --
                        Toby A Inkster BSc (Hons) ARCS
                        Contact Me ~ http://tobyinkster.co.uk/contact

                        Comment

                        • Norman Peelman

                          #13
                          Re: php variable in sql string

                          user wrote:
                          Have require file with several query stings in it.
                          >
                          Depending on user input one of strings is selected. Everything going
                          along smoothly until I wanted to also input a variable in string. If I
                          put string in program works ok, but, if I use string from require file I
                          can not seem to insert string.
                          >
                          $cccb_id is sting..... to be inserted into $query4 and changes depending
                          on user input.
                          >
                          $query4 = "select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
                          ',member_lname) as 'member' from member_cccb_lnk join member on
                          (member.member_ no = member_cccb_lnk .member_no) join cccb on
                          member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id = "$cccb_id"
                          order by member";
                          >
                          output is: select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
                          ',member_lname) as 'member' from member_cccb_lnk join member on
                          (member.member_ no = member_cccb_lnk .member_no) join cccb on
                          member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id = order by
                          memberError 1064
                          >
                          as you can see, "$cccb_id" is not in query string.
                          >
                          any help will be appreciated.
                          Try:

                          $query4 = "select cccb.cccb_name as cccb, CONCAT(member_f name,'
                          ',member_lname) as member from member_cccb_lnk join member on
                          (member.member_ no = member_cccb_lnk .member_no) join cccb on
                          member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id = '$cccb_id'
                          order by member";

                          If $cccb_id has a value in it it will show up in the output. Notice I
                          removed the single quotes from around cccb and member as they are not
                          needed. Use backticks (`) if you must. Always remember, to include
                          variables whithin strings the entire string must be enclosed in double
                          quotes or the variables won't get parsed.

                          Norm

                          Comment

                          • user

                            #14
                            Re: php variable in sql string

                            Jerry,

                            Read posts and reply or don't. That is your decision.

                            P.S. For you and Inkster. THE EARTH IS NOT FLAT!!! REALLY!! Any you
                            saying it is does not make it so!

                            Have a nice day!





                            Jerry Stuckle wrote:
                            user wrote:
                            >
                            >Jerry Stuckle wrote:
                            >>
                            >>user wrote:
                            >>>
                            >>>Jerry Stuckle wrote:
                            >>>>
                            >>>>user wrote:
                            >>>>>
                            >>>>>Tried those already.....
                            >>>>>>
                            >>>>>'$cccb_i d' cccb.cccb_id = ('') order by memberError 1064
                            >>>>>.'$cccb_id '. gets cccb.cccb_id = (.''.) order by memberError 1064
                            >>>>>and $cccb_id and [cccb_id] and ........
                            >>>>>>
                            >>>>>>
                            >>>>>>
                            >>>>>ZeldorBl at wrote:
                            >>>>>>
                            >>>>>>user wrote:
                            >>>>>>>
                            >>>>>>>Have require file with several query stings in it.
                            >>>>>>>>
                            >>>>>>>Dependin g on user input one of strings is selected. Everything
                            >>>>>>>going
                            >>>>>>>along smoothly until I wanted to also input a variable in
                            >>>>>>>string . If I
                            >>>>>>>put string in program works ok, but, if I use string from
                            >>>>>>>requir e file I
                            >>>>>>>can not seem to insert string.
                            >>>>>>>>
                            >>>>>>>$cccb_ id is sting..... to be inserted into $query4 and changes
                            >>>>>>>dependin g
                            >>>>>>>on user input.
                            >>>>>>>>
                            >>>>>>>$query 4 = "select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
                            >>>>>>>',member _lname) as 'member' from member_cccb_lnk join member on
                            >>>>>>>(member. member_no = member_cccb_lnk .member_no) join cccb on
                            >>>>>>>member_c ccb_lnk.cccb_id = cccb.cccb_id and cccb.cccb_id =
                            >>>>>>>"$cccb_i d"
                            >>>>>>>order by member";
                            >>>>>>>>
                            >>>>>>>output is: select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
                            >>>>>>>',member _lname) as 'member' from member_cccb_lnk join member on
                            >>>>>>>(member. member_no = member_cccb_lnk .member_no) join cccb on
                            >>>>>>>member_c ccb_lnk.cccb_id = cccb.cccb_id and cccb.cccb_id = order by
                            >>>>>>>memberEr ror 1064
                            >>>>>>>>
                            >>>>>>>as you can see, "$cccb_id" is not in query string.
                            >>>>>>>>
                            >>>>>>>any help will be appreciated.
                            >>>>>>>
                            >>>>>>>
                            >>>>>>>
                            >>>>>>>
                            >>>>>>>
                            >>>>>>>
                            >>>>>>>
                            >>>>>>>
                            >>>>>>Count your double quotes:
                            >>>>>>>
                            >>>>>>$query4 = "select cccb.cccb ... and cccb.cccb_id = "$cccb_id"
                            >>>>>>order by
                            >>>>>>member" ;
                            >>>>>>>
                            >>>>>>So your $cccb_id isn't inside the quotes. You probably want to
                            >>>>>>either
                            >>>>>>remove those quotes so the variable is inserted into the string
                            >>>>>>automatic ally or add .'s on both sides of $cccb_id.
                            >>>>>>>
                            >>>>>
                            >>>>Is $cccb_id a numeric value? If so, it shouldn't be in quotes.
                            >>>>Removing the double quotes around it will solve your problem.
                            >>>>>
                            >>>>If it is not numeric, then you need single quotes around it, not
                            >>>>double.
                            >>>>>
                            >> Nope but thanks anyway.
                            >> >
                            >> $query4 = "select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
                            >> ',member_lname) as 'member' from member_cccb_lnk join member on
                            >> (member.member_ no = member_cccb_lnk .member_no) join cccb on
                            >> member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id = '$cccb_id'
                            >> order by member;";
                            >> >
                            >> query4 is: select cccb.cccb_name as 'cccb', CONCAT(member_f name,'
                            >> ',member_lname) as 'member'
                            >> from member_cccb_lnk join member on (member.member_ no =
                            >> member_cccb_lnk .member_no) join cccb
                            >> on member_cccb_lnk .cccb_id = cccb.cccb_id and cccb.cccb_id = ''
                            >>order by
                            >> member;
                            >> >
                            >>>
                            >>(Top posting fixed)
                            >>>
                            >>Whoops - I missed one important thing. It looks like $cccb_id is empty.
                            >>>
                            >>Try echoing this to the screen before you build your select statement.
                            >>>
                            >>P.S. Please don't top post. Thanks.
                            >>>
                            >>>
                            >
                            variable is not empty. As explained earlier this same sql script runs
                            fine if placed inside the php program. It is just when it is located
                            within the require "db.inc" file that the variable substitution does not
                            work.
                            >
                            Appreciate your top post request, but refuse to join the flat earth
                            society.
                            >
                            >
                            (Top posting fixed - again)
                            >
                            As I said - did you actually try to echo the variable to the screen to
                            see what's in it?
                            >
                            And if you don't follow normal usenet conventions, don't expect to get a
                            lot of help from this newsgroup. You're the one asking for help. You
                            should follow the established conventions.
                            >
                            So please don't top post. Or don't expect much for answers.
                            >

                            Comment

                            • Geoff Berrow

                              #15
                              Re: php variable in sql string

                              Message-ID: <mn4sh.762646$Q Z1.204364@bgtns c04-news.ops.worldn et.att.net>
                              from user contained the following:
                              >P.S. For you and Inkster. THE EARTH IS NOT FLAT!!! REALLY!! Any you
                              >saying it is does not make it so!
                              Posting in a sensible manner in a technical forum such as this is not
                              flat earth mentality.

                              Thinking it is marks you out as singularly clueless.

                              Fine if you want to solve your own problems.
                              --
                              Geoff Berrow (put thecat out to email)
                              It's only Usenet, no one dies.
                              My opinions, not the committee's, mine.
                              Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                              Comment

                              Working...