Html form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #16
    just for info: $_POST['key'] (with square brackets, but that's probably a typo)

    Comment

    • luckysanj
      New Member
      • May 2009
      • 68

      #17
      thank you, Dormilich for replying. It is now working.

      Is there any function on php which reads the last value of data on the database table.
      For eg: On database table
      tbl_a

      std_id name
      1 Ram
      2 Shyam
      3 Hari
      4 Kishor

      In these above table. I want to read that last value of std_id(4) through php function or any idea if u have .

      & one thing more is How to use primary key & foreign key on sql database.

      Comment

      • Ciary
        Recognized Expert New Member
        • Apr 2009
        • 247

        #18
        seems like there were a lot of typo's in my code. i also forgot mysql_select_db but you already knew i did.

        the request is very simple i think:
        Code:
        $result = mysql_query("SELECT * FROM tbl_a");
        $anArray = mysql_fetch_assoc($result);
        
        $lastRecord = $anArray[(count($anArray)-1)];
        for the question about primary key and foreign key, i would refer to the mysql forum since it isnt php anymore and ... i can't really answer that :-O

        Comment

        • luckysanj
          New Member
          • May 2009
          • 68

          #19
          It doesn't work ciary sir.

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #20
            that's because only the first row was fetched…

            depending on your DB system, there are functions that will fetch all results in one go (like PDOStatement->fetchAll()) where this would work.

            Comment

            • Markus
              Recognized Expert Expert
              • Jun 2007
              • 6092

              #21
              Use ORDER BY on std_id and then LIMIT 1.
              Code:
              SELECT * FROM `tbl_name` ORDER BY `std_id` DESC

              Comment

              • luckysanj
                New Member
                • May 2009
                • 68

                #22
                Thank you .

                Comment

                • Canabeez
                  New Member
                  • Jul 2009
                  • 126

                  #23
                  Originally posted by luckysanj
                  [code=php]
                  foreach($_POST as $key=>$value)
                  {
                  $$key=$value;
                  }[/code]
                  Hi, using this code won't protect you from SQL Injection, you're still inserting direct $_POST vars into your SQL query, I suggest you at least do something like:

                  [code=php]
                  $$key = addslashes($val ue);
                  /* or */
                  $$key=mysql_rea l_escape_string ($value);[/code]

                  And to be more accurate, the query for multiple inserts, as Markus mentioned
                  Multiple inserts, through one query, can be achieved with syntax like:

                  Expand|Select|W rap|Line Numbers
                  INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),( 4,5,6),(7,8,9);

                  Not sure what the earliest version of MySQL this will work with, but it does for 5.1.
                  that is available since mySQL 4, so it should work perfectly (in case you are using mySQL 4 or higher), otherwise you must probably have sql syntax error or your number of inserts is limited by configuration.

                  Comment

                  • luckysanj
                    New Member
                    • May 2009
                    • 68

                    #24
                    Thank you very much .

                    Comment

                    Working...