Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

php help please

Options
  • 20-03-2006 3:34pm
    #1
    Closed Accounts Posts: 8,866 ✭✭✭


    Hi

    I have 3 scripts I want to edit slightly. The first is a basic form, which saves data to mysql database. Then there are 2 more forms, which can be used to edit details. All work as is. The second two scripts, call them edit1.php and edit2.php for example, can be used independantly at any time.

    What I would like is upon using the first script (call it create.php) it is directed to edit1.php and once that is completed it is then directed to edit2.php.

    Obviously directing scripts is easy, but if someone decides to use edit1.php on existing information I dont want them to be directed to edit2.php on submission of the new form.

    In simple terms, I need edit1.php and edit2.php to run off create.php, but still be able to use edit1.php and edit2.php independantly without the redirects from create.php. Am I making sense? :D


Comments

  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Actually, I can simplify that further. Create.php to edit1.php is fine as it is. But I need a hidden input to tell edit1.php if it should continue to edit2.php or not. Any help?


  • Registered Users Posts: 919 ✭✭✭timeout


    Simplest thing i can think of is a variable in the get to indicate which page redirected to edit1.php

    A hidden value in the create form that is not visable to the user might do it and then check it on the edit1.php page.

    So code would be somthing like this:
    $temp = $_GET['redirectedby']
    if($temp = "create.php")
      {
      do something;
      }else
      {
       do somthing else;
      }
    
    My PHP skills are slack of late.

    [edit] changed $_POST to $_GET
    [edit] Actually its really dependent on the form method <form action="edit1.php" method="get">


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    In my form on create.php i have this line:
    <input type=hidden name=custom_tour value=<?=$custom_tour?>>

    And then in edit1.php I have this:
    $custom_tour = $_POST

    if(isset($custom_tour)){
    header("location: p_tour_edit.php?id='$last_id'");
    exit();
    }else{
    header("location: p_tour_hotels.php");
    exit();
    }

    Should that work?


  • Registered Users Posts: 5,618 ✭✭✭Civilian_Target


    Sounds like you want $_GET to me.

    GETs go in the URL bar, POSTs go back as form data, so unless you're sending a POST to redirect to a GET-based page, you sound like you want GET all the way here.
    I'd recommend to sticking to either GET or POST for one variable and not mixing unless you really have to, it gets confusing.

    Depending on how much data you might want to store, you might want to consider using sessions - but it could also possibly be overkill.


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    I've tried both and neither seem to work... can someone give me some example scripting? A unique hidden field, and an if/else string example would be helpful, thanks!


  • Advertisement
  • Registered Users Posts: 249 ✭✭frost


    How are you moving from create.php to edit1.php?
    If you're using a form variable, and as civilian and timeout are saying, you need to submit your form on create.php to your second page using GET or POST.

    Here's an example using that method:

    create.php (or create.html):
    <form action='edit1.php' method='post'>
    <input type='hidden' name='custom_tour' value='1'>
    <input type='submit' value='continue'>
    </form>
    

    edit1.php:
    <?php  
       if ( $_SERVER['REQUEST_METHOD']=='POST' && $_POST['custom_tour']==1 ) {
          echo "You've come via POST from create.php";
       } else {
          echo "You've come directly here";
       }
    ?>
    

    You could also do this with session variables. Then you don't have to submit the form at all, for example, here I am just using a hyperlink:

    Create1.php
    <?php
       // Create1.php
       session_start();     // required in every script that uses session vars
       $custom_tour = '1';
       session_register('custom_tour'); // now this variable is available in all session-enabled scripts
    ?>     
    Look ma, no forms!<br>
    <a href='edit1a.php'>Go to edit1.php</a>
    

    Edit1a.php
    <?php  
       //edit1a.php
       session_start();     // required in every script that uses session vars
       if ($custom_tour==1) { 
          echo "You've come from create1.php";
          session_unregister('custom_tour');  // remove variable so the next time it won't be defined 
       } else {
          echo "You've come directly here";
       }
    ?>
    


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Neither option seems to have worked... I imagine the problem with the hidden input method is the fact that the form doesn't have edit1.php as its action. I have the form recalling itself as it must insert the data into the database. So create.php's form action is create.php and at the top of the script i have an 'if fields are set save data else present an empty form' command goin on.

    As for the session variable, the link I use from create.php to edit1.php is javascript, could that be why the session variable didnt work?


  • Registered Users Posts: 249 ✭✭frost


    the form doesn't have edit1.php as its action. I have the form recalling itself as it must insert the data into the database. So create.php's form action is create.php and at the top of the script i have an 'if fields are set save data else present an empty form' command goin on.
    Can you post your code?
    As for the session variable, the link I use from create.php to edit1.php is javascript, could that be why the session variable didnt work?

    If the session var is set correctly, it should work regardless of how you reach the second page. Do you have session_start(); at the top of both pages? Again, if you post your code it might be easier to help.


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    removed


  • Registered Users Posts: 249 ✭✭frost


    ok, i have them and will have a look later.
    (in future, if you dont want to put something up publicly you could just PM the files.)


  • Advertisement
  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Ok cheers frost, I got the session variable method to work, i had to change it to this:
    create.php
    session_start(); // required in every script that uses session vars
    session_register('custom_tour'); // now this variable is available in all session-enabled scripts
    $_SESSION = '1';

    edit1.php
    session_start(); // required in every script that uses session vars
    if ($_SESSION==1) {
    echo "You've come from create1.php";
    session_unregister('custom_tour'); // remove variable so the next time it won't be defined
    } else {
    echo "You've come directly here";
    }

    Cheers for pointing me in the right direction! ;)


  • Registered Users Posts: 249 ✭✭frost


    ah, you're way is better.

    my code must be taking advantage of a register_globals or some such setting that my development server has set.


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Yeah i think thats the case. As of Php 4 register_globals are set to off by default, due to security issues.


Advertisement