473,399 Members | 3,038 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,399 software developers and data experts.

Getting a 404 error when posting a form to the same page as itself.

26
Hello!

I am currently working on a project. And have been assigned to get up to speed quickly on php. And even though I love the language, it's not easy to get up to speed in like 2 seconds :-)

The code I will list below is supposed to have four parts:
1. Not logged in. List up all text from the database.
2. Logged in. List up all text from the database. But now with an "edit" button, with the possibility to jump to number 3.
3. Logged in, and pressed the edit button.
A form should show here, and the possibility to insert text into a field, and press submit.
4. Like number two, but now with the added text below.

The code I have is like this:

Expand|Select|Wrap|Line Numbers
  1. <?php include ("c:/db.inc");
  2. error_reporting(E_ALL);
  3. ini_set('display_errors', '0');
  4.  
  5. //global $id = intval( mysql_real_escape_string( $_GET['id'] ));
  6. //global $itemid = intval( mysql_real_escape_string( $_GET['Itemid'] ));
  7.  
  8. if ($my->id && $my->id > 0) { //if logged in
  9. //this code tells me that I am logged in.
  10.     //show edit so I can show form
  11.  
  12. $query = "SELECT * FROM jos_ibruk_issues WHERE jos_issues.contentid= '$id' ORDER BY text desc";
  13.      $result = mysql_query($query);
  14.  
  15.      while($row= mysql_fetch_array($result)) {
  16.           echo"$row[text]<BR>";
  17.     }
  18.  
  19. } else { //not logged in, list up text
  20.  
  21. $query = "SELECT * FROM jos_issues WHERE jos_issues.contentid= '$id' ORDER BY text desc";
  22.      $result = mysql_query($query);
  23.  
  24.      while($row= mysql_fetch_array($result)) {
  25.           echo"$row[text]<BR>";
  26.     }
  27.     //mysql_close();
  28. }
  29.  
  30.  
  31. if ($my->id && $my->id > 0) { //&& $_POST['Submit'] == 'sumbmit') { //IF logged in and have pressed the EDIT "link"
  32.  
  33.     if($_POST['submit'] == 'Submit') {//if submit when have pressed EDIT link in number 2.
  34.         //echo "Submit has been pressed <BR>";
  35.         if(!$_POST['text'] || $_POST['text'] == "") {
  36.              echo "there is a problem. did you fill out anything in the form?<BR>";
  37.         }
  38.         else {
  39.              //all ok, insert into db.
  40.              $id = intval( mysql_real_escape_string($_GET['id']));
  41.              $as_text = addslashes($_POST['text']);
  42.              $tr_text = trim($as_text);
  43.              $query = "INSERT INTO jos_issues(ID,text,contentid)
  44.              VALUES(NULL,'$tr_text','$id')";
  45.              $result = mysql_query($query);
  46.              echo "thanks for posting these issues<BR>";
  47.               $id = intval( mysql_real_escape_string( $_GET['id'] ));
  48.              //echo "id = $id";
  49.              $query = "SELECT * FROM jos_issues WHERE jos_issues.contentid= '$id' ORDER BY text desc";
  50.              $result = mysql_query($query);
  51.              while($row= mysql_fetch_array($result)) {
  52.                   echo"$row[text]<BR>";
  53.              }
  54.         }
  55.     }
  56. $adresse = "http://localhost/demotest/index.php?option=com_content&task=view&" . "id=" . "$id" . "&Itemid=" . "$itemid";  
  57.  
  58. print <<<END
  59. <html>
  60. <form id="form1" name="frmname" method="post" action="<? echo $_SERVER['$adresse'];?">
  61. <label>Text
  62. <input type="text" name="text" />
  63. </label>
  64. <label>
  65. <input type="submit" name="submit" value="Submit" />
  66. </label>
  67. </form>
  68. </html>
  69. END;
  70. }
  71.  
  72. ?>
the forms POST ACTION Doesnt work. give me an error message. Website doesn't exists something.

Can you please help me with this? I have been sitting with this for several days now. I should have been finished with this already, and my boss is breathing down my neck. And he haven't brushed his teeth today :-)


Phropman
Aug 29 '07 #1
9 2994
pbmods
5,821 Expert 4TB
Heya, "Phropman"

Changed thread title. Thanks for reading the Posting Guidelines!

