+ Reply to Thread
Results 1 to 5 of 5

Thread: Changed php code but still have question

  1. #1
    thenewprogrammer is offline x10Hosting Member thenewprogrammer is an unknown quantity at this point
    Join Date
    Jul 2009
    Posts
    45

    Changed php code but still have question

    Having problems outputing information from a table called login. Database information is correct and users are in there under field 'username' .Noticed everyone's opinions on whats wrong with code havnt worked so far. Output is always User profile which is direct text in the head. When signed in. Since im new to php and dont understand everything wondering if the username has to be in the url for this to work? The username when i log in at first puts the username in the url for main page. But when i clicked profile the username isnt in the url anymore. Does it have to be in the url for this to work? if so how do i do it for this page.


    Code:
    <? 
    $user = $_GET['user']; 
    session_start(); 
     
    if(!isset($_SESSION['user'])){ 
    header("Location: http://thenewprogrammer.x10hosting.com");
    } 
     
    $dbhost = "localhost"; 
    $dbname = "*****"; 
    $dbuser = "*****"; 
    $dbpass = "*****"; 
     
    mysql_connect($dbhost, $dbuser, $dbpass) or die("Could not connect: ".mysql_error()); 
    mysql_select_db($dbname) or die("Could not select the database: ".mysql_error());
    $username = mysql_real_escape_string($user);
    $query = "SELECT * FROM login WHERE username ='".$username."'";
    $result = mysql_query($query);
    $row = mysql_fetch_array($result);
    ?>
    <html>
    <head>
    User Profile
    </head>
    <body>
    <?php echo($username); ?>
    <br />
    <?php print_r($row); ?>
    </body>
    </html>

  2. #2
    nexhunter's Avatar
    nexhunter is offline x10 Sophmore nexhunter is an unknown quantity at this point
    Join Date
    Nov 2007
    Location
    millbury,massachusetts
    Posts
    239

    Re: Changed php code but still have question

    ?user=username should be at the end of the url to grab the data or you could use an if statement to grab the profile of the user viewing the profiles page or if the url is set grab that users data
    PHP Code:
    if(isset($_GET['user'])){
    $user mysql_real_escape_string$_GET['user']); }
    else{
    $user $_SESSION['user'];} 
    Last edited by nexhunter; 07-28-2009 at 08:52 PM.



  3. #3
    thenewprogrammer is offline x10Hosting Member thenewprogrammer is an unknown quantity at this point
    Join Date
    Jul 2009
    Posts
    45

    Re: Changed php code but still have question

    added the if statement and changed url but it gives me the 404 error

  4. #4
    zapzack is offline x10 Elder zapzack is an unknown quantity at this point
    Join Date
    Jul 2009
    Posts
    606

    Re: Changed php code but still have question

    Erm... 404 = not found.. make sure it uploaded in the correct place And remove that if that the user above posted.. It would be a security vulnerability..
    Last edited by zapzack; 07-28-2009 at 06:21 PM.

  5. #5
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Changed php code but still have question

    Quote Originally Posted by thenewprogrammer View Post
    added the if statement and changed url but it gives me the 404 error
    Please post the url you are using to access the script.

    Also,

    Code:
    <head>
    User Profile
    </head>
    is bad HTML.

    Code:
    <head>
    <title>
    User Profile
    </title>
    </head>
    if you want it to be the title of the page, but not show up in the body.

+ Reply to Thread

Similar Threads

  1. Hybrid's HTML Lessons
    By Hybrid in forum Tutorials
    Replies: 18
    Last Post: 11-28-2009, 02:12 PM
  2. how can i convert Php pages and code into asp pages and code
    By n4tec in forum Scripts & 3rd Party Apps
    Replies: 11
    Last Post: 01-10-2009, 09:40 PM
  3. PHP Question
    By flashcreations in forum Programming Help
    Replies: 3
    Last Post: 09-20-2008, 06:03 AM
  4. PHP version not actually changed
    By blackhnd in forum Free Hosting
    Replies: 5
    Last Post: 09-19-2008, 06:28 AM
  5. currently have an application pending php
    By biomasti in forum Free Hosting
    Replies: 1
    Last Post: 09-03-2008, 01:58 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers