Replacing "Something" with SessionId

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
amit_tgo
Forum Newbie
Posts: 5
Joined: Thu Mar 18, 2004 10:03 am

Replacing "Something" with SessionId

Post by amit_tgo »

Hello,
I have a slight problem.
I shall explain the same with a example.

Say for example I have a value in a particular field of my database
"Hello Something How are you"

I can manage to print this value on the page without any problem.

The user has logged in and he receives the message "Hello Something How are you"

I wish to Replace the text "Something" with his login sessionid

<?echo "$userid";?> this helps me print the userid of the person logged in on the page.

However, i am clueless on how i could replace some text that am fetching from the database and then replacing the same to get the logged in userid.

Help Please

Regards
Amit
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Tried http://php.net/str_replace ?

Though i'm not sure why you're not just doing, echo 'Hello '.$userid.'. How are you?';
amit_tgo
Forum Newbie
Posts: 5
Joined: Thu Mar 18, 2004 10:03 am

Post by amit_tgo »

Hello Mark,
Thanks i saw the url and its of help, However am a total fool when it comes to php. The application am building is actually a code i found somewhere and am trying to modify the same :(

So i cant really figure out what to do. Could you provide me with a example that i would require. I can then make the neccessary changes to the script.

Sorry for the trouble

Regards
Amit
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Code: Select all

<?php
$thetext = 'Hello Something, How are you';
$userid = 'Fred';
echo str_replace('Something', $userid, $thetext);
//this outputs Hello Fred, How are you
?>
amit_tgo
Forum Newbie
Posts: 5
Joined: Thu Mar 18, 2004 10:03 am

Hello Mark

Post by amit_tgo »

Thanks,
But am a touch confused, the text "Hello Something How are you" is coming in from the database and printing on the page.

Will this still work with the same?

Do i need to just copy paste this code?
or is there someway to implement it

Thanks Again
Amit
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Well without seeing your exact code, it's hard to say exactly what you need to do. But the theory is the same. Maybe post the bit of code that does the "printing on the page" ?
amit_tgo
Forum Newbie
Posts: 5
Joined: Thu Mar 18, 2004 10:03 am

Post by amit_tgo »

<?

mysql_connect($server, $db_user, $db_pass)
or die ("Database CONNECT Error (line 18)");
$result75 = mysql_db_query($database, "select * from interactive where progid='$progid'and id =

'$id'")
or die ("Database INSERT Error line 19");
if (mysql_num_rows($result75))
{
print "<font face=arial><TABLE width=100% align=center>";
while ($qry = mysql_fetch_array($result75))
{

print "<tr><td>";
print "<textarea name = domain2 cols=60 rows=5>";

print $qry[text];

print "</textarea>";

}
print "</TABLE>";
print "</tr></td>";
print "<br><br>";

} } }
?>


That's the part

Thanks & Regards
Amit
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Well, the only place i can see it going is :
print $qry[text];

So try replacing that with :
echo str_replace('Something', $userid, $qry['text']);

But i'm still not 100% sure which vars ar what, eg where $userid comes from etc..but that looks like the place to be doing it.
amit_tgo
Forum Newbie
Posts: 5
Joined: Thu Mar 18, 2004 10:03 am

Post by amit_tgo »

ThankYou ThankYou ThankYou
is all i can say - You've solved my problem in 10 mins - something i took a weird 11 hours :P

Thanks Again Markl999

May God Bless
Regards
Amit
Post Reply