hi all,
i created a shoutbox where users will display messages. when they click on shoutbox a table will appear in which we have message and name when they submit messages it should appear beside that shoutbox
shoutbox hiii hyderabad:praveen :: hello praveen:pandu
like this,i have inserted messages and names into database and i have to retrieve them in same page the problem its not coming and error is displayed saying program is not responding
i want to display that message without refreshing the page
please help me thank u in advance

Recommended Answers

All 7 Replies

hai praveen ,
here i am giving u code using javascript , u can usse it if u like...........

<HTML>
<HEAD>
<SCRIPT LANGUAGE="javascript">
function CreateMsg() {
var MsgDOM = document.getElementById("MSG");
MsgDOM.innerHTML = "Hello, " + document.forms[0].FNAME.value  + " " + document.forms[0].LNAME.value  + ". You're sex is " + document.forms[0].GENDER.value;
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="DUH">
<INPUT TYPE=TEXT NAME=FNAME>
<INPUT TYPE=TEXT NAME=LNAME>
<SELECT NAME="GENDER">
<OPTION VALUE="Male">Male</OPTION>
<OPTION VALUE="Female">Female</OPTION>
</SELECT>
<BR><BR>
<A HREF="javascript:CreateMsg();">Create Message</A>
<BR><BR>
<SPAN ID="MSG">&nbsp;</SPAN>
</FORM>
</BODY>
</HTML>
commented: thank u +1
commented: good code you have posted... +1

Try this..
it works fine:

<? 
mysql_connect('localhost','root','1234');
mysql_select_db('banjarahills');

if($_SERVER['REQUEST_METHOD']=='POST'){
print_r($_POST);

$n=$_POST['name'];
$m=$_POST['message'];
}
if(isset($_POST['submit']))
{
 $message=$_POST['message'];

   $name=$_POST['name'];
   
   

   

   if(strlen($message)<1)

   {

   print "You did not type amessage."; //no name entered

   }

   else if(strlen($name)<1)

   {

      print "You did not type name."; //no post entered

   }


  
  else

   {
      $thedate=date("U"); //get unix timestamp

      $displaytime=date("F j, Y, g:i a");

      //we now strip HTML injections
      $message=strip_tags($message);

      $name=strip_tags($name); 
	  
			 	
     $insertpost="INSERT INTO shout (message,name) values('$message','$name')";

      mysql_query($insertpost) or die("Could not insert post"); 
	  } }


 
$res="select * from shout";
$res1=mysql_query($res);

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<script language="javascript">
  function toggle_it(itemID){
      // Toggle visibility between none and inline
      if ((document.getElementById(itemID).style.display == 'none'))
      {
        document.getElementById(itemID).style.display = 'inline';
      } else {
        document.getElementById(itemID).style.display = 'none';
      }
  }
</script>

<body>
<form action="" name="form1" method="post">
<table width="981" height="57" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="155"><a href="#" onClick="toggle_it('prl')">shoutbox</a></td>
    <td width="826">
	<marquee direction="left">
	<?
	if(isset($_POST['submit']))
{
while($res2=mysql_fetch_array($res1))
{
	?>
	<?=$res2['message'];?>:<?=$res2['name'];?><? }}?></marquee>
	</td>
 </tr>
<table width="291" id="prl" style="display:none">
  <tr>
    <td width="95">message</td>
    <td width="196"><input name="message" type="text" id="message" ></td>
  </tr>
  <tr>
    <td>name</td>
    <td><input name="name" type="text" id="name"></td>
  </tr>
  <tr>
    <td colspan="2" align="center"><input type="submit" name="submit" value="submit"></td>
  </tr>
 
  </table>
</table>
</form>
</body>
</html>

Try this..
it works fine:

<? 
mysql_connect('localhost','root','1234');
mysql_select_db('banjarahills');

if($_SERVER['REQUEST_METHOD']=='POST'){
print_r($_POST);

$n=$_POST['name'];
$m=$_POST['message'];
}
if(isset($_POST['submit']))
{
 $message=$_POST['message'];

   $name=$_POST['name'];
   
   

   

   if(strlen($message)<1)

   {

   print "You did not type amessage."; //no name entered

   }

   else if(strlen($name)<1)

   {

      print "You did not type name."; //no post entered

   }


  
  else

   {
      $thedate=date("U"); //get unix timestamp

      $displaytime=date("F j, Y, g:i a");

      //we now strip HTML injections
      $message=strip_tags($message);

      $name=strip_tags($name); 
	  
			 	
     $insertpost="INSERT INTO shout (message,name) values('$message','$name')";

      mysql_query($insertpost) or die("Could not insert post"); 
	  } }


 
$res="select * from shout";
$res1=mysql_query($res);

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<script language="javascript">
  function toggle_it(itemID){
      // Toggle visibility between none and inline
      if ((document.getElementById(itemID).style.display == 'none'))
      {
        document.getElementById(itemID).style.display = 'inline';
      } else {
        document.getElementById(itemID).style.display = 'none';
      }
  }
</script>

<body>
<form action="" name="form1" method="post">
<table width="981" height="57" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="155"><a href="#" onClick="toggle_it('prl')">shoutbox</a></td>
    <td width="826">
	<marquee direction="left">
	<?
	if(isset($_POST['submit']))
{
while($res2=mysql_fetch_array($res1))
{
	?>
	<?=$res2['message'];?>:<?=$res2['name'];?><? }}?></marquee>
	</td>
 </tr>
<table width="291" id="prl" style="display:none">
  <tr>
    <td width="95">message</td>
    <td width="196"><input name="message" type="text" id="message" ></td>
  </tr>
  <tr>
    <td>name</td>
    <td><input name="name" type="text" id="name"></td>
  </tr>
  <tr>
    <td colspan="2" align="center"><input type="submit" name="submit" value="submit"></td>
  </tr>
 
  </table>
</table>
</form>
</body>
</html>

thanx shanti and us12,
i'll try it but there is no much difference in ur code and my code shanti i will make changes in my code thank u

k praveen...tel me if any error occurs...

thank u
my problem is solved

hai shanthi,
Nice code yaar.........

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.