text transfer from db table

ok, what i’m trying to accomplish is this:

I’m creating an email template system for our admin area support system. What i’m trying to do is have variables that when used will represent different things, %user% will be the user’s name and so on. I know how to do this part.

What i need help with, is how to get that template transferred from a drop down box, information exchanged and then appear in a text area box. Then all the person has to do is hit submit.

I’ve never really used javascript outside of code i’ve gotten from other sites, so any help on this would be greatly appreciated. I don’t have any code to post of yet, but as of now, its all straight php and html/css. I haven’t done the template part since i haven’t had any real time to sit down and get the db table setup for it. I plan on doing this stuff tomorrow, thanks to this rain/wind storm that decided to roll in today.

Any thoughts on how to accomplish would be helpful.

ok, well i got the replacement thing going here. Don’t know if it’ll work yet since i can’t really test it until i can get it to appear in the textarea. but here’s what i have for code:
[php]
if(isset($_POST[‘Answer’])) {
$id = $_POST[‘id’];
$req_id = $_POST[‘req_id’];

$find = mysql_query("SELECT * FROM venzo_contactus WHERE id = '$id'");
$f = mysql_fetch_assoc($find);

if(!empty($r['last_answered_by'])){ 
	if(strstr($r['last_answered_by'],$_SESSION['adminname'])){ 
		$temp = explode(', ',$r['last_answered_by']); 
		$temp = array_filter($temp,filterArray); 
		$str = implode(', ', $temp); 
		$str .= ', '.$_SESSION['adminname']; 
	} else { 
		$str = $f['last_answered_by'].", ".$_SESSION['adminname'];
	}
} else {
	$str = $_SESSION['adminname']; //Just have it one its own 
}

$status = 3;

//for default answer
$uname = $_POST['u_name'];
$aname = $_POST['a_name'];

//replace template variables
$mtemp = explode(" ", $_POST['answer']);
$find = array("%name%", "%admin%");

if(in_array($find, $mtemp)) {
	$replace = array($uname, $aname);
	$sub = str_replace($find, $replace, $_POST['answer']);
}

if(empty($r['answer'])) {
	$ansr = add_slashes_recursive($_POST['n_answer']);
	$up = mysql_query("UPDATE venzo_contactus SET last_answered_by = '$str', answer = '$ansr', status = $status WHERE id = $id AND req_id = '$req_id'") or exit(mysql_error());
} else {
	$ansr = '\r\n'.add_slashes_recursive($_POST['n_answer']);
	$up = mysql_query("UPDATE venzo_contactus SET last_answered_by = '$str', answer = CONCAT(`answer`, '{$ansr}'), status = $status WHERE id = $id AND req_id = '$req_id'") or exit(mysql_error());
	//SET message = CONCAT(`message`, '{$mess}'),
}

if($up) {
	$suc = $f['subject']." has been successfully updated.<br />An email has been dispatched to ".$f['name'].", notifying the user that their question has been answered.";
	$end = 1;
	
	$headers = 'From: [email protected]' . "\r\n";
	$headers .= 'X-Mailer: PHP/' . phpversion();
	$headers .= "MIME-Version: 1.0\r\n";
	$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
	
	$t = explode("\n", $_POST['n_answer']);
	$put = end($t);
	
	//Venzo Support [ID] [Topic]
	$sub = "Venzo Support Request ID: ".$f['req_id']."";
	$message = "
	<html>
	<body>
	$f[subject] has been replied to by $_COOKIE[adminuser].<br />
	Your answer is below:<br />".
	strip_slashes_recursive($put)
	."<br /><br />
	Please use this <a href='http://vmg.venzodigital.com/public_check_inquiries.php?req_id=$req_id'>link</a> to reply.
	</body>
	</html>";
	
	mail($f['email'], $sub, $message, $headers);
}

}
[/php]

Well, looks good so far, except inside your $message = section. You have variables which will not be processed. There are PHP variables inside your quotes that will not be processed. Look at your f-subject and cookie code. It will never be processed as far as I see.

Get that fixed up, test and post any problems you find. Wasn’t sure of your note about javascript. Are you needing help creating code to dynamically load PHP code onto a page? Update us on your progress…

oh, talking about that commented out line? yea i know, i was troubleshooting the line above it, i was just making sure that the format was right. I usually delete it once i get it working.

as for the javascript, i basically want the person responding to the inquiry to be able to select the response from a dropdown list, then have that message appear in a textarea box (code below).

<form action="" method="post">
	<div style="float: left; width: 90px; margin: 0 auto;">
		<input type="submit" name="close" value="close message" />
	</div>
	<div style="float: right; width: 100px;">
		<input type="button" name="select" value="Select" />
	</div>
	<div style="float: right; width: 100px;">
		<select name="danswer">
		<?php
		$ans = mysql_query("SELECT * FROM venzo_contactus_answers") or die(mysql_error());
		while($row = mysql_fetch_array($ans)) {
			echo "<option value='$row[id]'>$row[name]</option>";
		}
		?>
		</select>
	</div>
	<input type="hidden" name="id" value="<?=$id?>" />
	<input type="hidden" name="req_id" value="<?=$r['req_id']?>" />
	<input type="hidden" name="u_name" value="<?=$r['name']?>" />
	<input type="hidden" name="a_name" value="<?=$_SESSION['adminname']?>" />
