Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 08-15-2006, 07:36 PM Multiple Forms
Junior Talker

Posts: 1
Name: Hugh
Trades: 0
Hi,

i am writing a form which requires multilple pages, or two anyway. my first form is simple just entering name date and so on(job form), but once this is submitted i create an automatic id number and submit it into MySQL.

i then move to the next form which takes in other stuff such as reason, type (jobRecords) blahh blahhh. But my problem is i want this to be related to the previous entry in the job table by using the auto id number. But so far cannot work out how to add this auto id from the last form, either enter 2 entries which i dont want or the number is set to 0.

Any suggestions
hugh is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-15-2006, 08:39 PM Re: Multiple Forms
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
After running your first MySQL Insert query, use the php/mysql mysql_insert_id() function to retrieve the auto id. You can then pass this id to the next page through a session, post or get (url).
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 08-16-2006, 10:25 AM Re: Multiple Forms
tomcat_fo's Avatar
Ultra Talker

Posts: 275
Trades: 0
I have a question regarding the same thing.


If i have several forms(a php file each), but the first one people access is a simple form where they select which form they are going use.

The first form is only a dropdown (<select>) and a submit button, the things in the dropdown are kinde of groups with an ID that i want to enter into the record along with everything else people enter in the form they want to fill out.

This ID is lost when i enter the submit button, and another form comes on the screen.

How do i get this ID up in browsers addres field, so i can use an $_GET on it ?

I have tryed on the main form-page to use this line to get it up in the browsers addresline:
$_REQUEST formtype=$id

But notthing comes in the browser addres line.... tought $_REQUEST could do this even if it normaly takes info from the address line instead of putting it up there.

Could maybe do an URL that looks like this in the end ?formtype=$id but then i need a link that people click on??, but i dont wnat an ordianty link, becuase i allready have a submit button.... so does someone know how i can get this to happen by using the Submit button i allready have ?

Have heard about use of hidden fields for keeping Varibles etc. - is that maybe the ting i need.

I don't know how to do this the way Mgraphic talks about, so i hope someone can tell me how i get that ID up in my browsers address field, so i can use a $_GET on it

Last edited by tomcat_fo; 08-16-2006 at 10:40 AM..
tomcat_fo is offline
Reply With Quote
View Public Profile
 
Old 08-16-2006, 11:01 AM Re: Multiple Forms
Ultra Talker

Posts: 483
Trades: 0
Quote:
Originally Posted by tomcat_fo View Post
I have a question regarding the same thing.
I have tryed on the main form-page to use this line to get it up in the browsers addresline:
$_REQUEST formtype=$id

Assuming your field name is 'id', on your second page you should use something like:
$id_to_use = $_REQUEST['id'];

In reality, instead of $_GET, you should be trying to access it via $_POST.


In all instances, when using multiple page forms, the best thing to do is just set up a session and use that session to keep track of every thing, instead of using hidden fields and the like to continue passing information through the forms...
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Old 08-16-2006, 12:16 PM Re: Multiple Forms
tomcat_fo's Avatar
Ultra Talker

Posts: 275
Trades: 0
I have tryed to make a session based on the name of my dropdownmenu(<select>) on my form main-page.

but get this message when i click the submit-button on the first page, that is suppose to lead to the next:
Code:
Warning:  session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /usr/home/web/web128130/index8888.php:5) in /usr/home/web/web128130/kikarin/lysing.php on line 2
How would a session look like if it was based on what someone selects in the drop-down menu (<select>)

my session looked like this:

session_start();
$_SESSION[‘selectname’]
tomcat_fo is offline
Reply With Quote
View Public Profile
 
Old 08-16-2006, 12:31 PM Re: Multiple Forms
Ultra Talker

Posts: 483
Trades: 0
Your code is right, but as the error message tells you, where you put it is wrong.

The thing to understand about sessions is that they are managed via cookies. Cookies can only be sent while no 'normal' output has been sent. Therefore, you need to make sure that you do your session start code first, before any output whatsoever.

Normally, I start my session in an include file, because you also have to remember to run that session start on every page where you want to use session data.
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Old 08-16-2006, 12:57 PM Re: Multiple Forms
tomcat_fo's Avatar
Ultra Talker

