I am trying to write to an additional table in the database. There is an auto-increment set for the product_id field and I would like to fetch the newly generated product_id that's created in the connection that I have set up in chronoforms and write that into the second table along with a category_id which will be pulled from the form.
Here is what I have right now in the "custom code - before email" section but I can't seem to get it to work:
I'm sure I'm not writing the code correctly but I have no idea what is incorrect... I keep trying different things but to no avail.
Can anyone help?
Matt
Here is what I have right now in the "custom code - before email" section but I can't seem to get it to work:
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$pid = mysql_query("SELECT mysql_insert_id(product_id) FROM c7stn_redshop_product");
$cat = mysql_real_escape_string($_POST[category_id]);
$sql="INSERT IGNORE INTO c7stn_redshop_product_category_xref (category_id, product_id)
VALUES
('$cat','$pid')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?>
I'm sure I'm not writing the code correctly but I have no idea what is incorrect... I keep trying different things but to no avail.
Can anyone help?
Matt