Q:

PHP is failing to create mySQL record via form

I have been setting up my first form/PHP/mySQL combo using info from different sites (including this one) and running it with MAMP on my local server.  Although the webpage always connects to the target DB successfully it hasn't been inputting the data I type into the MySQL table (I am checking with phpMyAdmin). 
You may see some stuff commented out of insert.php, this was stuff I had previously tried but didn't work. 
form on index.php
<form action="insert.php" method="post">
        Diet Name: <input type="text" name="name"><br/>
        Your Rating: <select type="int" name="rating">
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
            <option value="6">6</option>
            <option value="7">7</option>
            <option value="8">8</option>
            <option value="9">9</option>
            <option value="10">10</option>
        </select><br/>
        Type: BodyBuilding<input type="radio" name="type" value="BodyBuilding"> Weight Loss<input type="radio" name="type" value="Weight Loss"><br/>
        Description: <input type="text" name="descr"><br/>
    <input type="submit">

insert.php that webpage sends form data to
<? php

    define('DB_NAME', 'diet');
    define('DB_USER', 'root');
    define('DB_PASSWORD', 'root');
    define('DB_HOST', 'localhost');

        $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

    if (! $link) {
        die('Could not connect: ' .  mysql_error());
    }
        $db_selected = mysql_select_db(DB_NAME, $link);

    if (! $db_selected) {
        die('Could not use ' .  DB_NAME . ': ' .  mysql_error());
    }
        /*$sql="INSERT INTO diet (name, rating, type, descr)
        VALUES('$_POST[name]','$_POST[rating]','$_POST[type],'$_POST[descr]')";*/

        $sql = "INSERT INTO diet ('name', 'rating', 'type', 'descr') VALUES ('$name','$rating','$type','$descr', NOW())";

    if (! $link) 
    {
        die('Could not connect: ' .  mysql_error());
    }
    echo 'Connected successfully';
? >

A:

Here is a PDO example.  I don't know what Now() represents for you (probably an insert date) but I think you can figure out how to add it.     
$dbhost = 'YOUR_SERVER';
$dbuser = 'YOUR_USERNAME';
$dbpass = 'YOUR_PASSWORD';
$dbname = 'YOUR_DATABASE_NAME';

try {
  $conn = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
}
catch(PDOException $e) {
    echo $e->getMessage();
}

$name = $_POST[name];
$rating = $_POST[rating];
$type = $_POST[type];
$desc = $_POST[descr];

if ($conn)
    {
        $query = "INSERT INTO diet (name, rating, type, descr) VALUES(:name, :rating, :type, :desc)";
        $insert = $conn->prepare($query);
        $insert->bindValue(":name",$name); 
        $insert->bindValue(":rating",$rating); 
        $insert->bindValue(":type",$type); 
        $insert->bindValue(":desc",$desc); 

        $insert->execute();         
    }
    /* Free connection resources. */ 
    $conn = null;

Documentation: http://us2.php.net/pdo.prepared-statements
Why you Should be using PHP’s PDO for Database Access

