Jump to content

Convert an input into a textarea?


okrobie

Recommended Posts

Hello, this line retrieves information from the database and allows me to edit it and save it and it works great so far. But now I need it to be a textarea. I tried a straight conversion but it replaced the database data with, "value=undefined". I read somewhere that "value" is not allowed in a textarea. Can someone please help me? Thanks, okrobie

 

Teacher: <input name="teacher<?php echo $rrows['id']; ?>" id="teacher<?php echo $rrows['id']; ?>" type="text" size="10" value="<?php echo $rrows['teacher']; ?>" >

Link to comment
Share on other sites

Thanks pbs, but my problem goes deeper than that.

 

Thanks isedeasy, that looks like it should work but it doesn't retrieve the data from the database and displays "undefined" instead. It also won't allow me to edit or save from that textbox. Please see if you can see what is wrong. Thanks again, okrobie

Link to comment
Share on other sites

Hello isedeasy, thanks for your help. Sorry for the delay I have been at my day job.

 

This code has a lot of extraneous garbage in it but I don't know what is important and what is not so I'll post the whole thing.

 

<?php 
include 'dbc.php';
page_protect();

if(!checkAdmin()) {
header("Location: login.php");
exit();
}

$page_limit = 10; 


$host  = $_SERVER['HTTP_HOST'];
$host_upper = strtoupper($host);
$login_path = @ereg_replace('adminsettings','',dirname($_SERVER['PHP_SELF']));
$path   = rtrim($login_path, '/\\');

// filter GET values
foreach($_GET as $key => $value) {
$get[$key] = filter($value);
}

foreach($_POST as $key => $value) {
$post[$key] = filter($value);
}

if($post['doBan'] == 'Ban') {

if(!empty($_POST['u'])) {
foreach ($_POST['u'] as $uid) {
	$id = filter($uid);
	mysql_query("update users set banned='1' where id='$id'");
}
}
$ret = $_SERVER['PHP_SELF'] . '?'.$_POST['query_str'];;

header("Location: $ret");
exit();
}

if($_POST['doUnban'] == 'Unban') {

if(!empty($_POST['u'])) {
foreach ($_POST['u'] as $uid) {
	$id = filter($uid);
	mysql_query("update users set banned='0' where id='$id'");
}
}
$ret = $_SERVER['PHP_SELF'] . '?'.$_POST['query_str'];;

header("Location: $ret");
exit();
}

if($_POST['doDelete'] == 'Delete') {

if(!empty($_POST['u'])) {
foreach ($_POST['u'] as $uid) {
	$id = filter($uid);
	mysql_query("delete from users where id='$id'");
}
}
$ret = $_SERVER['PHP_SELF'] . '?'.$_POST['query_str'];;

header("Location: $ret");
exit();
}

if($_POST['doApprove'] == 'Approve') {

if(!empty($_POST['u'])) {
foreach ($_POST['u'] as $uid) {
	$id = filter($uid);
	mysql_query("update users set approved='1' where id='$id'");

list($to_email) = mysql_fetch_row(mysql_query("select user_email from users where id='$uid'"));	

$message = 
"Hello,\n
Thank you for registering with the Holy Family Catholic School website. Your account has been activated...\n

*****LOGIN LINK*****\n
http://$host$path/login.php

Thank You

Administrator
$host_upper
______________________________________________________
THIS IS AN AUTOMATED RESPONSE. 
***DO NOT RESPOND TO THIS EMAIL****
";

@mail($to_email, "HFCS User Activation", $message,
    "From: \"HFCS Website Registration\" <auto-reply@$host>") ;
    

}
}

$ret = $_SERVER['PHP_SELF'] . '?'.$_POST['query_str'];	 
header("Location: $ret");
exit();
}

$rs_all = mysql_query("select count(*) as total_all from users") or die(mysql_error());
$rs_active = mysql_query("select count(*) as total_active from users where approved='1'") or die(mysql_error());
$rs_total_pending = mysql_query("select count(*) as tot from users where approved='0'");						   

list($total_pending) = mysql_fetch_row($rs_total_pending);
list($all) = mysql_fetch_row($rs_all);
list($active) = mysql_fetch_row($rs_active);


?>
<html>
<head>
<title>Admin Control Panel</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style2.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/javascript" src="js/jquery-1.3.2.min.js"></script>

</head>

<body>
<div id="container">

<table width="100%" border="0" cellpadding="5" cellspacing="0" class="myaccount">
        <tr>
          <td>Total users: <?php echo $all;?></td>
          <td>Active users: <?php echo $active; ?></td>
          <td>Pending users: <?php echo $total_pending; ?></td>
        </tr>
      </table>
<table width="100%" border="0" cellspacing="0" cellpadding="45" >
  <tr>
    <td width="14%" valign="top"><?php
