Jump to content

PHP Variables in URL


SamNewbie
Go to solution Solved by cyberRobot,

Recommended Posts

Hello,

 

I need some help on my PHP coding. I need the ?=ID to show up on the URL when the user logs in and then to be able to use GET['id'] to show the results (first name, surname, dob etc).

 

Below is my coding I have so far:

 

Heading.php - this is where the user will log in.

 

<div id="heading">
    <h2>Sports Pal</h2>
        <h5>Playing the same sport as you!</h5>
            <h5><a href="@">Home</a>:
            <a href="@">About</a>:
            <a href="@">Contact</a>:
            <a href="@">Advertise</a></h5>    
    <div class="signin">

<?php
    if ($_SESSION['loggedin'] == true){
          echo "<p>You are logged in.</p>\n";
    }else{
          echo "<p>Sign In:</p>\n";
    }
?>
     <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
        Username: <input type="text" name="liusername">
        Password: <input type="password" name="lipassword">
        <input type="submit" name="lisubmit" value="Sign In">
        </form>
    </div>      
</div>

 

Source code on profile.php

 

<?php
    include "./includes/nav.php";
?>

<div id="content">
    <h3>User Profile</h3>
    
<?php

    $query="SELECT user_id, user_firstname, user_surname, user_dob, user_gender FROM user";
    $result = mysql_query($query) or die (mysql_error());
    $row = mysql_fetch_array($result);


    
    if ($_GET['id'] == $_SESSION['id']);
    
    //if (isset($_GET['id'])){
        
        //$_GET['id'] == $_SESSION['id'];
            echo "<label>First Name: </label>";
            echo $row['user_firstname']."<br />";
            echo "<label>Surname: </label>";
            echo $row['user_surname']."<br />";
            echo "<label>Date of Birth: </label>";
            echo $row['user_dob']."<br />";
            echo "<label>Gender: </label>";
            echo $row['user_gender']."<br />";
            echo "<label>City: </label>";
    

?>
     <br />  
</div>

 

Many thanks for your help

 

 

 

Link to comment
Share on other sites

  • Solution

It looks like you're trying to have someone log in using the form. Once the form is submitted, you want to pull the user's information from the database which corresponds with the passed log in. If that's the case, you'll need to use $_POST variables since the form is set to POST.

 

Once you're familiar with using POST variables, you'll need to add them to a WHERE clause in your query. Don't forget to use mysql_real_escape_string():

http://www.php.net/mysql_real_escape_string

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.