www.webdeveloper.com

View Poll Results: Can someone fix it?

Voters
2. You may not vote on this poll
  • yes

    0 0%
  • no

    2 100.00%
Results 1 to 3 of 3

Thread: Help PHP,session,Mysql

  1. #1
    Join Date
    Oct 2009
    Posts
    28

    Talking Help PHP,session,Mysql

    can someone help me fix this program? the program will update data to the database but in a specific way like I just want to update the data from the user that log in. thats all please fix this below:




    <?php
    session_start();

    $dbhost = "localhost";
    $dbname = "sample";
    $dbuser = "root";
    $dbpass = "1234";

    $_SESSION['username']

    mysql_connect($dbhost,$dbuser,$dbpass) or die("Cannot connect to database: ". mysql_error());
    mysql_select_db($dbname) or die(mysql_error());

    $insert = $_POST['insert'];

    $query = "INSERT INTO files(file)
    VALUES('$insert')
    WHERE username = '$username'";

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

    echo "File Inserted";
    include('../sample/menu.php');

    mysql_close();
    ?>


    ___________________________________________

  2. #2
    Join Date
    Oct 2009
    Posts
    25
    $username is not defined in your script.
    Try this:
    PHP Code:
    <?php
    session_start
    ();

    $dbhost "localhost";
    $dbname "sample";
    $dbuser "root";
    $dbpass "1234";

    $username $_SESSION['username']

    mysql_connect($dbhost,$dbuser,$dbpass) or die("Cannot connect to database: "mysql_error());
    mysql_select_db($dbname) or die(mysql_error());

    $insert $_POST['insert'];

    $query "INSERT INTO files(file)
    VALUES('
    $insert')
    WHERE username = '
    $username'";

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

    echo 
    "File Inserted";
    include(
    '../sample/menu.php');

    mysql_close();
    ?>

  3. #3
    Join Date
    Oct 2009
    Posts
    25
    PHP Code:
    <?php
    session_start
    ();

    $dbhost "localhost";
    $dbname "sample";
    $dbuser "root";
    $dbpass "1234";

    $username $_SESSION['username'];

    mysql_connect($dbhost,$dbuser,$dbpass) or die("Cannot connect to database: "mysql_error());
    mysql_select_db($dbname) or die(mysql_error());

    $insert $_POST['insert'];
    $query 'INSERT INTO files(file) VALUES('$insert')  WHERE username = "'$username .'";

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

    echo "File Inserted";
    include('
    ../sample/menu.php');

    mysql_close();
    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles