Multiple if else and insert statements

http://saulcross.com/spellings/spelling_program.htm
The Spelling program:
Currently I have just been programming a spellings helper. The proposed functionality is as follows:

  1. The user is presented with a set of wav or mp3 files that they are able to play.
  2. The user then enters into a form how they think the spelling should be spelt and then if the spelling that the user tries is the same as the mp3 or wav file name then the program returns true or false.
  3. The program should work with a set of mp3’s or wav’s that are found in a folder. The user shouldn’t have to manually add the spellings to initialise the program.
  4. When the user gets a spelling correct then, there specific user id should be incremented with a value.
  5. Finally the spelling files should be reordered so that the user is only presented with the spellings that they get wrong.

Currently I have programmed with php, html and JavaScript media player up to statement 2. I have made the database for statements 3 and 4 but I 'm using an if else statement for:

If the spelling is correct then insert into the database the spelling and the user.

if ( $spelling_one == $remove[5]){
echo “Well done! you have spelt word 1 correctly”;
mysql_query(“INSERT INTO user (name, password, word_right_score) VALUES (‘saul’, ‘123’, ‘$remove[5]’)”);
echo “true”;

The problem that I keep encountering is: If all the other if statements for the words are executed then when you update for getting one spelling right you also update for all the other spellings being incorrect. Thus the addition that is required for statement 3 and 4 isn’t valid.

Can you help?

I have looked into elseif and switch statements but neither of those statements fit any better than what I have? Any help would be gratefully received, I plan to host the program on a decent server and am offering percentages on profits if any gained.

This is the functioning part of the program.

The database doesn’t function at current as I haven’t switch on the sql part of the hosting.

My details : [email protected]
uk 0044 079-8005-1973

Currently the program is in two parts.
Part A is where the user inputs the spelling, part B gives feedback in regards to a right answer and send to MySQL…
Part B

<?php // a trick to remove all errors perhaps not a good idea. error_reporting (E_ALL ^ E_NOTICE);

//$con = mysql_connect(“localhost”,“root”,"");
//if (!$con)
//{
//die('Could not connect: ’ . mysql_error());
//}

//mysql_select_db(“spelling”, $con);

// open the array and initialise values.
$documents=array();
$remove=array();
$i = 0;
$term = 0;
$handle=opendir(".");
$counter_one = 0;
$add_one = 0;

// read the documents into an array.
while (($file = readdir($handle))!==false) {
//echo “$file
“;
$i++;
$documents[$i]=”$file”;

}

closedir($handle);

// check that the array functions.
$i = 0;
while ($i <= 9) {
$i++;
;

$fileName = $documents[$i];
$name = substr($fileName, 0, strrpos($fileName, ‘.’));
//echo $name;
//echo “
”;
$remove[$i]="$name";

//echo $documents[$i];
// echo “$documents[$i]”;
}

$spelling_one = $_POST[‘spelling_one’];
$spelling_two = $_POST[‘spelling_two’];
$spelling_three = $_POST[‘spelling_three’];
$spelling_four = $_POST[‘spelling_four’];
$spelling_five = $_POST[‘spelling_five’];

if ( $spelling_one == $remove[5]){
echo “Well done! you have spelt word 1 correctly”;
//mysql_query(“INSERT INTO user (name, password, word_right_score) VALUES (‘Peter’, ‘123’, ‘$remove[5]’)”);
} else {
echo “Wrong! you have misspelt word 1”;
//mysql_query(“INSERT INTO user (name, password, word_wrong_score) VALUES (‘Peter’, ‘123’, ‘$remove[5]’)”);
}

echo “
”;
if ( $spelling_two == $remove[6]){
echo “Well done! you have spelt word 2 correctly”;
// mysql_query(“INSERT INTO user (name, password, word_right_score) VALUES (‘Peter’, ‘123’, ‘$remove[6]’)”);
} else {
echo “Wrong! you have misspelt word 2”;
//mysql_query(“INSERT INTO user (name, password, word_wrong_score) VALUES (‘Peter’, ‘123’, ‘$remove[6]’)”);
}

echo “
”;
if ( $spelling_three == $remove[7]){
echo “Well done! you have spelt word 3 correctly”;
} else {
echo “Wrong! you have misspelt word 3”;
}

echo “
”;
if ( $spelling_four == $remove[8]){
echo “Well done! you have spelt word 4 correctly”;
} else {
echo “Wrong! you have misspelt word 4”;
}

echo “
”;
if ( $spelling_five == $remove[4]){
echo “Well done! you have spelt word 5 correctly”;
} else {
echo “Wrong! you have misspelt word 5”;
}
echo “
”;
echo “back”;

?>

Part A:

<?php // open the array and initialise values. $documents=array(); $remove=array(); $i = 0; $term = 0; $handle=opendir("."); $counter_one = 0; $add_one = 0; // read the documents into an array. while (($file = readdir($handle))!==false) { //echo "$file
"; $i++; $documents[$i]="$file"; } closedir($handle); // check that the array functions. $i = 0; while ($i <= 9) { $i++; ; $fileName = $documents[$i]; $name = substr($fileName, 0, strrpos($fileName, '.')); //echo $name; //echo "
"; $remove[$i]="$name"; //echo $documents[$i]; // echo "$documents[$i]"; } ?>

Spelling program mk3

Part B:

Sponsor our Newsletter | Privacy Policy | Terms of Service