SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2000
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    I am trying to store the name $addusername to my database so that everytime someone signs-up then get a welcome message with their username is it.
    For example my test string is:
    Hi $addusername , Welcome to my page. I hope you find what you are looking for.

    $addusername is always different because it uses the username of the person who just signed up. However, when I am trying to get the string above from by database it doesn't translate $addusername to the actual username. It uses the EXACT thing written above. When I try echoing the $addusername variable right after I call the string, it shows the username just fine.

    Do I have to do something special when I take a variable name out of a database, or can I even do this?

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you need to eval the code so that it fills the vars with the correct values

    Code:
    $str = ${$strfromdb}
    
    print $str;
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2000
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can I do this to the whole long string or just the variable?

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The whole string, the new str $str will hold the long string with the vars filled in.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Zealot
    Join Date
    Oct 2000
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sweet...thanks!

  6. #6
    SitePoint Zealot
    Join Date
    Oct 2000
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It didn't seem to work...The $message variable was empty:


    $setmessage = mysql_query("SELECT * FROM welcome WHERE welcomeid= '1' ");

    $getmessage = mysql_fetch_array($setmessage);
    $dbmessage = $getmessage["welcome"];

    $message = ${$dbmessage};

    echo($message);

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Doh! I screwed that one up royally, sorry!
    You need eval()

    Code:
    $setmessage = mysql_query("SELECT * FROM welcome WHERE welcomeid= '1' "); 
    $getmessage = mysql_fetch_array($setmessage); 
    $dbmessage = $getmessage["welcome"]; 
    eval("\$message = \"$dbmessage\";"); 
    echo($message);
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Sausalito, Ca
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What are they signing up for? When they come back, do they sign in? If this is the case, then you need to keep a table of users in your database.

    When someone who has signed up returns to your site and signs in, it runs a query on the users database using the variable which is the name of the form field, in the query string to return information about that user.

    If it is a one time message though, where someone signs up, and then they recieve a message thanking them etc, then all you need do is echo the variable name (from the form filed) in your welcome message

    <form action="theNextPage.php" method="get">
    <input type="text" name="theName">
    <input type="submit" vaule='submit'>
    </form>

    // on the next page
    Welcome <? echo $theName ?>, I hope you find what you need.

  9. #9
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Sausalito, Ca
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    After reading your original post agian, it sounds like when you make the query to the database that you are not using a where clause, as you described getting the name of the last person who signed up. You need some way of identifying and extracting only the information that you want from your table. So to get back the user name of the person who is currently on your page you have to know who is currently on your page either by using cookies, or requiring them to sign in every time they visit. Then you can get that value, and use it as a where clause in your query.

    $query=mysql_query(SELECT * FROM usertable WHERE username='$login');
    $result=mysql_fetch_array($query);

    // $login being the name of your sign in form field, or the name stored in the cookie.

    This way you will get the row of data for that user in an array.

    Welcome back <? echo $result['username']?>. Thanks for returning to my site.

  10. #10
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually if you read it again. The template is stored in the database. He/She wants pull the template from the db and fill it accordingly. That is where eval() comes into play. Your way works for simple emails where you can just echo out the username from the form, but he needs to read the template in and rep[lace the vars in the tmeplate with vars from the form.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  11. #11
    SitePoint Zealot
    Join Date
    Oct 2000
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here Guys...you can take a first hand look...I do store the info in a database and retrive it and store it in a cookie.
    http://gamesdex.com

    BTW, I am a he...


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
  •