473,581 Members | 6,653 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

5 New Member
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=s m. 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 22544
dgreenhouse
250 Recognized Expert Contributor
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
dagmawi michael
5 New Member
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 Recognized Expert Contributor
$rows=mysql_fet ch_array($resul t) is not terminated.

Should be:
$rows=mysql_fet ch_array($resul t);
Mar 28 '11 #4
dagmawi michael
5 New Member
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
598
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: <sessionState
1
1805
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" name="adAuthCookie" timeout="60" path="/" > </forms> </authentication> The application did success to redirect to login page, but it cannot redirect back to...
4
10591
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 this System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=""JavaScript"">" & vbCrLf)...
1
1551
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 problem if I connected web server from our local network. But, I could not redirect if I connected from internet, say from our client's machine. In...
1
2176
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: http://www.asp.net/QuickStart/util/srcview.aspx?path=~/aspnet/samples...
0
1289
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: http://www.asp.net/QuickStart/aspnet/samples/data/GridViewMasterDetailsInsertPage_vb.aspx
1
1403
by: sahay | last post by:
Retain a visitor-specified value in a select option after page submition
1
2561
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. Simple example: In your start page simply try to redirect... private void Page_Load(object sender, System.EventArgs e) { if (!IsPostBack) //...
3
1708
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 form page that consists of an email text field and comment section that goes right to the business. The problem is not the form that I have remade,...
4
2324
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 - some which may only be accessed if logged in. If I add php code to the top of the pages to be protected to redirect if not logged in, I get the...
1
7880
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8157
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6539
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5350
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3794
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3807
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1394
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1119
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.