Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

SQL in PHP

DanyDany Posts: 26Member
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

  • satyadevsatyadev Posts: 11Member
    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


  • luhnthluhnth Posts: 78Member
    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

  • weapon__xweapon__x Posts: 138Member
    : $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

  • weapon__xweapon__x Posts: 138Member
    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

  • dreams17dreams17 Posts: 1Member
    [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.