Captcha for php/MySQL

Help! I am in desperate need of some advice on how to create a catpcha for an insert form that I am currently using. I have managed to create both a CAPTCHA and an INSERT form separately both of which work fine. Problem I have is that I cannot work out how to join the two together.

The CAPTCHA displays either the success or failure notice using an IF statement, the problem i have is that I am not sure how I can change the success IF statement to and INSERT command.

it strange how you wrote this.. im not an expert.. but maybe what i know is enough to help you there.

<?php
if($word_ok!==false)
?>

first of all !== is unknown to me... ( sorry i checked and it is available as a PHP operator... so !== isnt wrong)
it is either != for 'is different from' or == for 'is equal to'
Now if you use booleans, you dont even need to use them..
you can simply use

<?php
$isValid;
//then use a function to validate your $word_ok
// a function that returns false in case of errors, true ( or anything else) if no error encountered.
$isValid = validate_my_string ($word_ok);
//now if $isValid == false
if (!$isValid)
{
echo "$word_ok is invalid";
}
// else means $isValid is anything else but false..
// so if needed you function can return something else than true ( like an array, an object, a value or a variable)
else
{
echo "$Thanks you, $word_ok has been validated";
}
//you can also have your function to create an array and return it at the end..
//during the validation if necessary add entries to it, i usually name $errors and use $errors ['where is happens'] = "err_msg";
function validate ()
{
//first create an empty array
$errors = array();
// do your validation and if there is an error add it to $errors
if (empty($_POST['username']) || $_POST['username'] == "") $errors['username'] == "blank username";
if (empty($_POST['password']) || $_POST['password'] == "") $errors['password'] == "blank password";
//once it is done just return $errors array
return $errors;
}
//then you can have a page looking like
//validate and get the array
$validation = validate ();
if (empty ($validation)) echo "the error array is empty... which means you pass thru my validation, congrats, lol";
//else means there has been an error somewhere
else
{
echo "the following errors where found<br />";
echo "<ul>";
// foreach will do this for every entries in our error array. I'm putting it in unordered list, 100%optional
foreach ($validation as $whereIsError => $error_msg)
{
echo "<li>$whereIsError - $error_msg</li>";
}
echo "</ul>";
}