Quick PHP Question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mkx
    Confirmed User
    • Nov 2003
    • 4001

    #1

    Quick PHP Question

    I am using the following:

    [CODE]$sqlquery = "UPDATE `table` SET `name` = '$name' WHERE `id` = 'id1'";
    $results = mysql_query($sqlquery);/CODE]

    However, this only seems to be working for the ID that is 4 numerical characters long and not the ID that is 20 characters long with both numerical and alphabetical characters .

    Anyway to make this work with both?
  • ilbb
    Confirmed User
    • May 2005
    • 3025

    #2
    Use quotes exactly:
    $name = name
    $id = id of row in table

    $sqlquery = "UPDATE `table` SET `name` = '".$name."' WHERE `id` = '".$id."'";

    What data types do You have in Your sql table?

    Comment

    • ilbb
      Confirmed User
      • May 2005
      • 3025

      #3
      and Yes, If You want to work with 20chars id's check atrib ID datatypes:

      varchar (20) for alphabetical
      int (20) for numeric only

      Comment

      • mkx
        Confirmed User
        • Nov 2003
        • 4001

        #4
        ID = VARCHAR 20. It is also the Key. The script already pulls the ID from the url and when I echo ID1 on the page its correct

        Comment

        • mkx
          Confirmed User
          • Nov 2003
          • 4001

          #5
          Sorry - SET `name` = '55' name is already set in the script itself

          Comment

          • mkx
            Confirmed User
            • Nov 2003
            • 4001

            #6
            varchar (20) for alphabetical
            int (20) for numeric only

            What should I use for both? It looks something like this 907fasd90f78aha

            Comment

            • GFX Wiz
              Confirmed User
              • Jul 2004
              • 916

              #7
              Originally posted by mkx
              varchar (20) for alphabetical
              int (20) for numeric only

              What should I use for both? It looks something like this 907fasd90f78aha
              char (20)
              ICQ: 148.167.599

              Comment

              • mkx
                Confirmed User
                • Nov 2003
                • 4001

                #8
                still not working. sorry for the newb question but does anyone know how to just insert an increasing number into the ID table instead? Starting at 1. so each time a new entry is inserted, a new increasing id is created, 1, 2, 3 ., etc. I cant find my php for dummies book

                Comment

                • Sam Granger
                  Confirmed User
                  • Dec 2004
                  • 3958

                  #9
                  in phpmyadmin next to the attribute tick the auto_increment

                  $35-40 Per Signup, 60-70% Rev Share, over 80 Sites, Exclusive Sites, tons of free content
                  14,000+ Free hosted Galleries, RSS feeds, Domain Hosting, Embedded Flash Movies
                  Join Fetish Hits now!
                  ICQ: 358652230

                  Comment

                  • Sam Granger
                    Confirmed User
                    • Dec 2004
                    • 3958

                    #10
                    or just put auto_increment in your sql

                    $35-40 Per Signup, 60-70% Rev Share, over 80 Sites, Exclusive Sites, tons of free content
                    14,000+ Free hosted Galleries, RSS feeds, Domain Hosting, Embedded Flash Movies
                    Join Fetish Hits now!
                    ICQ: 358652230

                    Comment

                    • mkx
                      Confirmed User
                      • Nov 2003
                      • 4001

                      #11
                      Ok thanks, so how would I retype this line:

                      $sqlquery = "INSERT INTO $table VALUES('$txn_id','next........

                      Where I want to replace $txn_id with an auto increment number

                      Comment

                      • Phoenix66
                        Confirmed User
                        • Oct 2002
                        • 823

                        #12
                        Just omit the autoincrement field from your query, it will be generated automatically when you insert other fields.

                        Use mysql_insert_id() to obtain the value of that field right after the insert query, if you need it...
                        Adult Niche Traffic Exchange

                        Comment

                        • mkx
                          Confirmed User
                          • Nov 2003
                          • 4001

                          #13
                          Got it working, thanks!

                          Comment

                          Working...