madanthrax
IS-IT--Management
Hi all,
I have not used arrays before and am having a problem working out how to insert multiple rows into MySQL DB.
This is my test form:
From info I have found in this forum I have got this far with the insert-answers.php :
The above inserts 5 rows into the Answers table with of course only the Answer field populated, the rest NULL. I need the aValue to be inserted as well.
I have spent the last few hours researching Multidimensional Arrays and learnt a lot, but have been unable to get anything actually working along the lines I want.
Am I barking up the wrong tree? Is there a simpler way than this to add the other values to the rows?
Any help will be greatfully appreciated.
Anthony
I have not used arrays before and am having a problem working out how to insert multiple rows into MySQL DB.
This is my test form:
Code:
<form action="insert-answers.php" method="post">
<input type="text" name="answer[1]"> <input type="text" name="aValue[1]"><br>
<input type="text" name="answer[2]"> <input type="text" name="aValue[2]"><br>
<input type="text" name="answer[3]"> <input type="text" name="aValue[3]"><br>
<input type="text" name="answer[4]"> <input type="text" name="aValue[4]"><br>
<input type="text" name="answer[5]"> <input type="text" name="aValue[5]"><br>
<input name="submit" type="submit" />
</form>
Code:
<?php virtual ('/include/PHPweb.php'); ?>
<?php
mysql_select_db($database_PHPweb) or die( "Unable to find database");
$arrayname = $_POST['answer'];
foreach($arrayname as $key=>$value)
{
echo $key.": ".$value;
$sql = "INSERT INTO Answers (Answer) VALUES
('$value')";
mysql_query($sql);
}
mysql_close();
?>
I have spent the last few hours researching Multidimensional Arrays and learnt a lot, but have been unable to get anything actually working along the lines I want.
Am I barking up the wrong tree? Is there a simpler way than this to add the other values to the rows?
Any help will be greatfully appreciated.
Anthony
"Nothing is impossible until proven otherwise"