Need help with internal bookmarking

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
doddsey_65
Forum Newbie
Posts: 2
Joined: Thu May 21, 2009 5:59 pm

Need help with internal bookmarking

Post 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!
Last edited by Benjamin on Thu May 21, 2009 6:39 pm, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Need help with internal bookmarking

Post 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
Post Reply