Try this instead:
Expand|Select|Wrap|Line Numbers
  1. <form id="form1" name="frmname" method="post" action="<? echo basename(__FILE__);?">
  2.  
This will more reliably set the form action to the current page.
Aug 29 '07 #2
phopman
26
Try this instead:
Expand|Select|Wrap|Line Numbers
  1. <form id="form1" name="frmname" method="post" action="<? echo basename(__FILE__);?">
  2.  
This will more reliably set the form action to the current page.
I tried setting [PHP]action="<? echo basename(__FILE__);?>">[/PHP] but all I get is: "The requested URL was not found on this server. The link on the ">referring page seems to be wrong or outdated. Please inform the author of ">that page about the error. If you entered the URL manually please check your spelling and try again."

I have to disagree with the title though: The user authentication is in place, but I need to sort out where the users should go after what they press. Wait, maybe that is user authentication after all. well...
Aug 29 '07 #3
pbmods
5,821 Expert 4TB
Heya, Phopman

I have to disagree with the title though: The user authentication is in place, but I need to sort out where the users should go after what they press. Wait, maybe that is user authentication after all. well...
How's this?
Aug 29 '07 #4
phopman
26
Heya, Phopman



How's this?
I don't get a 404 error when users logs in. I just need help to help the users see different things whether they are:

Not logged in (guest)
Logged in
Logged in and have pressed edit button

That's why I disagree
Aug 30 '07 #5
pbmods
5,821 Expert 4TB
Heya, Phopman.

So when the User submits the form, it is correctly posting to a valid page... but when you try to redirect the User based on whether he is logged in, that's when you get the 'doesn't exist' error?
Aug 30 '07 #6
phopman
26
It should post to itself. Which it doesn't do.

It gives me a blank page, with nothing on.
Aug 30 '07 #7
pbmods
5,821 Expert 4TB
Heya, Phopman.

Okie. All set.

What does the form HTML look like when you view it in your browser and select 'View Source' from the menu?
Aug 30 '07 #8
phopman
26
Since the boss threatened to kick my ass yesterday, I just did it an very non-elegant way. Reckons he will yell at me today but :-)

four pages
1. mainpage . list up from database. print out data with links to delete, insert and update pages.
2. delete. deletes from db where contentid = id. No questions asked, it just does :-)
3. Insert. Where you can insert new text in the textarea
4. update. Where you can update.

I think I will have to see today whether I can put everything into one page. It's actually a module in joomla I am working on, so I can only have php in that module, and that is only one php file.
Aug 31 '07 #9
HaLo2FrEeEk
404 256MB
I'd recommend a switch statement, and (if you're not already) using sessions to store the logged on status. You could also use AJAX to submit the form and handle the response.
Jan 4 '11 #10

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

Similar topics

3
by: Gary Varga | last post by:
In the file WebUIValidation.js, when a postback that doesn't fail the validation has a javascript error saying summary is undefined in the ValidationSummaryOnSubmit function....
8
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported...
2
by: johngilmer | last post by:
I have a login page and it appears just fine (login.aspx). There are a couple of links on the page which use javascript to bring up modal dialogs of other aspx pages, and they work fine. But if I...
6
by: guoqi zheng | last post by:
In a regular html form, when user press "enter" key, the form will be submitted. However, in ASP.NET web form, a form will only be submitted (post back) when a special button is clicked. Many...
7
by: Bob L | last post by:
I've inserted a MsgBox in some VBScript on line 12 of an .asp page and get the following error: Microsoft VBScript runtime error '800a0046' Permission denied: 'MsgBox' /default.asp, line 12 ...
6
by: scottrm | last post by:
Hi Users seem to be getting the following intermitent error whe they post a form. Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that...
12
by: Lennart Anderson | last post by:
I'm having a MySQl table wih a lot of information. I want to present some main fields in a table on one page. Each record do, of course, have a unique ID. The presnted table will have one field as...
6
by: phopman | last post by:
Hi guys! Thanks a lot for helping me yesterday. But now I have a new problem. I have a module in joomla which I write PHP code in. $thisfile...
15
by: JohnDriver | last post by:
Hello I am learning Ajax and I am following the tutorials found but for some reason, my code is not working. I think I am missing something in the code that I am posting below. Please have a look...
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?
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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
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,...
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.