SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 30
  1. #1
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry Recently viewed products

    Hi
    I am having trouble writing code for a RECENTLY VIEWED PROPERTY LISTING for a estate Agency website.
    Please help

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    What exactly is the problem?

  3. #3
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What i want is like in E BAY ,which shows you the recent items,products viewed by the user.

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    I understand. But you say you're having problems with your code. So I immagine you've already written some code, but it isn't doing what you want. Post the code, explain what exactly is giving you trouble, and surely someone here will be able to help you.

    If you want the whole code written for you, you might want to take a look here.

  5. #5
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have created the database in phpadmin on local PC.

    <?php
    include 'db.inc';

    session_start();
    if(!$_SESSION['user_id']){
    $_SESSION['user_id'] = rand(1, 1000000);
    mysql_query('INSERT INTO product_recent (user_id) VALUES ('.$_SESSION['user_id'].')');
    }

    LINE 18 $productid = $_GET['user_id'];

    $query = 'SELECT * FROM product_recent WHERE user_id = '.$_SESSION['user_id'].'';
    $result = mysql_query($query);
    $row = mysql_fetch_array($result);
    mysql_query('UPDATE product_recent SET product_1="'.$productid.'", product_2="'.$row['product_1'].'", product_3="'.$row['product_2'].'" WHERE user_id="'.$_SESSION['user_id'].'"');
    ?>

    Error message: Notice: Undefined index: user_id in C:\xampp\htdocs\Amana new\testrecent.php on line 18

    Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Amana new\testrecent.php on line 22
    Last edited by chrisben; Apr 13, 2011 at 05:33. Reason: wANT TO SHOW WHERE IS LINE 18

  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    First error:
    You want to use $_GET['user_id']. Do you pass the variable user_id in the query string? That is, does the link to the script have ?user_id=value ?

    Second error:
    This indicates the query has finished with an error. Do an echo of $query and of mysql_error() in case of an error:
    Code:
    $query = 'SELECT * FROM product_recent WHERE user_id = '.$_SESSION['user_id'].'';
    $result = mysql_query($query) or die("mysql error" . mysql_error() . "in query: $query");

  7. #7
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks
    Changed code this is new error;
    Notice: Undefined index: user_id in C:\xampp\htdocs\Amana new\testrecent.php on line 18
    mysql errorNo database selectedin query: SELECT * FROM product_recent WHERE user_id = 983918

  8. #8
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    No database selected

    You didn't select a database. Or more probably, something went wrong connecting to the database.
    What does db.inc contain? Delete userid and password before posting that code here!

  9. #9
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Guido
    Is there another way off doing this without database ?
    Chris

  10. #10
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    No

  11. #11
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you
    Just busy sorting out the db.inc file to work.Wiil come back i have some more questions.
    How do i show the information on the page ?
    Chris

  12. #12
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My global.php file
    <?php
    $db = mysql_connect('localhost', 'root', 'chrisedit52');

    if (!$db) {
    echo "Unable to establish connection to database server";
    exit;
    }

    if (!mysql_select_db('amanatest', $db)) {
    echo "Unable to connect to database";
    exit;
    }
    ?>
    New error :Notice: Undefined index: user_id in C:\xampp\htdocs\Amana new\testrecent.php on line 18

    <?php
    include 'global.php';

    session_start();
    if(!$_SESSION['user_id']){
    $_SESSION['user_id'] = rand(1, 1000000);
    mysql_query('INSERT INTO product_recent (user_id) VALUES ('.$_SESSION['user_id'].')');
    }

    $productid = $_GET['user_id']; LINE 18
    $query = 'SELECT * FROM product_recent WHERE user_id = '.$_SESSION['user_id'].'';
    $result = mysql_query($query) or die("mysql error" . mysql_error() . "in query: $query");

    $result = mysql_query($query);
    $row = mysql_fetch_array($result);
    mysql_query('UPDATE product_recent SET product_1="'.$productid.'", product_2="'.$row['product_1'].'", product_3="'.$row['product_2'].'" WHERE user_id="'.$_SESSION['user_id'].'"');
    ?>

  13. #13
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,264
    Mentioned
    115 Post(s)
    Tagged
    1 Thread(s)
    Change $_GET['user_id'] to $_SESSION['user_id']

    $_GET is used where you're trying to get something off the querystring. Everywhere else on te page, you're working off the session user.
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  14. #14
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    New error on line 19

    Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\Amana new\testrecent.php on line 19

  15. #15
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Post the corrected code please. And put it between [php] tags (the end tag needs to be /php with [] around it).

  16. #16
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks
    Code:

    Code PHP:
    <?php
    include 'global.php';
     
    session_start();
    if(!$_SESSION['user_id']){
    $_SESSION['user_id'] = rand(1, 1000000);
    mysql_query('INSERT INTO product_recent (user_id) VALUES ('.$_SESSION['user_id'].')');
    }
    $productid =$_SESSION['user_id']
     
    $query = 'SELECT * FROM product_recent WHERE user_id = '.$_SESSION['user_id'].'';
    $result = mysql_query($query) or die("mysql error" . mysql_error() . "in query: $query");
     
    $result = mysql_query($query);
    $row = mysql_fetch_array($result);
    mysql_query('UPDATE product_recent SET product_1="'.$productid.'", product_2="'.$row['product_1'].'", product_3="'.$row['product_2'].'" WHERE user_id="'.$_SESSION['user_id'].'"');

    Do you mind if i proceed to morrow again,something came up
    Regards
    Chris

  17. #17
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Code PHP:
    $result = mysql_query($query) or die("mysql error" . mysql_error() . "in query: $query");
     
    $result = mysql_query($query);
    I don't know why you get that error, but there's one mysql_query() too much here
    If you need to see the mysql errors, keep the top one, otherwise keep the bottom one.

    Do you mind if i proceed to morrow again,something came up
    Of course not. You can come back when you want to. And if I'm not here, others will be, and I'm sure there will be someone to help you further.

  18. #18
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,264
    Mentioned
    115 Post(s)
    Tagged
    1 Thread(s)
    Remove the .'' at the end of the query.
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  19. #19
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi
    These are my database fields :
    user_id int(11) auto_increment
    product_1 varchar(100)
    product_2 varchar(100)
    product_3 varchar(100)
    time datetime (not functioning as yet

    I tested the page on live server,after rectifying errors .it uploads "user_id" data every time i reload page in browser,then i get this error:
    Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/stilbaai/public_html/testrecent.php:9) in /home/stilbaai/public_html/testrecent.php on line 12

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/stilbaai/public_html/testrecent.php:9) in /home/stilbaai/public_html/testrecent.php on line 12
    PRESENT CODE:
    <?php
    include 'global.php';

    LINE 12 session_start();
    if(!$_SESSION['user_id']){
    $_SESSION['user_id'] = rand(1, 1000000);
    mysql_query('INSERT INTO product_recent (user_id) VALUES ('.$_SESSION['user_id'].')');
    }
    $productid =$_SESSION['user_id'];

    $query = 'SELECT * FROM product_recent WHERE user_id = '.$_SESSION['user_id'];
    $result = mysql_query($query) or die("mysql error" . mysql_error() . "in query: $query");

    $result = mysql_query($query);
    $row = mysql_fetch_array($result);
    mysql_query('UPDATE product_recent SET product_1="'.$productid.'", product_2="'.$row['product_1'].'", product_3="'.$row['product_2'].'" WHERE user_id="'.$_SESSION['user_id'].'"');
    ?>
    I AM NOT fully understanding the code.At least the code uploads user_id to database.
    These numbers uploaded 98873,221870
    My ESTATE AGENT WEBSITE has different catogaries of houses (farms,plots,houses with images) each has it own page,must i add this code to each page with a seperate database for each.
    The PRODUCT_1 , PRODUCT_2 fields must capture the product description ?

    Thanks for your patients

  20. #20
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by chrisben View Post
    Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/stilbaai/public_html/testrecent.php:9) in /home/stilbaai/public_html/testrecent.php on line 12
    Move session_start() to the top of the script (before the include).
    I AM NOT fully understanding the code.
    That is a big problem. If you don't understand the code you're writing, who does?
    The PRODUCT_1 , PRODUCT_2 fields must capture the product description ?
    How would I know? You're the one that designed the database.
    By looking at those column names, it looks like there might be some more database normalization needed (if you don't know what that is, google for it ).

  21. #21
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Guido
    Sorry for this i will get myself more up to date.
    I have moved session_start() to above include still same error
    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/stilbaai/public_html/testrecent.php:8)
    Thank you

  22. #22
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Check for any output before the session_start. It might be an empty line, of even a space before the <?php tag.
    Another cause might be the BOM

  23. #23
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi
    I had the PHPH script between the BODY section of HTML ,i removed all of that and left only PHP the error is gone but DATABASE not adding user id /
    Thanks

  24. #24
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    You don't get any errors at all now?

    Then try adding some echo statements to follow the flow of the script. Echo variables you're interested in, do a print_r of $_SESSION to see what it contains.

  25. #25
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use Dreamweaver where do you set it ?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •