473,395 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Closing browser window

119 100+
Hi to all,

I have a page which is to be automated, i explain you clearly:

I have a page with 3 fields name mailid and message. what i can do with that page is i can type name mail id and message and if i sand go, the message with the name displays in the chat box.


ex :

here name is john, email is john.test@mymail.com

message is This is my message.


john : This is my message

This will be shown in the chat box. i think now you understood the point?

Here what i want to do is for every detail i have to insert name mail id and message and then i have to hit go to update to database.

for that i wrote a php code to automate the process, i connected to the database table and i have 3 fields in that name, mailid and message.

i created a php script to run that chat page and i used to bulk insert the 3 fields to this chat history.(name message and mail id).

what that script will do is it will get all the details from Database table and continuously insert in to this chat field and that process goes till the table records ends.

Now the problem is if i insert 4 records from the table to that chat window, 4 window is opening in the browser.

for example if i have 6 records in table and i am inserting to chat field. 6 window is created separately.

Can any one help me in this please, i want to close all the opening browsers after injecting all the values to chat box.

Thanks in advance,

Regards
Magesh
Mar 9 '09 #1
6 1791
TheServant
1,168 Expert 1GB
Firstly, we can't really know why your code is not working without seeing your code, so please post any relavent code.
Closing browser windows is not something PHP can do, but you want to look at Javascript for that.
From what you have said however, I think you are making an error with how you are retrieving your data and displaying it in a window. The logic should be to get ALL the data from your database, then print it all sequentially to one window. If your "open window" code is in the loop, for each line, it will create a new window for each line, but if you have your new window code before or after, it will only have one (and then no need to close any).

Ultimately I am guessing from what you have said, but if that doesn't help, show us the code where you think the problem is and we can be more specific.
Mar 9 '09 #2
phpmagesh
119 100+
@TheServant


Expand|Select|Wrap|Line Numbers
  1.  
  2.  $i=0;
  3.  
  4.  $result = mysql_query("SELECT * FROM $dbtable");
  5.  $resultvalue = mysql_num_rows($result);
  6.  
  7.   if($result) 
  8.  {  
  9.      if(mysql_num_rows($result) == 0) 
  10.      {
  11.         echo "<p>There are no datas in the database Table</p>";
  12.      }
  13.      else
  14.      {     
  15.  
  16.          while($row = mysql_fetch_assoc($result))
  17.          {   
  18.              $name = $row['name'];
  19.              $mail = $row['email'];
  20.              $message = $row['message'];
  21. ?>
  22. <body >
  23. <form name="data<?php echo $i; ?>" target="datamain" action="http://www.mysite.com/mybox/index.php?boxid=<?php echo $boxid; ?>&amp;boxtag=<?php echo $boxtag; ?>&amp;sec=submit&amp;" method="post" class="cfrm" id="mybox" >
  24.             <table width="400px" border="0" cellpadding="0" cellspacing="0">
  25.             <tr>
  26.             <td id="tblmid" valign="center" align="center" height="100%"><input name="key" value="" type="hidden"></td></tr>
  27.             <tr><td><input style="width: 445px;" maxlength="25" name="nme" size="9" value="<?php echo $name; ?>" class="frmtb" type="hidden"></td>
  28.             </tr>
  29.             <tr>
  30.             <td><input style="width: 444px;" maxlength="100" name="eml" size="9" value="<?php echo $mail; ?>" class="frmtb" type="hidden"></td>
  31.             </tr>
  32.             <tr>
  33.             <td><input style="width:500px;" maxlength="200" name="pst" size="9" value="<?php echo $message; ?>" class="frmtb" type="hidden"></td>
  34.             </tr>            
  35.             </table>
  36.             </form>
  37. </body>
  38. <?php    
  39.              echo "<table width='600px' border='1'>";              
  40.              echo "<tr><td width='100px'>". $row['name']. "</td>";
  41.              echo "<td width='200px'>". $row['email']. "</td>";
  42.              echo "<td width='300px'>". $row['message']. "</td>";            
  43.              echo "</tr>";        
  44.  
  45.           }
  46.       echo "</table>";    
  47.       $i=$i+1;     
  48.      }    
  49.      mysql_free_result($result); 
  50.  }
  51.  else 
  52.  {
  53.      echo "Error! SQL query failed:";
  54.      echo "<pre>". $dbh->error ."</pre>";
  55.  } 
  56.  
  57.  mysql_close($dbh); 
  58.  ?>
  59.  
  60. <script language="javascript" >        
  61. for (var i = 0; i < document.forms.length; i++) 
  62.         {    
  63.             document.forms[i].target='_blank';                
  64.             document.forms[i].submit();    
  65.  
  66.         }                    
  67. </script>
  68.  
This is my code.. i think you will understand this.

The action of the form and other id's used in the form can not be changed.

i m just incrementing the form using i and everytime the form name will change.

for every form i m using separate browser to open,

If possible can you tell me how to handle such issue in some other way. i just want to update in bulk data to the target chat window..

Thanks in advance,

