Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Join Date
    May 2002
    Location
    Philippines
    Posts
    480

    Question mySQL data storage

    I really don't understand it. How do you store the data from an HTML form to a MySQL db? All the tutorials I see are how to get data from them. Can anyone give a sample code?

  2. #2
    Join Date
    Jun 2004
    Location
    The Netherlands
    Posts
    153
    PHP Code:
    <?php 
    $host 
    "localhost"
    $user ""
    $pass ""
    $db ""

    mysql_connect($host $user  $pass); 
    mysql_select_db($db); 

    $sql "INSERT table_name (col1,col2) VALUES ('value1', 'value2')";

    mysql_query($sql);

    mysql_close();
    ?>
    Last edited by Project-A; 01-07-2005 at 11:53 AM.
    Bug? That's not a bug, that's a feature.
    LinkedIn - Twitter (dutch) - Work (dutch)

  3. #3
    Join Date
    May 2002
    Location
    Philippines
    Posts
    480
    thank you! thank you! thank you!

  4. #4
    Join Date
    Jan 2003
    Location
    Cookie Jar
    Posts
    971
    The VTMs show it well as well, I'd recommend a peek at those, they are superior to any other tutorials

  5. #5
    Join Date
    Dec 2004
    Posts
    28

    YEAH, VTMs the WAY TO GO

    The PHP and MySQL VTMs on the sample guestbook show specifically how to take form data and stick it into MySQL. The next one on the counter show you how to put your own generated data into the MySQL tables. But if you don't have a firm grip of PHP and MySQL I highly recommend the whole series first!

    ( If you can't find them, you just click on that long vertical bar about free video training on the right side of the main 3dbuzz.com site)

  6. #6
    Join Date
    May 2002
    Location
    Philippines
    Posts
    480
    Is the PHP version used in the VTMs 5 or 4? Because I'm using MySQL 4.1.x and PHP 5.0.x. I altered the sample code given by Project-A. Here it is:
    Code:
    <?php 
    $host="localhost"; 
    $user="root"; 
    $pass="1234"; 
    $db="test"; 
    
    $link=mysqli_connect($host,$user,$pass); 
    mysqli_select_db($link,$db); 
    $sql="insert into user
    (id,name,pword) values
    ('$acctid','$name','$pword')";
    mysqli_query($link,$sql);
    mysqli_close($link);
    ?>
    Assuming all the schemas and tables are made, I still have this problem when running it. I have a big feeling that something's still missing. I get this message:
    Notice: Undefined variable: acctid in C:\WebFiles\aurevoir\signup.php on line 11

    Notice: Undefined variable: name in C:\WebFiles\aurevoir\signup.php on line 11

    Notice: Undefined variable: pword in C:\WebFiles\aurevoir\signup.php on line 11
    This is the HTML code:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Au Revoir | Sign-Up</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    <form method="post" action="signup.php">
      <p><input name="acctid" type="hidden" value="12345678">
        Username:<input name="name" type="text" maxlength="15">
        <br>
        Password:<input name="pword" type="password" maxlength="10">
        <br>
        <input type="submit" name="Submit" value="Submit">
      </p>
    </form>
    </body>
    </html>
    Help again, please...

  7. #7
    Join Date
    May 2004
    Location
    Colorado
    Posts
    948
    well if you had register globals on, which you shouldnt, you need to get those variables depending on what method you defined int he form tag.
    so if the method is post, you need to either use $_POST[form element name] or $HTTP_POST_VARS[form element name], if you specified get you use $_GET[name], or $HTTP_GET_VARS[name]
    hope that helps you


    Absolute Power, its the only way to roll!

  8. #8
    Join Date
    May 2002
    Location
    Philippines
    Posts
    480
    I finally got it working. Thanks!

  9. #9
    Join Date
    Jan 2003
    Location
    Cookie Jar
    Posts
    971
    The PHP version in the VTMs is 4 though I dont think there should be any differences with what they do and PHP 5.

  10. #10
    Join Date
    Jun 2004
    Location
    The Netherlands
    Posts
    153
    Everything that done with version 4 also runs in 5, but some things are done faster in 5, and 5 has SQL Lite which is great.
    Bug? That's not a bug, that's a feature.
    LinkedIn - Twitter (dutch) - Work (dutch)

Page 1 of 2 12 LastLast

Posting Permissions

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