New Zenner
- Join Date:
- Jan 2009
- Posts:
- 51
- Plugin Contributions:
- 0
Im nearly there just need a bit of help
Okay i know I have already posted this but I didn't get any responses which leads me to believe i wordedit wrong so here goes.
I want it so that when a customer visits a page they can click on a link within that page that will store the pages url in a db table.
This will be recalled in their my account section so that they can just click on that link to go straight to that page.
Heres what I have so far. I have it so that the link is saved in the database and is recalled in the my account section. I can't however get it to stop inserting the link if it has already been inserted. This is leading to multiple inserts of the same link and since it is recalled in the my accounts section the page is cluttered with the same link. Heres my code:
<?php
$con = mysql_connect("host","user","pass");
if (!$con){
die('Could not connect: ' . mysql_error());}
mysql_select_db("database", $con);
$url= $_SERVER['REQUEST_URI'];
$currid = $_SESSION['customer_id'];
mysql_query("INSERT INTO
database_customers_favorites('customers_id', 'customers_favorites')
VALUES ($currid, $url)");
echo 'INSERTED';
mysql_close($con);
?>
That is what I am using to insert the link.
Here is what I tried to stop duplication. It doesnt work so if anyone has any ideas then please let me know. The code is:
<?php
$con = mysql_connect("host","user","pass");
if (!$con){
die('Could not connect: ' . mysql_error());}
mysql_select_db("database", $con);
$url= $_SERVER['REQUEST_URI'];
$currid = $_SESSION['customer_id'];
$searchurls = mysql_query("SELECT * FROM database_customers_favorites
('customers_favorites')
VALUES ($url)");
while($result=mysql_fetch_array($searchurls)){
if (!$url=$result){
mysql_query("INSERT INTO
database_customers_favorites('customers_id', 'customers_favorites')
VALUES ($currid, $url)");
echo 'INSERTED';
}
else
{
echo $url . 'ALREADY INSERTED';
}
}
mysql_close($con);
?>
Any help would be appreciated.
Thanks