Help Inserting multiple Values into a Database
Posted: Thu May 28, 2009 10:52 am
Hi
I have a web page that has 4 input fields with the option of adding 3 more, so the number of information to be entered can vary. I wrote a function that looks after the insert, but instead of inserting the the contents of the variable it inputs the name of the variable. For example $question = "how are you"; instead of inserting "how are you" it inserts $question.
my code is as follows,
I am open to any suggestions and Thanks for any help in advance I appreciate it.
Dave
I have a web page that has 4 input fields with the option of adding 3 more, so the number of information to be entered can vary. I wrote a function that looks after the insert, but instead of inserting the the contents of the variable it inputs the name of the variable. For example $question = "how are you"; instead of inserting "how are you" it inserts $question.
my code is as follows,
Code: Select all
<?php
function insertQuestions($ques1, $ques2, $ques3, $ques4, $ques5, $ques6, $ques7, $questionSet)
{
$query= "INSERT INTO questions (question, questionSet, questionType) VALUES";
$loop = 8;
if (strlen($ques7)<1)
$loop = 7;
if (strlen($ques6)<1)
$loop = 6;
if (strlen($ques5)<1)
$loop = 5;
if (strlen($ques4)<1)
$loop = 4;
if (strlen($ques3)<1)
$loop = 3;
for($row = 1; $row < $loop; $row++ )
{
$question = '$ques';
$question .= "$row";
//Debug
//print $question;
if($row != $loop-1)
{
$query.= "('$question', '$questionSet', ''),";
}
else
$query.= "('$question', '$questionSet', '')";
}
//Debug
print $query;
//insertMySQL($query);
}
?>
Dave