Results 1 to 8 of 8

Thread: PHP: Values inserted in wrong table

  1. #1
    Join Date
    Jul 2012
    Beans
    121
    Distro
    Ubuntu 12.04 Precise Pangolin

    PHP: Values inserted in wrong table

    hey

    i want to insert values in a table in a database and somehow end up inserting values in a table which i dont know where is (its really confusing)

    this is my code to insert values

    PHP Code:
    function about_me_insert($aname,$location,$occupation,$username)
    {
        
    $conn=db_connect();
     
    $result=$conn->query("update users set user_aname='".$aname."', user_location='".$location."', user_occupation='".$occupation."' where username='".$username."' ");
     
     if(!
    $result)
     {
         echo 
    "couldnt do it, sorry!!";
     }

        if (
    $result->num_rows>0) {
        throw new 
    Exception('Duplicate Details.');
      }
    else{
    echo 
    "Details saved with following parameters",$aname,$location,$occupation;}

    and this is the output of the
    Code:
    select * from table
    query

    Code:
    mysql> select * from users;
    +---------+----------+------------------------------------------+---------------------+-----------+----------------+--------------------+------------+-----------------------+-------------+---------------+--------------+-----------------+------------+
    | user_id | username | user_pass                                | user_email          | user_bday | user_lastvisit | user_login_attemps | user_posts | user_allow_viewonline | user_avatar | user_location | user_newpass | user_occupation | user_aname |
    +---------+----------+------------------------------------------+---------------------+-----------+----------------+--------------------+------------+-----------------------+-------------+---------------+--------------+-----------------+------------+
    |       5 | sid      | b1b3773a05c0ed0176787a4f1574ff0075f7521e | abcde@yahoo.co.in | NULL      |           NULL |               NULL |          0 |                  NULL | NULL        | home          | NULL         | NULL            | NULL       |
    +---------+----------+------------------------------------------+---------------------+-----------+----------------+--------------------+------------+-----------------------+-------------+---------------+--------------+-----------------+------------+
    1 row in set (0.00 sec)
    it says it inserts value in the tables, but it actually does something else, cause the output of that is empty

    and that 'home' in user_location is inserted by me through mysql itself

  2. #2
    Join Date
    Jan 2006
    Beans
    Hidden!
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: yet another php problem, values inserted in wrong table

    did you try turning on autocommit or committing the changes from php code?

    side note: SQL injection much?
    I am infallible, you should know that by now.
    "My favorite language is call STAR. It's extremely concise. It has exactly one verb '*', which does exactly what I want at the moment." --Larry Wall
    (02:15:31 PM) ***TimToady and snake oil go way back...
    42 lines of Perl - SHI - Home Site

  3. #3
    Join Date
    Jul 2012
    Beans
    121
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: yet another php problem, values inserted in wrong table

    no i didnt commit the changes from php, how that can be done?
    also,how do i turn on autocommit?

    this is running on my local machine, so i dont think SOL injection might be the cause

    but this commit thing might be

  4. #4
    Join Date
    Jan 2006
    Beans
    Hidden!
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: yet another php problem, values inserted in wrong table

    google will help in either case ...

    http://us3.php.net/manual/en/pdo.commit.php
    I am infallible, you should know that by now.
    "My favorite language is call STAR. It's extremely concise. It has exactly one verb '*', which does exactly what I want at the moment." --Larry Wall
    (02:15:31 PM) ***TimToady and snake oil go way back...
    42 lines of Perl - SHI - Home Site

  5. #5
    Join Date
    Dec 2012
    Beans
    7

    Re: PHP: Values inserted in wrong table

    Icky, I'd go through a few more php/mysql tutorials if i were you.

  6. #6
    Join Date
    Jul 2012
    Beans
    121
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: PHP: Values inserted in wrong table

    which i am doing
    btw is there anything wrong with my code??

  7. #7
    Join Date
    May 2011
    Beans
    253
    Distro
    Ubuntu 15.10 Wily Werewolf

    Re: PHP: Values inserted in wrong table

    I took a quick glance, it doesn't look like it.

    As a suggestion though, maybe you could pull out the sql.
    Code:
    $sql = "UPDATE users
               SET user_aname='".$aname."', user_location='".$location."', user_occupation='".$occupation."'
            WHERE username='".$username."'";
    
    $result=$conn->query($sql);
    Helps me more easily debug queries.
    (I did not change your query. There may be errors in it.)
    Kevin Harper
    http://www.kevinharper.com/


    Ubuntu: Because rebooting is ONLY for installing hardware

  8. #8
    Join Date
    Jul 2012
    Beans
    121
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: PHP: Values inserted in wrong table

    ok,i'll try this way also

Bookmarks

Posting Permissions

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