SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Mar 2004
    Location
    NY
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question inserting forms values into MySQL

    Hi all,

    I have an HTML form with many checkbox values and textareas. I want to insert the value of the checked checkbox to be inserted into a mysql database. I am not sure how I can do this. can someone guide me as to what the first step is??

    I'd appreciate the help...thanks.

  2. #2
    SitePoint Enthusiast Rouven's Avatar
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    Connect to the database:

    <?php
    include "config.db.php"?>

    // Config.db.php looks like this:

    //<?php
    //$user = "usr";              // Benutzername
    //$password = "*****";             // Passwort
    //$db       = "database";            // Name der Datenbank
    // $hostname = "localhost";  // Hostname

    //$link = mysql_connect($hostname, $user, $password);
    //if(!$link): die("Kann den Server nicht erreichen"); endif;
    //mysql_select_db($db) or die("Could not connect to database:".mysql_error());
    //
    ?>


    // check if form was submitted
    <?
    if(isset($_POST["send"]))
    {
    //then add the data to you database:

        
    mysql_query("INSERT INTO database (id, name, last_name) VALUES (NULL, '".$_POST["name"]."', '".$_POST["last_name"]."')");
        
    $num mysql_affected_rows();
        if (
    $num 0
        {
            print 
    "Positive!";
        }
        else
        {    
            print 
    "Negative!";
        }
    }
    ?>


    <? // Actual form ?>
    </span>
    <form action="<?php $_SERVER["PHP_SELF"]?>" method="post" name="Form" id="Form">
      
    </b>

          <br />
          Last name:<br />
         <input type="text" name="last_name" />
          <br />
          <br />
          First Name:<br />
          <input name="name" type="text" id="name" />
                <input name="send" type="submit" id="send" value="Send" />
          <input type="reset" name="Reset" value="Reset" />
       
      </p>
      
    </form>
    <?php mysql_close($link);?>
    Should work.


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
  •