469,268 Members | 1,025 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,268 developers. It's quick & easy.

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 4301
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

Post your reply

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

Similar topics

2 posts views Thread by Halldór Ísak Gylfason | last post: by
29 posts views Thread by Mic | last post: by
5 posts views Thread by Scott | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.