Regards
Magesh
Mar 9 '09 #3
TheServant
1,168 Expert 1GB
Why are you making a new form for every entry? I am really confused at why you are making a new window for every line? I will fix up the code now and you can try it and see if it's more useful...
Mar 9 '09 #4
TheServant
1,168 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. <body >
  2.     <form name="data" action="http://www.mysite.com/mybox/index.php?boxid=<?php echo $boxid; ?>" method="post" class="cfrm" id="mybox" >
  3.         <table width="400px" border="0" cellpadding="0" cellspacing="0">
  4. <?php
  5.     $result = mysql_query("SELECT * FROM $dbtable");
  6.     $resultvalue = mysql_num_rows($result);
  7.     if($result) {
  8.         if($resultvalue == 0) {
  9.             echo "<p>There are no datas in the database Table</p>";
  10.         } else {
  11.             while($row = mysql_fetch_assoc($result)) {
  12.                 $name = $row['name'];
  13.                 $mail = $row['email'];
  14.                 $message = $row['message'];
  15.                 echo( "
  16.                         <tr>
  17.                             <td id=\"tblmid\" valign=\"center\" align=\"center\" height=\"100%\"><input name=\"key\" value=\"\" type=\"hidden\"></td>
  18.                         </tr>
  19.                         <tr>
  20.                             <td><input style=\"width: 445px;\" maxlength=\"25\" name=\"nme\" size=\"9\" value=\"" . $name . "\" class=\"frmtb\" type=\"hidden\"></td>
  21.                         </tr>
  22.                         <tr>
  23.                             <td><input style=\"width: 444px;\" maxlength=\"100\" name=\"eml\" size=\"9\" value=\"" . $mail . "\" class=\"frmtb\" type=\"hidden\"></td>
  24.                         </tr>
  25.                         <tr>
  26.                             <td><input style=\"width:500px;\" maxlength=\"200\" name=\"pst\" size=\"9\" value=\"" . $message . "\" class=\"frmtb\" type=\"hidden\"></td>
  27.                         </tr>            
  28.                     " );
  29.             }
  30.         }
  31.     else { echo "Error! SQL query failed: <pre>". $dbh->error ."</pre>"; }
  32. ?>
  33.  
  34.         </table>
  35.     </form>
  36. </body>
  37.  
Basically all I did is put your while loop inside the surrounding table tag. This will make one table in one form on one page.
If you want to make tables per result, then simply change the <table> tag to inside the loop.
Again, your reasoning does not make sense why you had so many forms and pages if it's supposed to be a chat window???
Fixed up some of your code to make it have less echos.
You don't need to free results or close the database connections.
Mar 9 '09 #5
Dormilich
8,658 Expert Mod 8TB
@TheServant
It's always good coding practice to do this (there might be systems, that do not do this automaticly)

and one personal opinion: for a chat system I'd used AJAX (unless I completely misunderstood the intentions)
Mar 9 '09 #6
TheServant
1,168 Expert 1GB
@Dormilich
Yes, sorry, mine does close it automatically, just presumed it was industry standard now.

@Dormilich
I agree. AJAX means that there doesn't need to be any whole page refreshing and there are many more features in the terms of alerts etc... So although you can make a PHP one, it's really not the most appropriate language.
Mar 9 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jawahar Rajan | last post by:
All, I have a printer friendly page that is opened when a user clicks a link on my page to get the printer friendly version, How ever when they close out the printer friendly version and return to...
3
by: Daniel | last post by:
Is there a way to make a javascript do something when the user closes the browser? I would like it to go another url or something. I do not want this script to run when a user clicks on a link on...
2
by: Derek | last post by:
Hello: I want to capture the event when a browser is closing, to give to the user the posibility of close or no this browser. When the browser is closing, this show a confirm window with two...
4
by: bbass | last post by:
thanks to all that replyied to my previous post with the following code in question: <a href="merc.htm" target="_new_merc" onfocusout=window.close class="left_link"> i understand that the...
4
by: Daniel Walzenbach | last post by:
Hi, does anybody know the JavaScript the guys at Microsoft used in MS CRM to prevent people from closing a browser window and asking them (on the client) what they really want to do? If you...
1
by: Chirag Malvi | last post by:
hello all, I am developing the web application using ASP.net and VS.2003 IDE. here is the situation which i want to implement. 1) User is browsing some webform. I want to trap this event....
1
by: Audrey | last post by:
Hi Need some advice here.. I have a frame with a hyperlink to logout from the site When the Logout link (on the left frame) is clicked, a page stating "You've logged out. Please login again" is...
1
by: buran | last post by:
Dear ASP.NET Programmers, I am developing an intranet application using ASP.NET. I want to add such a functionality that the application displays a pop-up box to confirm when the user tries to...
7
by: Rich | last post by:
I have the following script on all pop up windows, would like to have this work on all newer browsers if possible. Right now it only works on MSIE & Opera. Not sure why. Any suggestions are...
1
by: karthik juneni | last post by:
Hi all, Iam trying to capture windows closing event (i.e) when the user clicks on the "X" button i want to capture that event and want to update some values in the database.I tried two methods...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.