473,398 Members | 2,120 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,398 software developers and data experts.

how to show this php code submit result at the same page

hello
I found this code somewhere and tried to create online dictionary with it. I managed to insert the code in to my template index.php. But after the user click submit button the result shows in other blank self created page something like index.php?act=sm. I need the results to show on the same page or somewhere with in the same template. I' ve tried every thing I can. Just I couldn't.how can I do that?

I add
Expand|Select|Wrap|Line Numbers
  1. action="<?php echo $PHP_SELF; ?>
but did not work out.

Thank you in advance
Best Regard's

this is the code
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. echo("<a href=admin.php>ACP</a><br>");
  3.  
  4. if(isset($_GET['act']))
  5. {
  6. $do=$_GET['act'];
  7. switch($do)
  8. {
  9.  case 'form': show_form();break;
  10.  case 'sm' : submited();break;
  11.  default : show_form; break;
  12. }
  13.  
  14. }
  15. else
  16. {
  17. show_form();
  18. }
  19.  
  20. function show_form()
  21. {
  22. ?>
  23. <form name=frm method=POST action="index.php?act=sm">
  24.  
  25. Word : <input type=text name="word"> <input type=submit name="sbm" value="Submit">
  26. </form>
  27. <?
  28.  
  29. }
  30. function submited()
  31. {
  32.  
  33. require("dbconn.inc");
  34. //if(isset($_POST['sbm']))
  35. //{
  36.  $word=$_POST['word'];
  37.  
  38.  $sql="select * from words where eng like '".$word."'";
  39.  //echo($sql);
  40.  $result=mysql_query($sql,$link);
  41.  if(@mysql_num_rows($result)!=0)
  42.  {
  43.   while($rows=mysql_fetch_array($result))
  44.   {
  45.    $vie=$rows["vie"];
  46.   }
  47.   echo("Word<b>$word</b> in vietnamese is : <b>$vie</b><br>");
  48. ?>
  49. <form name=frm method=POST action="index.php?act=sm">
  50.  
  51. Word : <input type=text name="word"> <input type="submit" name="sbm" value="Submit">
  52. </form>
  53. <?
  54.  }
  55.  else
  56.   echo("Don't know that word !! My database is not update!");
  57. //}
  58. mysql_close($link);
  59.  
  60. }
  61. ?>
Mar 27 '11 #1
4 22533
dgreenhouse
250 Expert 100+
Although I didn't test this, this may work:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Untitled Document</title>
  6. </head>
  7. <body>
  8. <?php
  9. echo("<a href=admin.php>ACP</a><br>");
  10.  
  11. $script = $_SERVER['PHP_SELF'];
  12.  
  13. if(isset($_POST['sbm']) && isset($_POST['word']) ) {
  14.   submited();
  15. } else {
  16.   show_form();
  17. }
  18.  
  19. function show_form() {
  20. ?>
  21.   <form name=frm method=POST action="<?php echo $script ?>">
  22.     Word : <input type=text name="word"><br />
  23.     <input type=submit name="sbm" value="Submit">
  24.   </form>
  25. <?php
  26. }
  27.  
  28. function submited() {
  29.   require("dbconn.inc");
  30.   $word=$_POST['word'];
  31.   $sql="select * from words where eng like '".mysql_real_escape_string($word)."'";
  32.   $result=mysql_query($sql,$link); // I assume $link is defined in dbconn.inc
  33.  
  34.   if(@mysql_num_rows($result)!=0) {
  35.     $rows=mysql_fetch_array($result)
  36.     $vie=$rows["vie"];
  37.     echo("Word<b>$word</b> in vietnamese is : <b>$vie</b><br>");
  38.   } else {
  39.     echo("Don't know that word !! My database is not update!");
  40.   }
  41.  
  42.   // The connection will close automatically since
  43.   // this is near the end of the script.
  44.   mysql_close($link);
  45.  
  46.   show_form();
  47. }    
  48. ?>
  49. </body>
  50. </html>
  51.  
Mar 28 '11 #2
hello dgreenhouse
Thank you for replying.
It shows parse error in line 36
Expand|Select|Wrap|Line Numbers
  1. $rows=mysql_fetch_array($result)
  2.     $vie=$rows["vie"];
When I add while loop here it brings me to the same page after clicking submit button but the results are not showing.

best regard's
Mar 28 '11 #3
dgreenhouse
250 Expert 100+
$rows=mysql_fetch_array($result) is not terminated.

Should be:
$rows=mysql_fetch_array($result);
Mar 28 '11 #4
Thanks a million,You were very helpful Dgreanhouse.
It works!!
Mar 28 '11 #5

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

Similar topics

1
by: Grant | last post by:
Hi, I have searched the net and still no luck... I just want to automatically have a page redirected to another page when the timeout set in the config file expires. I currently have: ...
1
by: Grey | last post by:
I have set the following parameters in web.config to prevent user direct access the web page without user login. <authentication mode="Forms"> <forms loginUrl="Initial/index.aspx"...
4
by: bnob | last post by:
In a Button clik event I have this code at the end of the event Response.Redirect("Page.aspx") But in this event I must show a message before redirect to the Page.aspx. I use to show Message...
1
by: Andrew | last post by:
Hello, friends, I am using Forms Authentication in our asp.net app. However, I found that sometimes, the ReturnURL was not in QueryString. For example, I could redirect from login page without...
1
by: Sam | last post by:
Attached I am sending 2 URL's from MSFT ASP.net Quick Start Tutorial Web Site. 1) Run it URL: http://www.asp.net/QuickStart/aspnet/samples/data/GridViewMasterDetai... 2) View Source URL:...
0
by: Sam | last post by:
Sorry to post the same post multiple times but the URL Addresses were not Correct in Earlier Posts. Here are the correct URL's: 1) Run It URL is here: ...
1
by: sahay | last post by:
Retain a visitor-specified value in a select option after page submition
1
by: rouellette | last post by:
Is it possible to redirect to another page in your application from the start page BEFORE the user has been authenticated if you're using FORMS authentication? I can't seem to get it to work. ...
3
by: bcarlsonco | last post by:
I am currently revamping a website for a small business and there is one page giving me issues. I am doing it as a favor for a friend and am not by any means the most tech savvy on coding. There is a...
4
by: pvs1 | last post by:
I've been going around in circles for days on this. I developed over 200 pages of code in a software package and have written the Login scripts in PHP. On about 100 pages are 3 hotlinks in iframe -...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.