Jump to content

text-area data update issue !


simzam

Recommended Posts

how to get text-area text into variable without using <form> i mean can i get through $_GET please provide me solution it needed badly

if ((isset($_GET['insertinto'])) &&($_GET['insertinto']=="true")){
if(isset($_SESSION["ajaxtext"])) {
    unset($_SESSION['ajaxtext']);
    $mysession =  "" ;  //my textarea typed data should b here 
     $_SESSION['ajaxtext'] = $mysession ;

//insertrow() ;
       }
    }

print <<<EOD
<textarea rows='3'  cols='40' id='ajaxtext' name ='ajaxtext'>$mysession</textarea><br>
EOD;  

Link to comment
Share on other sites

$mysession is blank, you also are setting $_SESSION['ajaxtext'] to an empty variable.  You need to put the correct info into $mysession.

 

So possibly, you can first set the proper information into $mysession, by doing $mysession = $query['row_info'], then you can call it into the textarea.  You can debug as well, do print_r($mysession), if it displays NULL or FALSE then it's because nothing has been set, it might even be completely empty.  So try doing, $mysession = 'test'; to first see if the forms are being submitted properly.  But no matter what when you input data and want it submitted into your db you will need to use <form>.

Link to comment
Share on other sites

thanks i will post my full code im using ajax

 

Mypage.php

<?php
session_start();
error_reporting(-1);

print <<<EOD
<html>
<head>
  <title> Insert Page !</title>
</head>
<body>
EOD;


if (!empty($_GET['divid']) && isset($_GET['divid'])){
$getdiv = $_GET['divid'] ;
print <<<EOD
<script type="text/javascript">
function doHttpRequest() {
  http.open("POST", "ajaxpost.php", true);
  http.onreadystatechange = getHttpRes;
  var params = "ajax1="+ encodeURI(document.getElementById("$getdiv").innerHTML);


  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", params.length);
  http.setRequestHeader("Connection", "close");
  http.send(params);
}

function getHttpRes(){
  if (http.readyState == 4 && http.status == 200) {
var myvar = document.getElementById('ajaxtext'),
    res = http.responseText;
             myvar.innerHTML = res;
  }
}

function getXHTTP( ) {
  var xhttp;
   try {
      xhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
    try {
      xhttp = new XMLHttpRequest();
    } catch (e3) {
      xhttp = false;
    }
      }
    }
  return xhttp;
}
var http = getXHTTP();
window.onload = doHttpRequest;
</script>
EOD;
          }


if(isset($_SESSION["ajaxtext"])) {
$mysession =  $_SESSION['ajaxtext'];
      }else{
$mysession = "";
        }


$httpquery =  $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']."insertrow=true" ;
if (isset($getdiv)){
$httpquery = str_replace("&divid={$getdiv}", "", $httpquery);
list($httpquery) = explode("insertrow=true", $httpquery);
$httpquery = $httpquery."insertrow=true"."&" ;
}else{
$httpquery = str_replace("&insertinto=true", "", $httpquery);
list($httpquery) = explode("insertrow=true", $httpquery);
$httpquery = $httpquery."insertrow=true"."&" ;
        }


if ((isset($_GET['insertrow'])) &&($_GET['insertrow']=="true")){
if(isset($_SESSION["ajaxtext"])) {
unset($_SESSION['ajaxtext']);
$mysession = "New Post !" ;
 $_SESSION['ajaxtext'] = $mysession ;
            }

}


$httpupdate =$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']."insertinto=true" ;
if (isset($getdiv)){
$httpupdate = str_replace("&divid={$getdiv}", "", $httpupdate);
list($httpupdate) = explode("insertinto=true", $httpupdate);
$httpupdate = $httpupdate."insertinto=true"."&" ;
}else{
$httpupdate = str_replace("&insertrow=true", "", $httpupdate);
list($httpupdate) = explode("insertinto=true", $httpupdate);
$httpupdate= $httpupdate."insertinto=true"."&";
        }


if ((isset($_GET['insertinto'])) &&($_GET['insertinto']=="true")){
if(isset($_SESSION["ajaxtext"])) {
       unset($_SESSION['ajaxtext']);
$mysession =  ""  ; // here is my issue!
 $_SESSION['ajaxtext'] = $mysession ;
//insertrow() ;
       }
    }

  print <<<EOD
     Insert: <br>
         ---------------------------------------------------------->
	  <a href='{$httpquery}' >New</a> <br>
	<textarea rows='3'  cols='40' id='ajaxtext' name ='ajaxtext'>$mysession</textarea><br>
         ---------------------------------------------------------->
	 <a href='{$httpupdate}'>Insert!</a>
EOD;

//  mysql_connect('localhost','root','******');
// mysql_select_db('fblike', $conn);
//    here i use my sql  'SELECT * FROM mytable';

echo "<table border= 1><tr>\n";
echo "<th>Title</th>\n";
echo "<th>Edit</th>\n";
echo "<th>Del</th></tr>\n";
while($row = mysql_fetch_assoc($rs)) {

	if ( !empty($_GET["page"])  &&  isset($_GET['page']) ){
$pageid = $_GET['page'] ;

echo  "<tr><td><div id=\"div{$row['id']}\">{$row['title']}</div></td> \n" ;
echo  "<td><a href= \"?page={$pageid}&divid=div{$row['id']}&\">Edit</a> </td>  \n" ;
echo  "<td><a href= \"#\">Delete</a> </td> </tr>  \n" ;
}
}

echo "</table>\n";
echo "<br>\n";

echo "</body>\n";
echo " </html>\n";

?>

 

ajaxpost.php

<?php

session_start();
if (isset($_POST['ajax1'])) {
$_SESSION['ajaxtext'] = $_POST['ajax1'];
echo "{$_SESSION['ajaxtext']}" ;
}


?>

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.