SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2005
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting variables into DB

    I have 7 variables I want to get into a database. Say they are $var1 $var2 $var3....

    How will I get them into the table "variables" thats in my database? The database has 7 fields, lets call them field1 field2 field3....

    This is the only code I have:
    Code:
    $dbh=mysql_connect ("localhost", "e39m5_conad1", "password") or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db ("e39m5_consys"); 
    
    $turnsuser = $_POST['turns'];
    mysql_query("UPDATE users SET turns='$newturns' WHERE id='$id'");
    Thanks,
    e39m5

  2. #2
    Pandora Tipem's Avatar
    Join Date
    Feb 2006
    Posts
    450
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    // mysql query
    mysql_query("INSERT INTO myTblName (field1, field2, field3, field4, field5, field6, field7) VALUES ('$var1', '$var2', '$var3', '$var4', '$var5', '$var6', '$var7')"); 
    Field1, field2 are you fields. Var1, var2 are your field datas respectively.
    Tipem no fancy sig, yup
    Need Neopets Help? Try Neopets
    fun adoptable eggs

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2005
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! ahh, one more thing... Field 1 is auto increment, what do I put there?

    e39m5

  4. #4
    SitePoint Guru themightystephen's Avatar
    Join Date
    Mar 2005
    Location
    England
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If your saying that Field 1 is the primary key field then you can just ignore it when stating the fields and inserting values, like this:

    PHP Code:
    // mysql query 
    mysql_query("INSERT INTO myTblName (field2, field3, field4, field5, field6, field7) VALUES ('$var1', '$var2', '$var3', '$var4', '$var5', '$var6')"); 
    Basically the first variable you put into values is put into field2 and var2 is put into field3 etc.
    Get your heelys now at flywalk.co.uk - But what are heelys?
    Heelys are simply shoes with wheels in the heels!

    Flywalk.co.uk - The UK Heelys Retailer


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
  •