Jump to content

reading variables into textbox


phpnewbie112

Recommended Posts

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"];).

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 :)

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".

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.