Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. My php and Msql problems

My php and Msql problems

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
helpphpdatabasemysql
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hathyan
    wrote on last edited by
    #1

    Hi I just have that stupid problem and hoping that you can help me on it. I try to take specific value (user ID for selected user name) from my database to deal with it. but it's seems that nothing happen ! :confused: the code is:

    $query2 = MYSQL_QUERY("SELECT userid FROM users WHERE username LIKE '" . $username . "'") ;

            while ($result2 = MYSQL\_FETCH\_ARRAY($query2)) {
            $found2 = '1'; $userid2 = $result2\['id'\]; }
    

    echo $userid2;

    K H C 3 Replies Last reply
    0
    • H hathyan

      Hi I just have that stupid problem and hoping that you can help me on it. I try to take specific value (user ID for selected user name) from my database to deal with it. but it's seems that nothing happen ! :confused: the code is:

      $query2 = MYSQL_QUERY("SELECT userid FROM users WHERE username LIKE '" . $username . "'") ;

              while ($result2 = MYSQL\_FETCH\_ARRAY($query2)) {
              $found2 = '1'; $userid2 = $result2\['id'\]; }
      

      echo $userid2;

      K Offline
      K Offline
      Kevin Schaefer
      wrote on last edited by
      #2

      Try changing your query to:

      $query2 = MYSQL_QUERY("SELECT userid FROM users WHERE username='$username';") ;

      I also think you need to SELECT the username as well, since that is what you are comparing:

      $query2 = MYSQL_QUERY("SELECT userid,username FROM users WHERE username='$username';") ;

      1 Reply Last reply
      0
      • H hathyan

        Hi I just have that stupid problem and hoping that you can help me on it. I try to take specific value (user ID for selected user name) from my database to deal with it. but it's seems that nothing happen ! :confused: the code is:

        $query2 = MYSQL_QUERY("SELECT userid FROM users WHERE username LIKE '" . $username . "'") ;

                while ($result2 = MYSQL\_FETCH\_ARRAY($query2)) {
                $found2 = '1'; $userid2 = $result2\['id'\]; }
        

        echo $userid2;

        H Offline
        H Offline
        hathyan
        wrote on last edited by
        #3

        I solved my problem As i write, it's a stupid one :$ I replace this

        $userid2 = $result2['id'];

        by this one

        $userid2 = $result2['userid'];

        thanks anyway !! :rose:

        1 Reply Last reply
        0
        • H hathyan

          Hi I just have that stupid problem and hoping that you can help me on it. I try to take specific value (user ID for selected user name) from my database to deal with it. but it's seems that nothing happen ! :confused: the code is:

          $query2 = MYSQL_QUERY("SELECT userid FROM users WHERE username LIKE '" . $username . "'") ;

                  while ($result2 = MYSQL\_FETCH\_ARRAY($query2)) {
                  $found2 = '1'; $userid2 = $result2\['id'\]; }
          

          echo $userid2;

          C Offline
          C Offline
          cjoki
          wrote on last edited by
          #4

          I debug sql queries by these methods... 1) echo the sql to a browser so I can test in the Mysql Query Browser to make sure that all variables are set as expected and the query is good. I also include page, line # and the mysql error message in the die command. So if any query is bad you will know where and what and why (<--most of the time). example:

          $sql = "select uid from users where uname='".$user_name."'";
          $rst = mysql_query($sql) or die("
          PG: ".__FILE__."
          LN: ".__LINE__."
          ER: ".mysql_error()."
          Q: ".$sql."
          ");

          Note: I usually do this as a function call inside the die so I can set a value for local debug and a live production messages. This is because the above information should be used for the developer and not something a user should ever see. Users should have a simple error message if you can not recover from the error in code. 2) if your code crashes out after the mysql_query, then find out what you query is returning...exactly. example:

          That should give you more info. Also keep in mind that if you develope on windows and move to linux you will see some error with the case of table and column names make sure you check that. Windows can be lax on case, while linux is not.

          Chris J www.redash.org

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups