Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Nov 2006
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    changing all '&id=' to '&sn=' in php script

    hello.

    i have a php member script and whenever you view other members' profile, the url is member/member&id=usernamehere.

    how can i change all &id= to &sn= for html validation sake?

    below is the PHP code i use for member.php
    PHP Code:
    <?php

    $id 
    mysql_real_escape_string $_GET['id'] );

    if ( isset ( 
    $id ) ) {
    $result mysql_query "SELECT * FROM users WHERE username='$id'" );
    $member mysql_fetch_array $result );
    }

    $file_title "Member Profile:split:$member[username]";

    function 
    DisplayInfo$header$content ) {
    global 
    $sitetitle$member;

    echo 
    "<tr><td><b>$header</b></td><td width='3'></td><td>";

    if ( empty ( 
    $member[$content] ) ) {
    echo 
    "Not Available";
    } else {

    switch ( 
    $content ) {
    case 
    "registered_on":
    echo 
    DisplayDate"$member[registered_on]""M d Y, h:i A""1" );
    break;

    case 
    "last_activity_time":
    echo 
    DisplayDate"$member[last_activity_time]""M d Y, h:i A""1" );
    break;

    case 
    "timezone":
    if ( 
    $member[dst] == ) {
    $timezone = ($member[timezone]+date("I"));
    } elseif ( 
    $member[dst] == ) {
    $timezone $member[timezone];
    }
    $zone 3600*($timezone-2);
    echo 
    gmdate 'h:i A'time() + $zone );
    break;

    case 
    "last_activity_url":
    if ( ( 
    time() - $member[last_activity_time] ) <= 300 ) {
    echo 
    "<font color='green'>Online</font>";
    } else {
    echo 
    "<font color='red'>Offline</font>";
    }
    break;

    case 
    "email_address":
    echo 
    "<a href='mailto: $member[email_address]'>Send an Email</a>";
    break;

    case 
    "website":
    if ( 
    ereg "www.|http://."$member['website'] ) ) {
    echo 
    "<a href='$member[website]' target='_blank'>Visit</a>";
    } else {
    echo 
    "<a href='http://$member[website] target='_blank'>Visit</a>";
    }
    break;

    case 
    "aim":
    $user_aim str_replace " ""+"$member[aim] );
    $aim_site_name str_replace " ""+"$sitetitle );
    echo 
    "<a href='aim:goim?screenname=$user_aim&message=Hi!+I+saw+you+from+$aim_site_name'>$member[aim]</a>";
    break;

    case 
    "gender":
    if ( 
    $member[gender] == "m" ) {
    echo 
    "Male";
    } elseif ( 
    $member[gender] == "f" ) {
    echo 
    "Female";
    } else {
    echo 
    "Not Telling";
    }
    break;

    case 
    "bday_month":
    if ( ( 
    $member[bday_month] == "-" && $member[bday_day] == "-" ) || ( $member[bday_month] != "-" && $member[bday_day] == "-" ) ) {
    echo 
    "Not Available";
    } elseif ( 
    $member[bday_month] == "-" && $member[bday_day] != "-" ) {
    echo 
    $member[bday_month];
    } else {
    echo 
    "$member[bday_month] $member[bday_day]";
    }
    if ( !empty ( 
    $member[bday_year] ) ) {
    echo 
    ", $member[bday_year]";
    }
    break;

    default:
    echo 
    "$member[$content]";

    echo 
    "</td></tr>";
    }

    }

    if ( isset ( 
    $id ) && !empty ( $id ) && mysql_num_rows $result ) > && ( eregi "^[a-z0-9\-_\.]+$"$id ) ) ) {
    echo 
    "<center><b>Viewing Profile: $member[username]</b><p>";
    if ( empty ( 
    $member[avatar] ) ) {
    echo 
    "<img src='$site_url/$script_folder/images/avatars/none.gif' width='60' height='60'>";
    } else {
    list ( 
    $avatar_width$avatar_height ) = getimagesize "$member[avatar]" );
    if ( 
    $avatar_width 60 || $avatar_height 60 ) {
    echo 
    "<img src='$member[avatar]'>";
    } else {
    echo 
    "<img src='$member[avatar]'>";
    }
    }
    echo 
    "<p></center>";
    ?>
    <table width="100%" cellpadding="0" cellspacing="0"><tr>
    <td width="49%">

    <fieldset>
    <legend class="main">Statistics</legend>
    <table cellpadding="0" cellspacing="5" class="main" align="center">
    <?php 
    DisplayInfo
    $header="Joined"$content="registered_on" ); 
    DisplayInfo$header="Posts"$content="posts" ); 
    DisplayInfo$header="Last Active"$content="last_activity_time" ); 
    DisplayInfo$header="User's Time"$content="timezone" ); 
    DisplayInfo$header="Status"$content="last_activity_url" ); 
    ?>
    </table>
    </fieldset>

    </td>
    <td width="5"></td>
    <td width="49%">

    <fieldset>
    <legend class="main">Contact Information</legend>
    <table cellpadding="0" cellspacing="5" class="main" align="center">
    <?php 
    DisplayInfo
    $header="Email"$content="email_address" ); 
    DisplayInfo$header="Website"$content="website" ); 
    DisplayInfo$header="MSN"$content="msn" ); 
    DisplayInfo$header="AIM"$content="aim" ); 
    echo 
    "<tr><td><b>PM</b></td><td width='3'></td><td><a href='$site_path/pm_compose&to=$member[username]'>Send PM</a><td></tr>";
    ?>
    </table>
    </fieldset>

    </td>
    </tr></table>


    <table height="7"><tr><td></td></tr></table>


    <table width="100%" cellpadding="0" cellspacing="0"><tr>
    <td width="49%">

    <fieldset>
    <legend class="main">Personal Information</legend>
    <table cellpadding="0" cellspacing="5" class="main" align="center">
    <?php 
    DisplayInfo
    $header="Gender"$content="gender" ); 
    DisplayInfo$header="Birthday"$content="bday_month" ); 
    DisplayInfo$header="Location"$content="location" ); 
    ?>
    </table>
    </fieldset>

    </td>
    <td width="5"></td>
    <td width="49%" valign="top">

    <fieldset>
    <legend class="main">Additional Information</legend>
    <table height="55" cellpadding="0" cellspacing="5" class="main" align="center">
    <?php 
    if ( empty ( $member[biography] ) ) {
    echo 
    "<tr><td style='text-align: justify'>$member[username] has not written anything about ";
    if ( 
    $member[gender] == "m" ) {
    echo 
    "himself";
    } elseif ( 
    $member[gender] == "f" ) {
    echo 
    "herself";
    } else {
    echo 
    "himself/herself";
    }
    echo 
    ".</td></tr>";
    } else {
    echo 
    "<tr><td style='text-align: justify'>$member[biography]<td></tr>";
    }
    ?>
    </table>
    </fieldset>

    </td>
    </tr></table>
    <?php
    } else {
    echo 
    "<center>There are no users in our database with that username</center>";
    }
    ?>

  • #2
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    PHP Code:
    $id mysql_real_escape_string $_GET['sn'] ); 
    Then use member/member&sn=usernamehere. as the url.

  • #3
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    the validator will be complaining about the use of literal &s, not the 'id' after it. Instead of &, you should use &amp;

  • #4
    New Coder
    Join Date
    Nov 2006
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by GJay View Post
    the validator will be complaining about the use of literal &s, not the 'id' after it. Instead of &, you should use &amp;
    omg that made my errors from 27 to 2 in the validation checker

  • #5
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Having a site validate isn't all that good. Don't live by the validation.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •