472,352 Members | 1,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Form to submit, but also display data?

Hello, like everyone else on here, I'm looking for some help, but I'm thinking this should be fairly simple for people who know the language.

I've got an HTML form full of drop downs and input boxes that a user fills out, then they hit Submit and using the POST method it goes to an upload.php page I wrote, that uploads all of their values to a database, and presents them with the unique Web ID it generated.

Now, I need them to be able to go back to the original page, and enter in the Web ID in they were just given, and have all of the forms controls load the data from the database.

I'm wondering, what's the best method of going about this? I don't mind researching, I just don't know what to research. My thoughts on it are having a "refresh" button, so once they select "display" rather then create on the main page, they hit refresh, which submits to the upload.php using POST, and has a check, if display was selected on the previous page, then reload the previous page, but some how set all of the controls with the proper values from the database based on the Web ID. There has got to be a better way then putting in logic for each control on the web form "If display was selected, set the value too... otherwise, list possible values for selection"

Can anyone give me some pointers, please?
Aug 25 '10 #1
7 4412
johny10151981
1,059 1GB
You can do it in several ways.

The best way i propose is

index.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(isset($_GET['submit'])==false)
  3. {
  4.  $id="";
  5.  $name="";
  6.  $age="";
  7.  exit;
  8. }
  9.  $name=$_GET['name'];
  10.  $age=$_GET['age']; 
  11.  // mysql queries start 
  12.  $id=from mysql query....
  13.  // mysql queries end
  14.  
  15.  include_once('index_gui.php');
  16. ?>
  17.  
index_gui.php
Expand|Select|Wrap|Line Numbers
  1. <form action="index.php" method=POST>
  2. <span><?php echo $id;?></span>
  3. <input name="name" value='<?php echo $name;?>'>
  4. <input name="age" value='<?php echo $age;?>'>
  5. <input type=submit name="submit" value='Submit'>
  6. </form>
  7.  

Try this way.....
Aug 25 '10 #2
Thanks a lot for the reply.

If I'm understanding it correctly, you have a page with 2 input controls on it, if it's the first load of the page, all values are empty, but if submit had been hit, then it queries the database to populate the controls, correct?

I wish I had asked this before programming most of the App.

I have it setup like this:

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. echo'<select name="TSH1">';
  3. echo'<option value=""></option>'; 
  4. $conn1 = odbc_connect('daisy','chrisbwamp',''); 
  5. if ($conn1) 
  6.   $query1 = "SELECT DESCRIPTION, HIERARCHY1 FROM TRADE_SPEND_HIER1"; 
  7.   $result1=odbc_exec($conn1, $query1); 
  8.   while(odbc_fetch_row($result1))
  9.   { 
  10.   $DESCRIPTION1=odbc_result($result1,"DESCRIPTION");
  11.   $HIERARCHY1=odbc_result($result1,"HIERARCHY1");   
  12.   echo'<option value="'.$HIERARCHY1.'">'.$DESCRIPTION1.'</option>'; 
  13.   } 
  14.   }
  15.     echo "</select>";
  16.     odbc_close($conn1);
  17. ?>
  18.  
So each control is doing it's own query, it's not all done upfront, and then variables used (as it probably should be).

Sounds like I need to do this query (and all others) at the beginning, and put it into an array or two, and then call the array rather then perform the whole query at each control.

Either that, or have a variable set to true or false (for being submitted) and put an if statement and on each control.

Also, mine is setup, so that POST goes to an "upload.php" file that stores the data they entered into a database. If they hit submit and it goes to upload.php, how should I go about redirecting them back to the main page?

for example:

index.php:

They select "display" and type in a WebID and hit submit, it then goes to upload.php which does a check, sees that display was selected, and redirects back to index.php passing on the WebID variable

Thanks a TON for reading this, and for helping the first time around.
Aug 25 '10 #3
Looking around a bit more, it looks like another option may be to have a section in my page that queries my database (when the user selects "Display") based on the WebID, stores them each in variables, and then sets all the controls at once using Javascript, any thoughts on this as well?
Aug 25 '10 #4
johny10151981
1,059 1GB
You can do this.

So far what ever you did.

Keep your upload page as it is.

Now made few change at submit page.

Try to submit data using ajax you can call the upload.php. After processing upload.php will send you back a xml file which will include uploaded data.

Try this.
Aug 26 '10 #5
Thanks for the reply, but I'm not sure I quite understand what your saying.

I'm very new to HTML/Javascript/PHP ... like 2 weeks new lol.

Your saying that I should let it POST to upload.php, then once there, save the data to an XML file, then redirect (how?) back to the main page, and load the values from xml (also not sure how?).

Thanks again for taking the time to reply.
Aug 26 '10 #6
Anyone have any ideas?

I'm at a bit of a loss here.

If I click any button on the page, it's going to go to upload.php, which is fine, I can do queries and get the data I need to display in variables there, but how do I redirect the user back to the previous page, and get the variables available there, and then set the elements to those variables.

I don't need an answer, just an idea of what method to use.

Thanks.
Aug 27 '10 #7
TheServant
1,168 Expert 1GB
I suggest looking into header redirect:

So if you form is on index.php and it submits to process.php, you can put:
Expand|Select|Wrap|Line Numbers
  1. header("Location: index.php");
which will start delivering that page instead. The catch is, header() can only be used if NO output has been sent. As in, no echo's or print's, and definitely no HTML. If process.php works how it should all it does is process stuff, it doesn't output stuff.

No the next question is how to give success/fail messages. Glad you asked. This is where you should use $_GET variables. Put this in your process.php:
Expand|Select|Wrap|Line Numbers
  1. if ($success) {
  2.     $gets = "?success=true";
  3. } else {
  4.     $gets = "?success=false";
  5. }
and then change your header() in your process.php to:
Expand|Select|Wrap|Line Numbers
  1. header("Location: index.php$gets"); // returns a URL like: http://domain.com/index.php?success=true
And then finally in your index file put this at the top:
Expand|Select|Wrap|Line Numbers
  1. if ($_GET['success']) {
  2.     $message = "SUCCESS!!!";
  3. } else {
  4.     $message = "FAIL :(";
  5. }
And then in your index's HTML in a nice location:
Expand|Select|Wrap|Line Numbers
  1. <p class="message"><?php echo $message; ?></p>
That might need some minor debugging, but you get the idea ;)
Aug 27 '10 #8

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

Similar topics

2
by: Halldór Ísak Gylfason | last post by:
In my application I have an iframe that is empty (and not visible) initially, however when a user presses a button a form is programmatically...
29
by: Mic | last post by:
Goal: delay execution of form submit Code (Javascript + JScript ASP): <% Response.Write("<OBJECT ID='IntraLaunch' STYLE='display : none'...
5
by: Scott | last post by:
How can I tell a form to submit itself in the code-behind in vs.net? In other words, in javascript I can do blah.submit() - how do I do this in...
4
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I...
5
by: g | last post by:
Hi Guys.. i know this might sound really really simple, but I'm kinda stuck..I have this form..which has a table (created from stored procedure...
3
by: tamimmakki | last post by:
Hi guys, I am new to php. can you tell me how can we post a form to same page and display to posted data on the same page with form. Actully i need...
4
by: szimek | last post by:
Hi, I've already posted an email with this problem, but this time I think I got a bit more info. The app I'm currently working on works like...
4
by: giandeo | last post by:
Hello experts. I wish to post a string and display the output in the same page. The Scenario: Table name: importer Field name: imp_code,...
14
by: white lightning | last post by:
How to have <select onchange="this.form.submit()"and also a Submit button on one form? I have something like this: <form action="<?php...
17
by: lee weaver | last post by:
I have a form to edit employee data that is a copy of the add employee form ( Which works great) with a list box at the top to select the employee to...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
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...
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...
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...
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...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
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...

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.