In my functions.php, this code executes successfully (I've hidden my database info):
add_action("gform_post_submission_1", "set_post_content", 10, 2);
function set_post_content($entry, $form){
define("HOSTNAME","*****");
define("USERNAME","*****");
define("PASSWORD","*****");
define("DATABASE","*****");
$con = mysql_connect(HOSTNAME, USERNAME, PASSWORD);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
echo "do";
$sql="INSERT INTO user_items (user, item) VALUES ('1', '2')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
mysql_close($con);}
The form executes, my data gets entered, and my "do" is written to the form as expected. If I change the code to this:
add_action("gform_post_submission_1", "set_post_content", 10, 2);
function set_post_content($entry, $form){
define("HOSTNAME","*****");
define("USERNAME","*****");
define("PASSWORD","*****");
define("DATABASE","*****");
$con = mysql_connect(HOSTNAME, USERNAME, PASSWORD);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
echo "do";
$sql="INSERT INTO user_items (user, item) VALUES ($entry['created_by'], $entry['2'])";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
mysql_close($con);}
I get this error or a variation of it:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/63/6744963/html/wp-content/themes/CeCe3/functions.php on line 38
The line number of the error generaly doesn't point to anything meaningful.
Let me know if you need more info.
Posted 13 years ago on Friday August 19, 2011 |
Permalink