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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.