Jump to content

passing array in url


phpme1221

Recommended Posts

So far what i have up top

 

session_start();

if(isset($_SESSION['view'])){

  if($_SESSION['view'] == 1){

  exit("Host already registered!");

}

}

 

MIDDLE is the FORM code

 

BOTTOm is where i am not sure what you mean ? i have tried this but not sure

 

unset($_SESSION['view']);

 

how do i know if this will work without submitting the form just yet?

Link to comment
Share on other sites

  • Replies 62
  • Created
  • Last Reply

Top Posters In This Topic

So far what i have up top

 

session_start();

if(isset($_SESSION['view'])){

  if($_SESSION['view'] == 1){

  exit("Host already registered!");

}

}

 

MIDDLE is the FORM code

 

BOTTOm is where i am not sure what you mean ? i have tried this but not sure

 

unset($_SESSION['view']);

 

how do i know if this will work without submitting the form just yet?

why are you unsetting the session value, that the opposite of what you would want to do.. at the bottom belongs..

 

$_SESSION['view'] = 1;

Link to comment
Share on other sites

my goodness you are on fire  :D i thought you need to clear it out first or unset the varibale/values.

nooo, basically what we are doing here is...the first time that a user clicks the link, there will not be a session that is set, so the code runs as normal...then at the end of execution we set a session to 1.. then the next time that the user would try to click on the page, they would get the error since the session is set

Link to comment
Share on other sites

yes and no,

 

ok whats happening is if the user does not remove the email keeps it for a while, that user still sees the values of the array, howerver as soon as i hit the refresh i get the message.  (already registered)

 

would it be better to not to see the parameter everytime they may click on an older email?  i tried redirecting them to another page to clear up the url with

header("Location: index.php"); doesnt work though

 

 

Link to comment
Share on other sites

you could redirect them yes, why wouldn't it work for you here? you would only need to change one line..

 

session_start();
if(isset($_SESSION['test'])){
      if($_SESSION['test'] == 1){
            header("Location: index.php");
      }
}

now when you refresh the page it should redirect you to the index page

Link to comment
Share on other sites

is reg.php the target page that the array is sent to?

Still not sure what you are trying to do, or how a form would have any relevance here.. but what you can do is display a form for each value in the array like so..

 

foreach($array as $value){
      print "<form action='#' method='POST'>
      $value Active = <input type='radio' name='active' value='Yes' /><input type='radio' name='active' value='No' /><br />
      Lease for Another 90 Days? <input type='radio' name='lease' value='Yes' /><input type='radio' name='lease' value='No' /><br />
      Description <textarea name='description' cols='5' rows='30'></textarea>
      <input type='submit' name='$value' value='Submit' />"; 
}

something like that perhaps, then you can grab the data based on which Host it is

 

if(isset($_POST['Host1'])){ //if the submit button for Host1 has been pressed
      // sanitize data, insert into database
}elseif(isset($_POST['Host2'])){ // is the submit button for Host2 has been pressed, etc...

}

did you see this post earlier...I addressed this

Link to comment
Share on other sites

no i did not see that in the earlier post; but thanks aykay,  what if you dont know the # of host to put in, shouldnt it be onw giant sql insert at the end ?

 

is reg.php the target page that the array is sent to?  YES

 

I am thinking, what if the user made a mistake in submitting form and wants to click the back button he will get the redirect page right?  Anyway around this problem? suggestions?

Link to comment
Share on other sites

AyKay,

 

After a user submitts the form, how do i end that session basically?  i dont want to use the below code , causes too many confusion with browser staying up and not clearing cache.

 

session_start();

if(isset($_SESSION['view'])){

if($_SESSION['view'] == 1){

  //exit("Host already registered!");

  header("Location: index.php");

$_SESSION['view'] = 1;

 

 

The user shuoud be able to view his hosts but unable to resubmit prompting an error message.  Before the user submits the user can view as many times his list of host, but as soon as the user hits submit he/she is not longer able to resubmit even from old emails?  i have created a field in mysql db, Register (yes or no) so if you hits submit then it is registered if he has not it is consider a NO not registered.  Therefore once he/she hits the submit, he or she is registered so how do i check everytime when the use hits submit if the parameter register is yes or no for that user?

Link to comment
Share on other sites

Hi Aykay,

 

Can you help me out once again, im trying to do a drop down instead of haveing the user see all the fields to enter, i want to show only 1 set of fieds with a drop down of host to choose from to enter registration, can you help me out, please

 

I have a so far gathered from the web but its confusing

 

 

Reg.php

 

//function dropdown

function generateSelect($name = '', $VM = array()) {

        $html = '<select name="'.$name.'">';

        foreach ($VM as $value) {

                $html .= '<option value='.$value.'>'.$VM.'</option>';

        }

        $html .= '</select>';

        return $html;

}

 

$html = generateSelect('VM', $value);

 

<select name="Host">

    <option value="0">Choose a server</option>

    <?php showOptionsDrop($VM, null, true); ?>

</select>

 

 

HELP!

Link to comment
Share on other sites

so you want it to be a drop-down list instead of radio buttons? try this..

 

print "<select name='selections'>";
foreach($array as $value){
      print "<option value='$value'>$value</option>";
}
print "</select>";

 

which is pretty much what you have, just a little different...what exactly are you having issues with here?

Link to comment
Share on other sites

Thank Aykay coming to the rescue,

 

I want the user to register there servers.  they will be sent an email and then they click on email with there server info with identification, which leads me to the next questions how do or if i could add another array or variable in same url their email address for identiification?  After they click on email they will be presented with a form to fill in their Server info to lease or use another 90 days.  What do you think is the easier of the 2 ways, a drop down or show the # of forms to fill in that corralates with the number of host from array? 

 

if they dont respond within 1 week i will resend email, and on the 2nd week from the day i send out i will shutdown server.  I can schedule that part. Hope that helps.

Link to comment
Share on other sites

i just want each individual owner of the server to register their server/s in the link they each get in the email.  I have show how the link looks like in the previous post, it will show each of the server they own and now they have to just register it by filling in the forms,

 

either i have 1 submit button for all forms but that seems way too difficult for me OR have multiple submit buttons for each servers they need to regiseter (own)  , remember a user may only need to register 1 server ( own 1 server )  hope that explains it much simpler than it sounds and to code  ;D

 

THANKS AYKAY

Link to comment
Share on other sites

okay I see what you are saying, what I would do is have one submit button that grabs all of the data, have conditions set (if/else statements) set for each individual form....if no data is grabbed from a specific form, don't do anything with that form, if data is grabbed from a form, store that specific data in your database.

 

Now if you decide to use a submit button for each form and don't want the page to refresh after the user submits...which is understandable, you can use either AJAX or jquery to submit the form, handle the data on the server, and output a response without refreshing the page...so that's an option here

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.