SQL in PHP

Hello,
Can someone help me, I hope this is the right place for it.
I am trying to write sql queries in php and they are not working. I am pretty sure it's a quote double quote thing, which confuses me. can someone explain. I tried add/removeslashes() but they don't seem to help. would appreciate an example. this is what I am trying to write:
$query='update our_guests set username ='.$userid.' where guest ID = '.$id; (something like that anyways)
where $userid and $id are variables, and username is a field. I manage other SQL statements which are hardcoded so it must be a quote thing. Thanks!!

Comments

  • Hi,
    I think you have to write sql qury as following :

    $query='update our_guests set username = $userid where guest ID = $id;
    because $userid and $id is variable so no need to quote , when you are try to insert a hardcode string value then only you need to put quote.

    I hope this is help.

    With regards,
    Satyadev Singh


  • Try this:

    [code]
    $query="UPDATE `our_guests` SET `username` ='".$userid."' WHERE `guest ID` = '".$id."'";
    [/code]

    I was having trouble with that when I first started PHP and SQL. Some servers require you to do that. Oh yeah, next time, go to the SQL or the PHP message board, not the Apache board.


    Best Regards,
    CodeKing

  • : $query='update our_guests set username = $userid where guest ID = $id;


    this i think should read as:::>

    : $query='update our_guests set username = $userid where guest ID = $id';


    it happens...


    baboy... baboy...

    weaps

  • or better yet try this:::>

    $query="update our_guests set username ='" . $userid . "' where guest ID ='" . $id . "';";
    that is, as i assume, if both fields are text and ID is not numeric.


    baboy... baboy...

    weaps

  • [b][red]This message was edited by dreams17 at 2007-4-4 4:18:51[/red][/b][hr]

    Hi,
    i don know anything about php but then seeing ur query i was troubled.
    why do u break ur head in all these?just my opinion






    : Hello,
    : Can someone help me, I hope this is the right place for it.
    : I am trying to write sql queries in php and they are not working. I am pretty sure it's a quote double quote thing, which confuses me. can someone explain. I tried add/removeslashes() but they don't seem to help. would appreciate an example. this is what I am trying to write:
    : $query='update our_guests set username ='.$userid.' where guest ID = '.$id; (something like that anyways)
    : where $userid and $id are variables, and username is a field. I manage other SQL statements which are hardcoded so it must be a quote thing. Thanks!!
    :





Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories