I'm wondering if this necessarily calls for an array and/or loop, and what solutions might solve this issue. As a learning exercise, I'm trying to insert two of five variable into two successive rows in MY SQL. I set up a simple table with one column in SQL called test. My first "INSERT INTO table VALUES ( '$Word1' )"; statement successfully inserts the value into the first row. Similar/almost identical subsequent code with $Word2 does not add the value to SQL. I'm imagining I have to somehow advance to the next row, but I'm completely lost as to how to accomplish this. I scoured the forums, my PHP book, and w3Schools in vain.
/*retrieve user input from separate HTML input form */
/* and initializes variables */
$Word1 = $_POST["Word1"];
$Word2 = $_POST["Word2"];
$Word3 = $_POST["Word3"];
$Word4 = $_POST["Word4"];
$Word5 = $_POST["Word5"];
//select db
mysql_select_db("madlibs", $con);
//insert user input for word 1 into SQL
$sql = "INSERT INTO test (MadWords)
VALUES
('$Word1')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
//word 2
/* ***THIS CODE AND MANY VARIATIONS OF IT FAIL TO ENTER $WORD2 INTO SQL*/
"INSERT INTO test (MadWords)
VALUES
('$Word2')";
if (!mysql_query($sql2,$con))
/*I've cut this if statement in other debugging runs with the same result*/
{
die('Error: ' . mysql_error());
}
echo "1 record added";