how to send values to another page

php India
  • 14 years ago
    Here i am having problem in sending values to another page.
    this is my first program here i am having userid .
    index.php
    <?php

    $userid=$_POST['userid'];
    $password=$_POST['password'];
    $_SESSION['userid']=$userid;
    $_SESSION['password']=$password;
    $Http_Host = $_SERVER['HTTP_HOST'];
    $sqlServer =@mysql_connect('localhost','root','') or die("Unable to connect to mysql ");
    $db = mysql_select_db("mssi",$sqlServer) or die("Unable to connect to Users dabase");
    $result = mysql_query("select * from users where username='$userid' and password='$password'");
    $users = mysql_num_rows($result);
    if($users>0)
    {
       $ROW = mysql_fetch_array($result,MYSQL_ASSOC);
      include("index2.php");
    }
    else
    {
    include("index.php");
    echo "<html><head><script type=\"text/javascript\">alert (\"Please Enter Correct Username and Password\");</script></head></html>";
    }
    ?>

    If the given userid and pwd is correct then it includes index2.php.
    index2.php file.
    <html>
    <body>
     <a href="#">Home</a> <a href="tutorial.php">Tutorials</a>
                <a href="presentations.php">Presentations</a> <a href="recuritertraining.php">Recruiter
                Training</a> <a href="contactinfo.php">Contact Info</a> <a href="Message.php">Message
                Board</a>

         
    <a href="imagepath.php">Photos</a>

    <?
    if($_SESSION['userid']=='administrator')
    {
    ?>
    <a href="users.php">Insert User</a>
    <a href="userdelete.php">Delete User</a>
    <?
    }
    ?>            <a href="changepwd.php">Change Password</a>
                <a href="index.php" target="_parent">Logout</a>

    <?php  include("news.php");?>
    </body>
    </html>

    if i click the links in the <a> tags, i want to send the userid to that page.

    any one of know Please help.


























































  • 14 years ago

    rahha,

       To send something as simple as userid, send it as GET data. Change something like:

    <a href="changepwd.php">Change Password</a> to

    <a href="changepwd.php?userid=<?=$userid?>">Change Password</a>


      
    On the changepwd.php page, you would access the userid GET fiels as $_GET['$userid'].
       When you are more comfortable with PHP, I would recommend you use some type of Model-View-Controller(MVC) design pattern. Mixing your code and html with a bunch of <? ?> tag will get messy very quickly.

                             - Howard

  • 14 years ago
    Thank you Howard for your response.

    I will do like this the username will be displayed in the URL.
    I dont want to show my username.
    Is there any other way to solve this with our MVC.
    I know MVC. But i want to know the solution for this with out using MVC.

    Ok. My problem was solved in other way. I am using encryption and decryption.










  • 13 years ago

    It sounds to me like you want to use a session.

    In the page you are coming from you will need this:

    <?
        session_start();//starts a session
        $_SESSION['userid']=$userID;//after the user has logged in
    ?>


    In the page you are going to you will need this:

    <?
        session_start();//starts a session
        $userID=$_SESSION['userID'];
    ?>



    Beware though, as session_start() needs to be called before any output is sent to the browser. Have a look at the php manual for more information on sessions.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The trouble with programmers is that you can never tell what a programmer is doing until it's too late.” - Seymour Cray