I seem to be having a problem in actually reading in a user id from a cookie and inserting this in to a database.
Any ideas here is the code I am trying to run without any success, although the other variables are being put in to the database ok:
<?
//Check for required fields
if ((!($sel_item)) || (!($sel_item_title)) || (!($sel_item_qty)) || (!($sel_item_price))) {
header("Location: http://www.aboutsuck.com/eshop/showcds.php");
exit;
}
if (!isset($user_id)) {
$token = md5(uniqid(rand()));
setcookie("user_id",$token,time()+86400,"/",".digitalbeatbox.com");
}
//create connection
$connection = mysql_connect("localhost", "username", "password") or die ("Sorry a connection to the server could not be established");
//select database
$db = mysql_select_db("username", $connection) or die ("Sorry a connection to the database could not be established");
//Calculate price
$sel_item_totalprice = $sel_item_qty * $sel_item_price;
//Format datestamp
$date_added = date("d-m-y");
//SQL statement to add record to tracking db
$sql = "INSERT INTO TRACKING VALUES(\"$user_id\", \"$sel_item\", \"$sel_item_title\", \"$sel_item_qty\", \"$sel_item_price\", \"$sel_item_totalprice\", \"$date_added\")";
//Execute SQL and exit if failure
$sql_result = mysql_query($sql, $connection) or die ("Sorry the query could not be executed");
?>