473,385 Members | 2,069 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,385 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 4530
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 submitted and the target is set to the IFrame. I...
29
by: Mic | last post by:
Goal: delay execution of form submit Code (Javascript + JScript ASP): <% Response.Write("<OBJECT ID='IntraLaunch' STYLE='display : none' WIDTH=0 HEIGHT=0...
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 vs.net code-behind?
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 am left with the code of a guy who has left. When 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 values)..once the table is populated..i have some...
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 a form if i submit it i want the submitted data...
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 this: when user clicks on a clickable element, it...
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, imp_sname, imp_address, imp_tel I have a page...
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 $_SERVER; ?>" method="post"...
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 edit that is susposed to navigate to the correct...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.