Jump to content

Insert session query


thefollower

Recommended Posts

I have an insert query which is inputting a sentence but some of the sentence is created with session carrying a value and i think its what is causing my syntax error with my insert....

 

 

<?php
$InsetLog = mysql_query("INSERT INTO userlogs (UserID, Log)
VALUES ('{$_SESSION['Current_User']}', 'Trained '{$_SESSION['GainedStrength']}' strength giving them $Strength total strength')")
or die(mysql_error());
?>

 

 

The error I get is:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0.064' strength giving them 6.4285 total strength')' at line 2
Link to comment
Share on other sites

Your problem is the single quotes that are around the "'GainedStrength'" value. You have a single quote right before "Trained" which begins the second value, but then there is a second single quote right after that which closes the second value.

 

<?php
$query = "INSERT INTO userlogs (UserID, Log)
          VALUES ('{$_SESSION['Current_User']}', 'Trained {$_SESSION['GainedStrength']} strength giving them $Strength total strength')";
$InsetLog = mysql_query($query) or die(mysql_error());
?>

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.