if (isset($_SESSION['user_id'])) ?>


  


    <td width="74%" valign="top" style="padding: 10px;"><h2><font color="#FF0000">Administration 
        Page</font></h2>
      
      <!-- Begin Sidebar -->
	<div id="sidebar">
		<ul>

			<li><a href="defaultusers.php">Home</a></li>
			<li><a href="email.php">Email all users</a></li>
			<li><a href="logout.php">Logout</a></li>

		</ul>
	</div>
	<!-- End Sidebar -->

      <p><?php 
  if(!empty($msg)) {
  echo $msg[0];
  }
  ?></p>
      <table width="80%" border="0" align="center" cellpadding="10" cellspacing="0" style="background-image: url('images/mission background.jpg'); background-color: #FFCC00;padding: 2px 5px;border: 1px solid #CAE4FF;" >
        <tr>
          <td><form name="form1" method="get" action="adminsettings.php">
              <p align="center">Search 
                <input name="q" type="text" id="q" size="40">
                <br>
                [Type email or user name] </p>
              <p align="center"> 
                <input type="radio" name="qoption" value="pending">
                Pending users 
                <input type="radio" name="qoption" value="recent">
                Recently registered 
                <input type="radio" name="qoption" value="banned">
                Banned users <br>
                <br>
                [You can leave search blank to if you use above options]</p>
              <p align="center"> 
                <input name="doSearch" type="submit" id="doSearch2" value="Search">
              </p>
              </form></td>
        </tr>
      </table>
      <p>
        <?php if ($get['doSearch'] == 'Search') {
  $cond = '';
  if($get['qoption'] == 'pending') {
  $cond = "where `approved`='0' order by date desc";
  }
  if($get['qoption'] == 'recent') {
  $cond = "order by date desc";
  }
  if($get['qoption'] == 'banned') {
  $cond = "where `banned`='1' order by date desc";
  }
  
  if($get['q'] == '') { 
  $sql = "select * from users $cond"; 
  } 
  else { 
  $sql = "select * from users where `user_email` = '$_REQUEST[q]' or `user_name`='$_REQUEST[q]' ";
  }

  
  $rs_total = mysql_query($sql) or die(mysql_error());
  $total = mysql_num_rows($rs_total);
  
  if (!isset($_GET['page']) )
	{ $start=0; } else
	{ $start = ($_GET['page'] - 1) * $page_limit; }
  
  $rs_results = mysql_query($sql . " limit $start,$page_limit") or die(mysql_error());
  $total_pages = ceil($total/$page_limit);
  
  ?>
      <p>Approve -> A notification email will be sent to user notifying activation.<br>
        Ban -> No notification email will be sent to the user. 
      <p><strong>*Note: </strong>Once the user is banned, he/she will never be 
        able to register new account with same email address. 
      <p align="right"> 
        <?php 
  
  // outputting the pages
	if ($total > $page_limit)
	{
	echo "<div><strong>Pages:</strong> ";
	$i = 0;
	while ($i < $page_limit)
	{


	$page_no = $i+1;
	$qstr = ereg_replace("&page=[0-9]+","",$_SERVER['QUERY_STRING']);
	echo "<a href=\"adminsettings.php?$qstr&page=$page_no\">$page_no</a> ";
	$i++;
	}
	echo "</div>";
	}  ?>
	</p>
	<form name "searchform" action="adminsettings.php" method="post">
        <table width="100%" border="0" align="center" cellpadding="2" cellspacing="0">
          <tr bgcolor="#E6F3F9"> 
            <td width="4%"><strong>ID</strong></td>
            <td width="10%"><strong>Date</strong></td>
            <td width="10%"><div align="center"><strong>First Name</strong></div></td>
		<td width="10%"><div align="center"><strong>Last Name</strong></div></td>
            <td width="10%"><div align="center"><strong>User Name</strong></div></td>
            <td width="25%"><strong>Email</strong></td>
            <td width="5%"><strong>Approval</strong></td>
            <td width="5%"> <strong>Banned</strong></td>
            <td width="15%"> </td>

          </tr>
          <tr> 
            <td> </td>
          </tr>
          <?php while ($rrows = mysql_fetch_array($rs_results)) {?>
          <tr> 
            <td><input name="u[]" type="checkbox" value="<?php echo $rrows['id']; ?>" id="u[]"></td>
            <td><?php echo $rrows['date']; ?></td>
            <td> <div align="center"><?php echo $rrows['first_name'];?></div></td>
		<td> <div align="center"><?php echo $rrows['last_name'];?></div></td>
		<td> <div align="center"><?php echo $rrows['user_name'];?></div></td>
            <td><?php echo $rrows['user_email']; ?></td>
            <td><span id="approve<? echo $rrows['id']; ?>"> <?php if(!$rrows['approved']) { echo "Pending"; } else {echo "Active"; }?></span> </td>
            <td><span id="ban<? echo $rrows['id']; ?>"> <?php if(!$rrows['banned']) { echo "no"; } else {echo "yes"; }?>
              </span> </td>
            <td> <font size="2">
              <a href="javascript:void(0);" onclick='$.get("do.php",{ cmd: "approve", id: "<? echo $rrows['id']; ?>" } ,function(data){ $("#approve<? echo $rrows['id']; ?>").html(data); });'>Approve</a> 
              <a href="javascript:void(0);" onclick='$.get("do.php",{ cmd: "ban", id: "<? echo $rrows['id']; ?>" } ,function(data){ $("#ban<? echo $rrows['id']; ?>").html(data); });'>Ban</a> 
              <a href="javascript:void(0);" onclick='$.get("do.php",{ cmd: "unban", id: "<? echo $rrows['id']; ?>" } ,function(data){ $("#ban<? echo $rrows['id']; ?>").html(data); });'>Unban</a> 
              <a href="javascript:void(0);" onclick='$("#edit<?php echo $rrows['id'];?>").show("slow");'>Edit</a> 
              </font> </td>
          </tr>
          

          <tr> 
            <td colspan="7">

		<div style="display:none;font: normal 11px arial; padding:10px; background: #e6f3f9" id="edit<?php echo $rrows['id']; ?>">
		<form name="edit<?php echo $rrows['id']; ?>" action="" method="get"> 
		<input type="hidden" name="id<?php echo $rrows['id']; ?>" id="id<?php echo $rrows['id']; ?>" value="<?php echo $rrows['id']; ?>"><br>
		First Name: <input name="first_name<?php echo $rrows['id']; ?>" id="first_name<?php echo $rrows['id']; ?>" type="text" size="10" value="<?php echo $rrows['first_name']; ?>" >
		Last Name: <input name="last_name<?php echo $rrows['id']; ?>" id="last_name<?php echo $rrows['id']; ?>" type="text" size="10" value="<?php echo $rrows['last_name']; ?>" >
		User Name: <input name="user_name<?php echo $rrows['id']; ?>" id="user_name<?php echo $rrows['id']; ?>" type="text" size="10" value="<?php echo $rrows['user_name']; ?>" >
		<br><br>
		User Email:<input id="user_email<?php echo $rrows['id']; ?>" name="user_email<?php echo $rrows['id']; ?>" type="text" size="30" value="<?php echo $rrows['user_email']; ?>" >
		Level: <input id="user_level<?php echo $rrows['id']; ?>" name="user_level<?php echo $rrows['id']; ?>" type="text" size="5" value="<?php echo $rrows['user_level']; ?>" > 1->Parent,2->Teacher,5->Admin
		<br><br>
		New Password: <input id="pass<?php echo $rrows['id']; ?>" name="pass<?php echo $rrows['id']; ?>" type="text" size="20" value="" > (leave blank)

		<!--Teacher<span class="example"></span><br> 
              <textarea name="teacher" cols="80" rows="5"  id="teacher"><? echo $row_settings['teacher']; ?></textarea> -->
           
		<!--Teacher: <input name="teacher<?php echo $rrows['id']; ?>" id="teacher<?php echo $rrows['id']; ?>" type="text" size="10" value="<?php echo $rrows['teacher']; ?>" >-->

		<br>Teacher:<textarea name="teacher<?php echo $rrows['id']; ?>" id="teacher<?php echo $rrows['id']; ?>" rows="5" cols="80"><?php echo $rrows['teacher']; ?></textarea>
		<!--Teacher:<br>  <textarea name="teacher<?php echo $rrows['id']; ?>" id="teacher<?php echo $rrows['id']; ?>" cols="80" rows="5"   >   </textarea><br><br>-->
		Homework: <br> <textarea name="homework<?php echo $rrows['id']; ?>" cols="80" rows="5"  id="homework<?php echo $rrows['id']; ?>">   </textarea><br><br>
		Projects: <br> <textarea name="projects<?php echo $rrows['id']; ?>" cols="80" rows="5"  id="projects">  <?php echo $rrows['projects']; ?> </textarea><br><br>
		Schedules:<br>  <textarea name="schedules<?php echo $rrows['id']; ?>" cols="80" rows="5"  id="schedules">  <?php echo $rrows['schedules']; ?> </textarea><br><br>
		News & Information:<br>  <textarea name="news<?php echo $rrows['id']; ?>" cols="80" rows="5"  id="news">  <?php echo $rrows['news']; ?> </textarea><br>

		<br><br>

		<input name="doSave" type="button" id="doSave" value="Save" 
		onclick='$.get("do.php",{ cmd: "edit", pass:$("input#pass<?php echo $rrows['id']; ?>").val(),first_name:$("input#first_name<?php echo $rrows['id']; ?>").val(),last_name:$("input#last_name<?php echo $rrows['id']; ?>").val(),user_level:$("input#user_level<?php echo $rrows['id']; ?>").val(),user_name:$("input#user_name<?php echo $rrows['id']; ?>").val(),teacher:$("input#teacher<?php echo $rrows['id']; ?>").val(),user_email:$("input#user_email<?php echo $rrows['id']; ?>").val(),homework:$("input#homework<?php echo $rrows['id']; ?>").val(),projects:$("input#projects<?php echo $rrows['id']; ?>").val(),schedules:$("input#schedules<?php echo $rrows['id']; ?>").val(),news:$("input#news<?php echo $rrows['id']; ?>").val(),id:$("input#id<?php echo $rrows['id']; ?>").val() } ,function(data){ $("#msg<?php echo $rrows['id']; ?>").html(data); });'> 
		<a  onclick='$("#edit<?php echo $rrows['id'];?>").hide();' href="javascript:void(0);">close</a>
	  </form>
	  <div style="color:red" id="msg<?php echo $rrows['id']; ?>" name="msg<?php echo $rrows['id']; ?>"></div>
	  </div>
	  
	  </td>
          </tr>
          <?php } ?>
        </table>
    <p><br>
          <input name="doApprove" type="submit" id="doApprove" value="Approve">
          <input name="doBan" type="submit" id="doBan" value="Ban">
          <input name="doUnban" type="submit" id="doUnban" value="Unban">
          <input name="doDelete" type="submit" id="doDelete" value="Delete">
          <input name="query_str" type="hidden" id="query_str" value="<?php echo $_SERVER['QUERY_STRING']; ?>">
          <strong>Note:</strong> If you delete the user, they can register again. 
	Instead, 
          ban the user. </p>
        
      </form>
  
  <?php } ?>
      <p> </p>
  <?php
  if($_POST['doSubmit'] == 'Create')
{
$rs_dup = mysql_query("select count(*) as total from users where user_name='$post[user_name]' OR user_email='$post[user_email]'") or die(mysql_error());
list($dups) = mysql_fetch_row($rs_dup);

if($dups > 0) {
die("The user name or email already exists in the system");
}

if(!empty($_POST['pwd'])) {
  $pwd = $post['pwd'];	
  $hash = PwdHash($post['pwd']);
}  
else
{
  $pwd = GenPwd();
  $hash = PwdHash($pwd);
  
}

mysql_query("INSERT INTO users (`first_name`,`last_name`,`user_name`,`user_email`,`pwd`,`approved`,`date`,`user_level`,`homework`,`projects`,`schedules`,`news`)
		 VALUES ('$post[first_name]','$post[last_name]','$post[teacher]','$post[user_email]','$hash','1',now(),'$post[user_level]','$post[homework]','$post[projects]','$post[schedules]','$post[news]')
		 ") or die(mysql_error()); 



$message = 
"Thank you for registering with Holy Family Catholic School Website. Here are your login details...\n
User Email: $post[user_email] \n
Passwd: $pwd \n

*****LOGIN LINK*****\n
http://$host$path/login.php

Thank You

Administrator
$host_upper
______________________________________________________
THIS IS AN AUTOMATED RESPONSE. 
***DO NOT RESPOND TO THIS EMAIL****
";

if($_POST['send'] == '1') {

mail($post['user_email'], "HFCS Login Details", $message,
    "From: \"HFCS Website Registration\" <auto-reply@$host>");
      
}
echo "<div class=\"msg\">User created with password $pwd....done.</div>"; 
}

  ?>
  
      
      <p> </p>
      <p> </p>
      <p> </p>
      <p> </p></td>
    <td width="12%"> </td>
  </tr>
</table>
</div>
</body>
</html>

Link to comment
Share on other sites

  • 4 weeks later...

You MUST deactivate the HTML code by making it appear as text in whichever box you use. The code I show below WILL work as it's been tested. To have active code to be clickable inside the scroll box, you MUST use a div type scroll box and not one using the "textarea" tags.

 

Change all the opening tag symbols, "<", to the character entity, & lt ; (without spaces) as & lt ; (without spaces) = <. This will deactivate the HTML code in the textarea/scroll box, but allow users viewing the page to copy/paste the code.

 

Example:

 

& lt;img style="width: XXpx; width: YYpx; border: 0; src"pic

link" alt="Text Description" /&' gt;

 

&' lt; without spaces = < and &' gt; without spaces = >

 

Example:

 

<textarea style="background: transparent;" rows="8" cols="70"> & lt;img style="width: XXpx; width: YYpx; border: 0; src"pic link" alt="Text Description"> </textarea>

 

There is no closing tag for the image tag unless you are using an XHTML DocType then the image tag is closed with a space and a "/":

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.