Jump to content

SESSION


crazy8

Recommended Posts

Ok I have a little bit of an issue. I have a site im doing which has 3 forms to be filled out by potential customers who would like to open an account. My plan is that after all three forms get filled out all the info will be echoed onto a page for them to look at and verify all the info is correct. If all is good then the form will be submitted and entered into the db. If there is a mistake then I need to allow them to go back to what ever form the mistake is on, and have them correct it.

 

So the problem is that I have next to NO experiance with sessions and even though I understand the logic im clueless as to how to correctly program them. So my question is this. Below is my first of 3 forms. If someone could possibly show me how to do what I need to do on this form I will figure out the rest from there. I learn a bit better from example and when I can see something as a whole.

 

<div class = "nround">
<div class = "ntop"><h2>Become a hotspot</h2></div>
<div class = "nmiddle" align="left">
<form name="step1" method="post" action="basic2.php">

<?php include ('db_scripts/db_connect_insert.php'); ?>

<table border="0" cellpadding="2" cellspacing="0" width="100%">
<tbody><tr>
<td colspan="2"><b>Please enter a valid e-mail address. You will need to confirm your e-mail address to activate your account.</b>
</td>
</tr>
<tr>
<td class="required">Company Name</td>
<td class="required"><input type="text" name="comp_name" size="20" maxlength="15" /></td>
</tr>
<tr>
<td class="required">Establishment Type</td>
<td class="required">
<select name="comp_type">
<option selected>- Select One -</option>
<option value="bars">Bar</option>
<option value="clubs">Club</option>
<option value="coffee_shops">Coffee Shop</option>
<option value="resturants">Resturant</option>
</select>
</td>
</tr>
<tr>
<td class="required">Address</td>
<td class="required"><input type="text" name="comp_address" size="30" maxlength="30" /></td>
</tr>
<tr>
<td class="required">Phone Number</td>
<td><input type="text" name="comp_phone" size="20" maxlength="40" /></td>
</tr>
<tr>
<td class="required">Email Address</td>
<td><input type="text" name="comp_email" size="30" maxlength="20" /></td>
</tr>
<tr>
<td class="required">Website Address</td>
<td><input type="text" name="comp_web" size="30" maxlength="20" /></td>
</tr>
<tr>
<td class="required">Description</td>
<td><textarea name="comp_desc" cols="30" rows="12" ></textarea></td>
</tr>																																																															
<tr>
<td class="verdana11" align="right" width="125"><p></td>
<td><input onClick="basic2.php" type="submit" name="submit" value="Go to step 2" /></td>
</tr>
</tbody>
</table>

</form>
</div>
<div class = "nbottom"></div>
</div>

 

Thank you all so much for the help

Link to comment
Share on other sites

The first form is of no use to us, you need to save the data from this form within the script the form points too.

 

Example.

 

f1.php

<form action="f2.php" method="post">
  <input type="text" name="foo">
  <input type="submit" name="submit">
</form>

 

f2.php

<?php

  session_start();
  
  if (isset($_POST['submit'])) {
    $_SESSION['foo'] = $_POST['foo'];

?>

<form action="f3.php" method="post">
  <input type="text" name="bar">
  <input type="submit" name="submit">
</form>

<?php } ?>

 

f3.php

<?php

  session_start();
  
  if (isset($_POST['submit'])) {
    $_SESSION['bar'] = $_POST['bar'];

?>

<form action="process.php" method="post">
  <input type="text" name="bob">
  <input type="submit" name="submit">
</form>

<?php } ?>

 

process.php

<?php

  session_start();

  if (isset($_POST['submit'])) {
    $_SESSION['bob'] = $_POST['bob'];
    print_r($_SESSION);
  }

?>

Link to comment
Share on other sites

This is just an idea, but when I need to verify form data before final submitting, I make my action be the same page, and then test it and reload the fields with value="<?php echo $_POST['var'];?>" or if you clean it first then change it to the right one, then when its finalized it goes to a final processor, thus no sessions used

Link to comment
Share on other sites

Im sorry. Here is form 2

