Forums / General Questions / Im nearly there just need a bit of help

Im nearly there just need a bit of help

Locked

Started by doddsey_65 on 20 May 2009, 6:38 PM · Views: 861

Results 1 to 9 of 9
This thread is locked. New replies are disabled.
20 May 2009, 6:38 PM
#1
doddsey_65 avatar

doddsey_65

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

21 May 2009, 12:04 AM
#2
doddsey_65 avatar

doddsey_65

New Zenner

Join Date:
Jan 2009
Posts:
51
Plugin Contributions:
0

Re: Im nearly there just need a bit of help

Okay Ive done it. It automatically inserts the url into the database.

All I need now is a link on the page that does it when clicked instead of it being done automatically when the page is accessed.

Heres my code:

<?php 
error_reporting(E_ALL); 

$con = mysql_connect("host", "user", "pass") 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 $_SERVER['REQUEST_URI'].' ALREADY INSERTED';  
} 

mysql_close($con); 

?> 

Any ideas?

Cheers

21 May 2009, 1:35 AM
#3
mrchristoh avatar

mrchristoh

New Zenner

Join Date:
May 2009
Location:
from parts unknown
Posts:
74
Plugin Contributions:
0

Re: Im nearly there just need a bit of help

hi,

The problem is that once the PHP has loaded it can't all of a sudden do more php with the click of a link (unless you load a new page or the same page given new information.)

hope this helps?

21 May 2009, 1:41 AM
#4
doddsey_65 avatar

doddsey_65

New Zenner

Join Date:
Jan 2009
Posts:
51
Plugin Contributions:
0

Re: Im nearly there just need a bit of help

What I want though is to get rid of that and replace it within a link. I dont want that aswell as a link. I don't want it to automatically run i want it so that the cust can choose wether to run this query or not via a link.

21 May 2009, 1:42 AM
#5
mrchristoh avatar

mrchristoh

New Zenner

Join Date:
May 2009
Location:
from parts unknown
Posts:
74
Plugin Contributions:
0

Re: Im nearly there just need a bit of help

hi again,

** dirty way
have a popup (separate_page.php) that takes the url from the parent (your_page) and separate_page.php then does the work and this can be called from any page via a link

21 May 2009, 1:55 AM
#7
doddsey_65 avatar

doddsey_65

New Zenner

Join Date:
Jan 2009
Posts:
51
Plugin Contributions:
0

Re: Im nearly there just need a bit of help

I would rather use my code since it works and only needs a little modification to turn it into a link. If I used something else I would have to odify or create it.
Im thinking of something like:

echo '<a href=' . $query . '>' . 'Click to Bookmark' . '</a>'

but i don'tknow what $query should be to tie it in with the above code.

21 May 2009, 2:01 AM
#8
mrchristoh avatar

mrchristoh

New Zenner

Join Date:
May 2009
Location:
from parts unknown
Posts:
74
Plugin Contributions:
0

Re: Im nearly there just need a bit of help

Maybe throw it into the PHP community?

Getting advice on something that doesnt fall into 'zencart default function(s)' is an uphill task on this forum.

ive been asking for help with ajax.......with no luck (if that helps) LOL

21 May 2009, 5:11 AM
#9
doddsey_65 avatar

doddsey_65

New Zenner

Join Date:
Jan 2009
Posts:
51
Plugin Contributions:
0

Re: Im nearly there just need a bit of help

Mrchristoh:

hi again,

** dirty way
have a popup (separate_page.php) that takes the url from the parent (your_page) and separate_page.php then does the work and this can be called from any page via a link

I have tried calling bookmark.php from a link but thats no good because i am using the customers_id to insert the bookmark so that it is relevent to that customer. Calling it like that brings up 0 under customer id.