phpnewbie112 Posted June 19, 2008 Share Posted June 19, 2008 Hello, is it possible in php to assign a tag for a variable. for example. if I have $c1 = $row['tag1']; how can I assign %c1 so that when I insert %c1 into the textbox and save the value, it will be stored in MySql as the value itself and not as %c1 Link to comment https://forums.phpfreaks.com/topic/110864-reading-variables-into-textbox/ Share on other sites More sharing options...
lilwing Posted June 19, 2008 Share Posted June 19, 2008 What do you mean by tag? HTML tag? Please be more descriptive so I can help. Link to comment https://forums.phpfreaks.com/topic/110864-reading-variables-into-textbox/#findComment-568822 Share on other sites More sharing options...
Stephen Posted June 19, 2008 Share Posted June 19, 2008 I think he wants to do with "str_replace". Try doing: <?php $textbox=$_POST["textbox"]; //Your textbox name $tag="%c1"; $replace="C1TAG"; $new=str_replace($tag,$replace,$textbox); ?> If you want to crab tags from the mysql database, have the replacement and tag in the db and do a while loop with the tag/replace/new in it (tag would be like $row["tag"]; and replace would be $row["replace"]. Link to comment https://forums.phpfreaks.com/topic/110864-reading-variables-into-textbox/#findComment-568823 Share on other sites More sharing options...
phpnewbie112 Posted June 19, 2008 Author Share Posted June 19, 2008 let me explain it better. I have a table with the fields: name, email, tag1, tag2, tag3 in this table, for each name and email I have a different tag1, tag2 and tag3 values. I have another table "Messages", in the code when I query the 1st table and add manually the value inside the textbox it is successfuly stored inside the "Messages" table. but I need to be able to do the following: Dear 'name' you are kindly requested to contact mr 'tag1' before 'tag2' at time 'tag3' so how can I enter in the textbox Dear %c1 you are kindly request to contact mr %c2 before %c3 at %c4 and be able to store this sentence in the "Messages" with the REAL values. Hope it is clear and thanks for your reply Link to comment https://forums.phpfreaks.com/topic/110864-reading-variables-into-textbox/#findComment-568825 Share on other sites More sharing options...
Stephen Posted June 19, 2008 Share Posted June 19, 2008 For this you will need to enter what user you want to send this (assuming this is an email) to. <?php $_user=$_POST["user"]; //The user you want to send this to $_text=$_POST["textarea"]; //The message box $_sql_handle=mysql_connect("host","user","pass"); $_sql_db=mysql_select_db("db",$_sql_handle); $_sql_user=mysql_query("SELECT * FROM table WHERE name='".$_user."'"); while($_rows=mysql_fetch_array($_sql_user)) { $_db_name=$_rows["name"]; $_db_email=$_rows["email"]; $_db_tag1=$_rows["tag1"]; $_db_tag2=$_rows["tag2"]; $_db_tag3=$_rows["tag3"]; $_newtext=str_replace("%c1",$_db_name,$_text); $_newtext=str_replace("%c2",$_db_email,$_newtext); $_newtext=str_replace("%c3",$_db_tag1,$_newtext); $_newtext=str_replace("%c4",$_db_tag2,$_newtext); $_newtext=str_replace("%c5",$_db_tag3,$_newtext); } ?> %c1 = Users name %c2 = Users email %c3 = Tag one %c4 = Tag two %c5 = Tag three The new message will be "$_newtext". Link to comment https://forums.phpfreaks.com/topic/110864-reading-variables-into-textbox/#findComment-568842 Share on other sites More sharing options...
phpnewbie112 Posted June 19, 2008 Author Share Posted June 19, 2008 wow thanks a million it is working Link to comment https://forums.phpfreaks.com/topic/110864-reading-variables-into-textbox/#findComment-568880 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.