<div align="left"><h2><font color="#b80101">Types of Cuisine</font></h2></div>
<fieldset align="center">
<table>
<tr>
<td><input type="checkbox" name="afghan"/></td><td>Afghan</td>
<td><input type="checkbox" name="caribbean"/></td><td>Caribbean</td>
<td><input type="checkbox" name="greek"/></td><td>Greek</td>
<td><input type="checkbox" name="korean"/></td><td>Korean</td>
<td><input type="checkbox" name="pizza"/></td><td>Pizza</td>
<td><input type="checkbox" name="swedish"/></td><td>Swedish</td>

</tr>

<tr>
<td><input type="checkbox" name="american"/></td><td>American</td>
<td><input type="checkbox" name="chinese"/></td><td>Chinese</td>
<td><input type="checkbox" name="indian"/></td><td>Indian</td>
<td><input type="checkbox" name="lebanese"/></td><td>Lebanese</td>
<td><input type="checkbox" name="peruvian"/></td><td>Peruvian</td>
<td><input type="checkbox" name="sweets"/></td><td>Sweets</td>

</tr>

<tr>
<td><input type="checkbox" name="appetizers"/></td><td>Appetizers</td>
<td><input type="checkbox" name="cuban"/></td><td>Cuban</td>
<td><input type="checkbox" name="irish"/></td><td>Irish</td>
<td><input type="checkbox" name="mediterranean"/></td><td>Mediterranean</td>
<td><input type="checkbox" name="portuguese"/></td><td>Portuguese</td>
<td><input type="checkbox" name="thai"/></td><td>Thai</td>

</tr>

<tr>
<td><input type="checkbox" name="brazilian"/></td><td>Brazilian</td>
<td><input type="checkbox" name="french"/></td><td>French</td>
<td><input type="checkbox" name="italian"/></td><td>Italian</td>
<td><input type="checkbox" name="mexican"/></td><td>Mexican</td>
<td><input type="checkbox" name="southwestern"/></td><td>South Western</td>
<td><input type="checkbox" name="turkish"/></td><td>Turkish</td>

</tr>

<tr>
<td><input type="checkbox" name="cajun&creole"/></td><td>Cajun & Creole</td>
<td><input type="checkbox" name="german"/></td><td>German</td>
<td><input type="checkbox" name="japanese"/></td><td>Japanese</td>
<td><input type="checkbox" name="middle_eastern"/></td><td>Middle Eastern</td>
<td><input type="checkbox" name="spanish"/></td><td>Spanish</td>
<td><input type="checkbox" name="vietnamese"/></td><td>Vietnamese</td>

</tr>
</table>

 

Ill take a look at what you have posted for the examples and see if I understand whats going on :D

 

UPDATE: Ok i have looked it over, I understand whats going on now. So now I have a few more questions.

1) How do I incorporate so much data into a single (or a few) sessions?

2) I also have an image uploading script which is part of form2. Do you think id have to worry about anything with that?

3) Once all the session stuff is built how do I take all the data from the session and insert everything into the db?

Link to comment
Share on other sites

1) How do I incorporate so much data into a single (or a few) sessions?

 

Each form element will need to be stored in its own session. As thorpe showed you, the POST variables should be converted to sessions. As far as checkboxes, you will need to be familiar with arrays because a checkbox group will be stored in one session.

 

2) I also have an image uploading script which is part of form2. Do you think id have to worry about anything with that?

 

I have no idea about this one.

 

3) Once all the session stuff is built how do I take all the data from the session and insert everything into the db?

 

<?php
$query = "
INSERT into table(field1, field2)
VALUES ('" . $_SESSION['element1'] . "', '" . $_SESSION['element2'] . "')";
?>

 

I'm not a mod or anything here but I hope this gets you going in the right direction.

Link to comment
Share on other sites

As far as putting a ton of stuff into a session could I put it into an array then into a session and do something like this?

<?php 
// begin the session 
session_start(); 

// create an array 
$step1=array('comp_type', 'comp_name', 'comp_address', 'comp_phone', 'comp_desc', 
'comp_email',' comp_web') //I would include values for form 2 and 3 here to wouldnt I? 

// put the array in a session variable 
$_SESSION['signup']=$step1; 
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.