</form>
<div style="clear: both;"> </div>
<form action="" method="post">
	<input type="hidden" name="id" value="<?=$id?>" />
	<input type="hidden" name="req_id" value="<?=$r['req_id']?>" />
	<textarea style="width: 100%;" rows="12" name="n_answer"><?=nl2br(strip_slashes_recursive($r['answer']))?></textarea>
	<div align="center" style="width: 100%;"><input type="submit" name="Answer" value="Answer" /></div>
</form>

No, I was talking further down where you actually create your message. It will not include the PHP variables.

As far as Javascript goes, I assume you are looking for something like this demo:
http://remysharp.com/wp-content/uploads/2007/09/select-chain.php

If so, here is their explanation of how to do it:
http://remysharp.com/2007/09/18/auto-populate-multiple-select-boxes/

I think that will help you. It works well… Good luck…

I’ll take a look at the links.
your talking about this:
[php]
$message = "

$f[subject] has been replied to by $_COOKIE[adminuser].
Your answer is below:
".strip_slashes_recursive($put)."

Please use this link to reply. ";[/php]?

The message works just fine. the variables will work as long as its inside double quotes.

I had a look at that demo link - nothing happens

This is more like what i’m trying to do - http://www.dynamicdrive.com/forums/archive/index.php/t-29405.html, except my pulldown box is dynamically created and it would have to run a query to get the corresponding default answer. so like right now there’s just 1 message (Registration). So if i selected that, upon me clicking or onChange, the message

Hi %name%,

Please provide me with the following: Label Name (Artist Name if Unsigned), PayPal E-mail, and Country.

From there we’ll go ahead and create your account so you can begin uploading your music to iTunes.

Please let us know if you have any questions - %admin%

would appear in the textarea box.

I gave you the answer in the links I sent.

It shows how to do dynamic loading of ANY field. You just have to change the last dropdown(s) to a textarea and it will load it. You have to alter the code to fit whatever you want to show in the textarea. I used this to dynamically load data saved in a database into a textarea and it works just fine. I am sure you can alter their samples to fill your textarea.

If not, show us what you have done and we can help… I have seen your replies to others and know you should be able to figure this out. Let us know if not…

I did some research on ajax and mysql and think i’ve come up with a solution. My problem was how to get the selected response into the textarea. I’m working on that now and will update the code once i hit another roadblock.

Sounds good… If no roadblocks, then great! If some, post away… Good luck.

lol, i quickly hit a big roadblock. Having no experience with ajax, i’m at a loss as to what’s going on here.
my ajax capture. I was using the tutorial from http://www.tizag.com/ajaxTutorial/ajax-mysql-database.php, which before it crapped out, wasn’t exactly known for having accurate tutorials.

[code]

[/code]

ajax_query.php
[php]

<?php include 'config.php'; $id = mysql_real_escape_string($_GET['a_id']); $qry = mysql_query("SELECT danswer FROM venzo_contactus_answers WHERE id = $id") or die(mysql_error()); $row = mysql_fetch_assoc($qry); $display_string = $row['danswer']; echo $display_string; ?>

[/php]

the form

<form action="" method="post" name="myform">
	<div style="float: left; width: 90px; margin: 0 auto;">
		<input type="submit" name="close" value="close message" />
	</div>
						
	<div style="float: right; width: 100px;">
		<select name="danswer" id="danswer" >
		<?php
		$ans = mysql_query("SELECT * FROM venzo_contactus_answers") or die(mysql_error());
		while($row = mysql_fetch_array($ans)) {
		echo "<option value='$row[id]'>$row[name]</option>";
		}
		unset($row);
		?>
		</select>
	</div>
	<div style="float: right; width: 100px;">
		<input type="button" id="a_select" name="select" value="Select" onclick="ajaxFunction"/>
	</div>
		<input type="hidden" name="id" value="<?=$id?>" />
		<input type="hidden" name="req_id" value="<?=$r['req_id']?>" />
		<input type="hidden" name="u_name" value="<?=$r['name']?>" />
		<input type="hidden" name="a_name" value="<?=$_SESSION['adminname']?>" />
						
	</form>
	<div style="clear: both;"> </div>
	<form action="" method="post" name="myforma" >
		<input type="hidden" name="id" value="<?=$id?>" />
		<input type="hidden" name="req_id" value="<?=$r['req_id']?>" />
		<div id="d_answer"></div>
		<textarea style="width: 100%;" rows="12" name="n_answer" id="n_answer"><?=nl2br(strip_slashes_recursive($r['answer']))?></textarea>
		<div align="center" style="width: 100%;"><input type="submit" name="Answer" value="Answer" /></div>
	</form>

I dont’ know if its from having 2 different forms or what, but nothing happens when i click on select.

Well, when you call a function that has the format “ajaxfunction()” You must call it with “ajaxfunction();” in the ONCLICK. So, I think this is the problem. ONCLICK=“ajaxfunction();”

Let us know if that gets it working. And, if it throws an error, post the error also… Good luck.

yea i caught that, didn’t work when i fixed it.

Well, do us a favor… In the form once it is up in a browser, RIGHT-CLICK on it and select VIEW-SOURCE.
Then, paste the code here. This will show us exactly what the code looks like AFTER the PHP code. It should show up any javascript- calling errors and might help sort this out.

Thanks…

I got it working. I was missing the ; in the function call and i had to comment out document.myform.time.value = ajaxRequest.responseText;

thanks for the help

Glad you solved it… Good luck…

Sponsor our Newsletter | Privacy Policy | Terms of Service