472,354 Members | 2,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 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 22501
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
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made but the http to https rule only works for...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

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.