Posts: 275
Trades: 0
On the main-form page i had but start session part below the script lines where the submit button is, but on all the other form-files the session start was at the begining(i started the session when the button was clicked...... now i'v put session start etc. in the start of every file, where i want the session, but still get that message.


Are you sure i can make a session based on a dropdown-menu (<select>) ?
tomcat_fo is offline
Reply With Quote
View Public Profile
 
Old 08-16-2006, 01:06 PM Re: Multiple Forms
Ultra Talker

Posts: 483
Trades: 0
The question:
Are you sure i can make a session based on a dropdown-menu (<select>) ?

makes no sense.

You are attempting to make a session that stores the value of the select field.
That is possible: a session can hold any information you like.

If you've put it at the start of every page, then there shouldn't be a problem. Upload a bit of one of the files for us to have a look at...
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Old 08-16-2006, 01:12 PM Re: Multiple Forms
tomcat_fo's Avatar
Ultra Talker

Posts: 275
Trades: 0
Quote:
Originally Posted by TwistMyArm View Post
The question:
Are you sure i can make a session based on a dropdown-menu (<select>) ?

makes no sense.

You are attempting to make a session that stores the value of the select field.
That is possible: a session can hold any information you like.

If you've put it at the start of every page, then there shouldn't be a problem. Upload a bit of one of the files for us to have a look at...
But i need to hold on to that ID so......

but here is the session part of the main-form page:
session_start();
$_SESSION[bolkar2];


This is how it looks in the other files where i need the session:
session_start();
if(isset($_SESSION[bolkar2]))
{



My website is a dynamic PHP website, so i have a index file with a lot of included files.... and my session part is in these included files..... do not know if this plays a role.
tomcat_fo is offline
Reply With Quote
View Public Profile
 
Old 08-16-2006, 01:19 PM Re: Multiple Forms
Ultra Talker

Posts: 483
Trades: 0
Oh god. I know those variable names... I've seen you asking about this code elsewhere, haven't I??

Anyway, the whole idea of sessions is to hold on to that information. Just as you want.

The line:
$_SESSION[bolkar2];

means nothing. Are you setting it to equal something? It doesn't magically work out what value you want it to be!

OK, so this whole 'I have an index file with a lot of included files': your problem is probably there. Guaranteed that one of the files that are being included before you start your session is giving output. Output can even be 'whitespace outside of the <? / ?> PHP tags'. Whitespace can be a new line at the end of a closing tag.

If you look at the error message above:
Cannot send session cookie - headers already sent by (output started at /usr/home/web/web128130/index8888.php:5)

you can see that it even tells you where that output came from. Go into index8888.php and look at line 5. Stop it from doing whatever it is that is causing the output. Or put your session start before that line. Check it again and see if there's output coming from somewhere else. Rinse and repeat until your session start is the first thing that is happening in your pages.
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Old 08-16-2006, 01:32 PM Re: Multiple Forms
tomcat_fo's Avatar
Ultra Talker

Posts: 275
Trades: 0
Quote:
Originally Posted by TwistMyArm View Post
Oh god. I know those variable names... I've seen you asking about this code elsewhere, haven't I??

Anyway, the whole idea of sessions is to hold on to that information. Just as you want.

The line:
$_SESSION[bolkar2];

means nothing. Are you setting it to equal something? It doesn't magically work out what value you want it to be!

OK, so this whole 'I have an index file with a lot of included files': your problem is probably there. Guaranteed that one of the files that are being included before you start your session is giving output. Output can even be 'whitespace outside of the <? / ?> PHP tags'. Whitespace can be a new line at the end of a closing tag.

If you look at the error message above:
Cannot send session cookie - headers already sent by (output started at /usr/home/web/web128130/index8888.php:5)

you can see that it even tells you where that output came from. Go into index8888.php and look at line 5. Stop it from doing whatever it is that is causing the output. Or put your session start before that line. Check it again and see if there's output coming from somewhere else. Rinse and repeat until your session start is the first thing that is happening in your pages.
Well iv had some questions about bolkar2, but that was entirely another case

As you know i wany to hold on to that <select> ID, and "bolkar2" is the name of the <select> ...... so maybe i misplaced it in the session, i have maybe set the name of the session(var of the session) wrong - it should maybe be like this:

session_start();
$_SESSION['sessionvar']="bolkar2";

here bolkar2 is the name of the <select>
tomcat_fo is offline
Reply With Quote
View Public Profile
 
Old 08-16-2006, 01:44 PM Re: Multiple Forms
Ultra Talker

Posts: 483
Trades: 0
On the page that receives the <select> value (that is, the page that you go to after selecting the value), you want:

$_SESSION['sessionvar'] = $_REQUEST['bolkar2'];


Then, throughout the session, whenever you want to know what that selected value was, just use $_SESSION['sessionvar']...
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Old 08-16-2006, 02:38 PM Re: Multiple Forms
tomcat_fo's Avatar
Ultra Talker

Posts: 275
Trades: 0
Thanks for your answers, will try and get it to work... hope i did not mess up Hugh's original question

If you know a better(smarter) way to do what i want, then you are welcome to tell


By the way, if I use session for the kind of thing im talking about, will there then be any conflict in the system later on if i want to make sessions for usename & password check and god know what else ?
tomcat_fo is offline
Reply With Quote
View Public Profile
 
Old 08-16-2006, 02:45 PM Re: Multiple Forms
Ultra Talker

Posts: 483
Trades: 0
I'm just hoping that hugh's question has been answered in amongst all of this.

Just to clarify: you're not making a 'session for the ID'. You're making a session, then storing the ID in that session.

If you wanted to store the username in the session, just set $_SESSION['username'] for example.

The session variable is just an array of data that you want to have available while dealing with this user, basically.
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Multiple Forms
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.01498 seconds with 12 queries