PHP and MySQL WHERE statement

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

  • Steven
    Guest replied
    Re: PHP and MySQL WHERE statement


    "JS Bangs" <jaspax@u.washi ngton.edu> wrote in message
    news:Pine.A41.4 .55.03070523292 40.87346@dante1 8.u.washington. edu...[color=blue]
    > Steven sikyal:
    >[color=green]
    > >
    > > "Cowfisher" <corpheous@yaho o.com> wrote in message
    > > news:93268ad9.0 307051640.63618 731@posting.goo gle.com...[color=darkred]
    > > > I can write simple MySQL stuff in PHP but I'm having problems putting
    > > > in WHERE clauses. Everytime I do I get errors like this:
    > > >
    > > > Parse error: parse error, unexpected T_ENCAPSED_AND_ WHITESPACE,
    > > > expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\program
    > > > files\apache group\apache\ht docs\vod\minera l_action.php on line 10
    > > >
    > > > The code that generated this crap is:
    > > >
    > > > $sql = "UPDATE character SET mining = $new_skill WHERE char_name =
    > > > $_SESSION['user']";
    > > > [snip][/color]
    > >
    > > Use double quote:
    > >
    > > $_SESSION["user"][/color]
    >
    > Don't do that. This will close your quote one one side of "user" and
    > reopen it one the other. It might compile (thought I doubt it), and it
    > might work because PHP assumes that barewords are single-quoted strings if
    > it can't figure out otherwise. It's still a very bad thing, though.
    >
    > What you want is to use no quotes at all:
    >
    > $sql = "UPDATE character SET mining = $new_skill WHERE char_name =
    > $_SESSION[user]";
    >
    > This is an exception to the normal parsing of variable names, but that's
    > how PHP does it inside a double-quoted string. This information is in the
    > manual somewhere, but I can never find it.
    >
    >
    > Jesse S. Bangs jaspax@u.washin gton.edu
    > http://students.washington.edu/jaspax/
    > http://students.washington.edu/jaspax/blog
    >
    > Jesus asked them, "Who do you say that I am?"
    >
    > And they answered, "You are the eschatological manifestation of the ground
    > of our being, the kerygma in which we find the ultimate meaning of our
    > interpersonal relationship."
    >
    > And Jesus said, "What?"[/color]

    Actually, I did this :

    previous statement". $_SESSION["user"]."after statment...

    It works, and I just tried it without the quote at all and it is also
    working :)

    Thanks for point that out.

    -Steven



    Leave a comment:


  • JS Bangs
    Guest replied
    Re: PHP and MySQL WHERE statement

    Steven sikyal:
    [color=blue]
    >
    > "Cowfisher" <corpheous@yaho o.com> wrote in message
    > news:93268ad9.0 307051640.63618 731@posting.goo gle.com...[color=green]
    > > I can write simple MySQL stuff in PHP but I'm having problems putting
    > > in WHERE clauses. Everytime I do I get errors like this:
    > >
    > > Parse error: parse error, unexpected T_ENCAPSED_AND_ WHITESPACE,
    > > expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\program
    > > files\apache group\apache\ht docs\vod\minera l_action.php on line 10
    > >
    > > The code that generated this crap is:
    > >
    > > $sql = "UPDATE character SET mining = $new_skill WHERE char_name =
    > > $_SESSION['user']";
    > > [snip][/color]
    >
    > Use double quote:
    >
    > $_SESSION["user"][/color]

    Don't do that. This will close your quote one one side of "user" and
    reopen it one the other. It might compile (thought I doubt it), and it
    might work because PHP assumes that barewords are single-quoted strings if
    it can't figure out otherwise. It's still a very bad thing, though.

    What you want is to use no quotes at all:

    $sql = "UPDATE character SET mining = $new_skill WHERE char_name =
    $_SESSION[user]";

    This is an exception to the normal parsing of variable names, but that's
    how PHP does it inside a double-quoted string. This information is in the
    manual somewhere, but I can never find it.


    Jesse S. Bangs jaspax@u.washin gton.edu



    Jesus asked them, "Who do you say that I am?"

    And they answered, "You are the eschatological manifestation of the ground
    of our being, the kerygma in which we find the ultimate meaning of our
    interpersonal relationship."

    And Jesus said, "What?"

    Leave a comment:


  • Steven
    Guest replied
    Re: PHP and MySQL WHERE statement


    "Cowfisher" <corpheous@yaho o.com> wrote in message
    news:93268ad9.0 307051640.63618 731@posting.goo gle.com...[color=blue]
    > I can write simple MySQL stuff in PHP but I'm having problems putting
    > in WHERE clauses. Everytime I do I get errors like this:
    >
    > Parse error: parse error, unexpected T_ENCAPSED_AND_ WHITESPACE,
    > expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\program
    > files\apache group\apache\ht docs\vod\minera l_action.php on line 10
    >
    > The code that generated this crap is:
    >
    > $sql = "UPDATE character SET mining = $new_skill WHERE char_name =
    > $_SESSION['user']";
    >
    > I do have my session correctly started and all that (I know this
    > mainly because I don't get error without the WHERE stuff and have
    > tested out the variable). I think I've tried everything under the sun
    > to try and get this working. This is in <? ?> as correctly needed
    > with PHP it's just something with the WHERE statements. I tried the
    > yahoo chat rooms but to no avail.
    >
    > Besides looking for help with this problem, can anyone refer me to a
    > good irc chat room for php problems that has ACTIVE (not filled with
    > lurkers) people in it?
    >
    > Thanks for your help![/color]

    Use double quote:

    $_SESSION["user"]

    -Steven


    Leave a comment:


  • Cowfisher
    Guest started a topic PHP and MySQL WHERE statement

    PHP and MySQL WHERE statement

    I can write simple MySQL stuff in PHP but I'm having problems putting
    in WHERE clauses. Everytime I do I get errors like this:

    Parse error: parse error, unexpected T_ENCAPSED_AND_ WHITESPACE,
    expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\program
    files\apache group\apache\ht docs\vod\minera l_action.php on line 10

    The code that generated this crap is:

    $sql = "UPDATE character SET mining = $new_skill WHERE char_name =
    $_SESSION['user']";

    I do have my session correctly started and all that (I know this
    mainly because I don't get error without the WHERE stuff and have
    tested out the variable). I think I've tried everything under the sun
    to try and get this working. This is in <? ?> as correctly needed
    with PHP it's just something with the WHERE statements. I tried the
    yahoo chat rooms but to no avail.

    Besides looking for help with this problem, can anyone refer me to a
    good irc chat room for php problems that has ACTIVE (not filled with
    lurkers) people in it?

    Thanks for your help!
Working...