Thread: Recommand it!

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    31
    Rep Power
    15
    Hi,

    I create a small script for refering a page to a friend.
    My probleme is to included the http_referer into the database
    At this time my script will put the name of the form "recommand.php3"
    into the database and not the one I want the "article002.html"

    Here's the essential line if someone know what
    I'm doing wrong please let me know!

    Recommend.php3
    ---------------

    <H3>Recommend this article to a friend!</H3>
    <?

    // Ok... I take the http_referer with no problem example; http://mydomain.com/article3422.html//
    $referer = getenv("HTTP_REFERER");
    print "URL of the page: $referer<P>";

    // Here's my simple form //

    IF ($action==""):

    <FORM METHOD=POST ACTION="<? echo "$PHP_SELF"; ?>">
    Your Name: <INPUT TYPE="text" NAME="name"><br>
    Your Email: <INPUT TYPE="text" NAME="email"><br>
    Friend's Name: <INPUT TYPE="text" NAME="friend_name"><br>
    Friend's Email: <INPUT TYPE="text" NAME="friend_email"><br>
    Additional Comments: <TEXTAREA NAME="comments" ROWS="3" COLS="30"></TEXTAREA><br>
    <INPUT TYPE="hidden" NAME="url" VALUE="<? echo "$referer"; ?>"><br>
    <INPUT TYPE="submit" NAME="action" VALUE="Send">
    </FORM>
    <?
    exit;
    ELSEIF ($action="Send"):

    $link = @mysql_connect("localhost", "root", "");
    mysql_select_db("recommande",$link);

    $dat = date("Y-m-d H:i:s");
    $query = "INSERT INTO recommande VALUES ('$name','$email','$friend_name','$friend_email','$comments','$referer','$dat')";
    $result = mysql_query($query);
    ?>
    // mail part and all the rest //
    <H3>Thank you!</H3> Your recommendation has been sent!
    ......................


    [This message has been edited by dalida (edited October 09, 2000).]
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Your need to place the line:

    $referer = getenv("HTTP_REFERER");

    and place it inside the if as it's getting reset after submission (which, of course, would be the page the form is on, IOW, itself).

    Placing it inside the if will prevent that and the original value of $referer will be stored.

    ---- OOPS----

    Just noticed you are passing it as 'url'. In that case, do as I said and change the hidden name to referer or change your query to insert $url instead of $referer

    [This message has been edited by rod k (edited October 09, 2000).]
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    31
    Rep Power
    15
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by dalida:
    Hi Rod,
    When I put the http_referer inside the if
    it does not print the http_referer info into my database. I tried to move it almost everywhere and I have the same result

    Regards!
    Dalida
    [/quote]

  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    That's not what I said.

    Change this line:

    $query = "INSERT INTO recommande VALUES ('$name','$email','$friend_name','$friend_email','$comments','$referer','$dat')";

    to this:

    $query = "INSERT INTO recommande VALUES ('$name','$email','$friend_name','$friend_email','$comments','$url','$dat')";
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    31
    Rep Power
    15
    I know, but it's still not working
  10. #6
  11. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Could be several things wrong.

    Check to see if the datatype for the field you are trying to insert the URL into will hold that value.

    If that doesn't help, cut and paste your entire code as it stands now (X-ing out any passwords etc) to this forum.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    31
    Rep Power
    15
    To make it simple I removed a lot of field just for testing.

    <H3>Recommend this article to a friend!</H3>
    <?
    $referer = getenv("HTTP_REFERER");
    print "URL of the page: $referer<P>";

    // Here's a simple form //

    IF ($action==""):

    <FORM METHOD=POST ACTION="<? echo "$PHP_SELF"; ?>">
    Your Name: <INPUT TYPE="text" NAME="name"><br>
    Your Email: <INPUT TYPE="text" NAME="email"><br>
    <INPUT TYPE="hidden" NAME="url" VALUE="<? echo "$referer"; ?>"><br>
    <INPUT TYPE="submit" NAME="action" VALUE="Send">
    </FORM>
    <?
    exit;
    ELSEIF ($action="Send"):

    $link = @mysql_connect("localhost", "root", "");
    mysql_select_db("recommande",$link);

    $dat = date("Y-m-d H:i:s");
    $query = "INSERT INTO test VALUES ('$name','$email','$referer','$dat')";
    $result = mysql_query($query);

    <H3>Thank you!</H3>
    ?>
  14. #8
  15. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    dalida,
    you may just try the following..
    i have changed couple of things in your script..


    <H3>Recommend this article to a friend!</H3>
    <?
    $referer = getenv("HTTP_REFERER");
    print "URL of the page: $referer<P>";
    // Here's a simple form //

    if (empty($action)){
    //user has not clicked on submit button
    ?>
    <FORM METHOD=POST ACTION="<? echo "$PHP_SELF"; ?>">
    Your Name: <INPUT TYPE="text" NAME="name"><br>
    Your Email: <INPUT TYPE="text" NAME="email"><br>
    <INPUT TYPE="hidden" NAME="url" VALUE="<? echo "$referer"; ?>"><br>
    <INPUT TYPE="submit" NAME="action" VALUE="Send">
    </FORM>
    <?
    exit;
    }elseif($action="Send"){

    $link = $mysql_connect("localhost", "root", "");
    mysql_select_db("recommande",$link);

    $dat = date("Y-m-d H:i:s");
    $query = "INSERT INTO test(name,email,referer,dat) VALUES ('$name','$email','$referer','$dat')";
    //change the coulmn names here as in the table(ie,name..)


    $result = mysql_query($query,$link);
    //issue query..

    if($result){
    //database updated
    echo "<H3>Thank you!</H3>";
    }else{
    //could not update the database..
    echo "Sorry!! Could not update the database";
    }
    }
    ?>


    ------------------
    SR -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "The fear of the LORD is the beginning of knowledge..."
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    31
    Rep Power
    15
    Thank you Shiju,

    You got the solution! Everything work fine, I am going to bed now

IMN logo majestic logo threadwatch logo seochat tools logo