Page 1 of 1

Need help with internal bookmarking

Posted: Thu May 21, 2009 6:05 pm
by doddsey_65
Okay I have some code that automatically inserts the current url into a database table. This is then recalled on my customers My Account section so that they can click the link and go straight to their favorite page. What I need is for the code to be inserted in to a hyperlink rather than being done automatically when the page loads. With me so far? Here is my code on the pages that can be bookmarked:

Code: Select all

 
<?php 
$con = mysql_connect("host", "user", "password") or die('Could not connect to host: '.mysql_error()); 
mysql_select_db("database", $con) or die('Could not select database: '.mysql_error()); 
$sql = sprintf("SELECT customers_favorites FROM database_customers_favorites WHERE customers_favorites = '%s'", mysql_real_escape_string
 
($_SERVER['REQUEST_URI'], $con)); 
$result = mysql_query($sql, $con); 
if(!$result) 
{ 
    die('Invalid query: '.mysql_error()); 
} 
if(mysql_num_rows($result) == 0) 
{ 
    $sql = sprintf("INSERT INTO database_customers_favorites (customers_id, customers_favorites) VALUES (%d, '%s')", 
 
mysql_real_escape_string($_SESSION['customer_id'], $con), mysql_real_escape_string($_SERVER['REQUEST_URI'], $con)); 
    if(mysql_query($sql, $con)) 
    { 
        echo 'INSERTED'; 
    } 
    else 
    { 
        die('Invalid query: '.mysql_error()); 
    } 
} 
else 
{ 
    echo 'ALREADY INSERTED';  
} 
mysql_close($con); 
?> 
 

I have tried to call it in a seperate file by doing:

<a href=bookmark.php> which in theory would work, i think, but i am using the current customers id to insert it into the correct database table and if i call it externally then it doesnt pull their id.

Does anyone know how i could put this code into a link? I am not that good with php, i know the basics, so I may need some detail in the reply.

Thanks!

Re: Need help with internal bookmarking

Posted: Fri May 22, 2009 4:32 pm
by Darhazer
Where you are starting the session?
Probably it is started elsewhere in the code, and when you are cuting and pasting this code in another file, you forget to start the session, and because of this the customerID is missing