help me with my update.php

Discussion in 'PHP' started by chinhelhas, Oct 18, 2009.

  1. #1
    <?php
    session_start();
    $_SESSION['username'];


    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = '1234';
    $dbname = 'sessions';

    mysql_connect($dbhost, $dbuser, $dbpass) or die("Could not connect: ".mysql_error());
    mysql_select_db($dbname) or die(mysql_error());


    $update = $_POST['update'];

    $query = ("UPDATE register
    set files = '$update'
    WHERE username = '$_SESSION['username']'");

    mysql_query($query) or die(mysql_error());


    echo "Username: " . $_SESSION['username'];


    echo "File updated";
    echo "<br>";
    include('home.php');

    ?>

    i dont know what's the problem with this but when i remove $_session['username'] and the WHERE part it works please fix my sample program I've tried to explore but i need more support thnx in advance:confused:
     
    chinhelhas, Oct 18, 2009 IP
  2. Brandon_R

    Brandon_R Peon

    Messages:
    330
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It would be wise to post the error that PHP returns.
     
    Brandon_R, Oct 18, 2009 IP
  3. chinhelhas

    chinhelhas Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thnks for the replies good job its already fixed
     
    chinhelhas, Oct 18, 2009 IP
  4. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #4
    good that you solved it yourself. Just curious to know what is $_SESSION['username']; along doing on 3rd line of your script? It has no effect to code anyways.

    Just to tell you little more.. have habit of using {} around variables inside double quoted string, specially if that variable is of array or object.

    The query would somewhat look like this after above changes..

    
    $query = ("UPDATE register
    set files = '{$update}'
    WHERE username = '{$_SESSION['username']}'");
    
    PHP:
     
    mastermunj, Oct 18, 2009 IP
  5. chinhelhas

    chinhelhas Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thats my mistake i dont know that i can put $_Session['username'] to a variable but ive already fixed it. my code looks like this now
    $username = $_SESSION['username'];

    $query = "UPDATE register
    set files = '$update'
    WHERE username = '$username'";


    you know how to use frame? can u please give me some example with that so that when i click a link the page doesn't refresh everything. thnx
     
    chinhelhas, Oct 18, 2009 IP
  6. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #6
    mastermunj, Oct 18, 2009 IP
  7. chinhelhas

    chinhelhas Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    why is that so? im just going to use frame for the link: home,profile,contact us, services then that's all. thnks for the links. can u add me ym?
     
    chinhelhas, Oct 18, 2009 IP
  8. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #8
    I would not recommend that way of keeping links for home, profile, contact us and other main links on website.

    More over, from the perspective of SEO also you should keep such links as direct links rather than inside iFrame.
     
    mastermunj, Oct 18, 2009 IP
  9. chinhelhas

    chinhelhas Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    its not literary inside the frame it looks like this one

    | HOME | PROFILE | PRODUCTS | CONTACT US | // THIS IS OUTSIDE THE FRAME
    ________________________________________________________
    HOME
    BLA BLA BLA BLA BLA BLA BLA BLA BLA BLA BLA BLA BLA BLA BLA BLA BLA BLA // INSIDE THE FRAME

    ________________________________________________________

    what i want is that when i click the home at the upper part the contents inside the frame will be change. i don't know what to call it. forgive if im mistake.
     
    chinhelhas, Oct 18, 2009 IP
  10. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #10
    Yes, this can be done and will be easier to do and user's will also feel good about it, but let few things be plain simple.

    However, if at all you want to implement the asked solution, please refer to the links I have given in my previous post.
     
    mastermunj, Oct 18, 2009 IP