Jump to content

Quotation Marks on Session Variables


Larry101

Recommended Posts

Hi all... once again I am trying to re-educate my self into PHP after a long gap.

 

I do not have a problem as such just a question... here is part of my script that doesnot work;

 

<?

       $sql= "INSERT INTO member (

        username,
        email
    )
VALUES (
        \"$_SESSION['nm_username']\",
        \"$_SESSION['nm_email']\"


)";

?>

 

The above errors because there are single quotation marks in the session variables. When I remove them the script works and the values of the variables seem to be correct!

 

My question is - do I NEED the quotation marks in the variable and if so how should I write the query?

 

Regards

Link to comment
Share on other sites

Yes, you need the quotes around the SESSION[] elements.  You should also only use single quotes around sql strings.  your query should look like:

 $sql= "INSERT INTO member (
        username,
        email
    )
VALUES (
        '".$_SESSION['nm_username']."',
        '".$_SESSION['nm_email']."'
)";

 

using . to concatenate the string values with the variable contents.

Link to comment
Share on other sites

Yes, you need the quotes around the SESSION[] elements.  You should also only use single quotes around sql strings.  your query should look like:

 $sql= "INSERT INTO member (
        username,
        email
    )
VALUES (
        '".$_SESSION['nm_username']."',
        '".$_SESSION['nm_email']."'
)";

 

using . to concatenate the string values with the variable contents.

 

Thank you very much Muddy_Funster. I didn't feel comfortable leaving off the quotations.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.