send data....

Discussion in 'PHP' started by Namuk, Feb 18, 2008.

  1. #1
    how do i send the same data that i enter for login?... i want to send the same data to the next page(page if the login success).

    how i can do it.... i need the data(userid form login) to the next page(successful login) for query.

    please help me....


    thanks.GBU
     
    Namuk, Feb 18, 2008 IP
  2. DarkMindZ

    DarkMindZ Guest

    Messages:
    175
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I dont really understand, but maybe you can save them in a $variable, and use them later on? ;s explain more please
     
    DarkMindZ, Feb 18, 2008 IP
  3. 00johnny

    00johnny Peon

    Messages:
    149
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    sounds like you should do some php or whatever language your using in php you get variables by either
    $_GET['varName']
    or
    $_POST['varName']

    depending on if your using the post or get
     
    00johnny, Feb 18, 2008 IP
  4. Namuk

    Namuk Peon

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thanks....
    ok. i has 2 page.. one is a login page(page 1) and the other one is page(page 2) if the login success.

    so... in a login page, i need to enter "user id" and "password" and send($_POST) it to it self page(login page) to validate the user id and password. if the validation success(true) it will go to the next page(page 2).

    but my problem is.... i want the "user id" from page 1 send to page 2. in the page 2, i want to use the "user id" to query database. if login success and go to page 2... the database will be automatic appear(not need the button search).
     
    Namuk, Feb 18, 2008 IP
  5. decepti0n

    decepti0n Peon

    Messages:
    519
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #5
    sessions. after you have a successful login on the first page, set $_SESSION['data'] = 'whatever'; Then redirect to page 2. And at the top of both pages, you'll have to add session_start();
     
    decepti0n, Feb 18, 2008 IP
  6. Namuk

    Namuk Peon

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    it still can not function.....
    this is my code... please tell me where part i wrong...

    page 1.
    -------------------------------
    <?php
    session_start();
    $_SESSION['userid']='userid';
    $db = mysql_connect("localhost", "root", "gade") or die("Could not connect.");
    if(!$db)
    {
    die("no db");
    }
    if(!mysql_select_db("gade",$db))
    {
    die("No database selected.");
    }
    if($_POST['userid']!='' && $_POST['password']!='')
    {
    $userid=mysql_real_escape_string($_POST['userid']);
    $password=mysql_real_escape_string($_POST['password']);
    $result=mysql_query("SELECT * FROM userhtl WHERE userid='$userid' AND password='$password'");

    if(mysql_num_rows($result)==1)
    {
    $row = mysql_fetch_assoc($result);
    $_POST['userid'] = $row['userid'];
    header("Location: 7.php");

    }
    else
    {
    //Validation failed
    $error = 'login error';
    echo 'Wrong User ID or Password!!';
    }
    }
    else
    {
    echo 'Please insert user id and password';
    }
    @mysql_close();
    ?>

    ----------------------------------------------------------

    and this is the second page. (page 2).
    ------------------------------------------------

    <?php
    session_start();

    $db = mysql_connect("localhost", "root", "gade") or die("Could not connect.");
    if(!$db)
    {
    die("no db");
    }
    if(!mysql_select_db("gade",$db))
    {
    die("No database selected.");
    }
    $_SESSION['userid']='$userid';

    $sql = "SELECT * FROM hotel WHERE userid='$userid'";
    $result = mysql_query($sql);

    echo '<strong>Hotel information</strong>';
    echo "<table border='1'>
    <tr>
    <th>Hotel Id</th>
    <th>Hotel Name</th>
    <th>Information</th>
    <th>Address</th>
    <th>Contact Number</th>
    <th>Email</th>
    </tr>";
    while($row = mysql_fetch_array($result))
    {
    echo "<tr>";
    echo "<td>" . $row['hotelid'] . "</td>";
    echo "<td>" . $row['name'] . "</td>";
    echo "<td>" . $row['info'] . "</td>";
    echo "<td>" . $row['address'] . "</td>";
    echo "<td>" . $row['contactno'] . "</td>";
    echo "<td>" . $row['email'] . "</td>";
    echo "</tr>";
    $hotel=$row['hotelid'];
    }
    //}
    echo "</table>";

    $sql = mysql_query("select hotelid,room_type,full,available,star from booking where hotelid= '$hotel'");
    echo '<strong>Booking Information</strong>';
    echo "<table border='1'>
    <tr>
    <th>Hotelid</th>
    <th>Room Type</th>
    <th>Full</th>
    <th>Rome Available</th>
    <th>Room Rating</th>
    </tr>";
    while($row = mysql_fetch_array($sql))
    {
    echo "<tr>";
    echo "<td>" . $row['hotelid'] . "</td>";
    echo "<td>" . $row['room_type'] . "</td>";
    echo "<td>" . $row['full'] . "</td>";
    echo "<td>" . $row['available'] . "</td>";
    echo "<td>" . $row['star'] . "</td>";
    echo "</tr>";
    }
    echo "</table>";

    ?>

    -----------------------------------------------------

    please tell me where i m wrong....
     
    Namuk, Feb 18, 2008 IP
  7. Namuk

    Namuk Peon

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    i am already got the answer,,,
    thanks for the help....

    my problem here is i m wrong to set the session_start()..
    actually the place of session_start() at the head of page before html....



    thanks....
     
    Namuk, Feb 18, 2008 IP