Hi, I am posting in PHP forum as I believe it is a PHP problem. I have seen examples of inserting multiple rows and it seems there are generally 2 options...to use multiple insert commands or to 'concatonate' the query. I have tried these options but with no success.
So I have a form which I will provide snippets of but generally it is like this...one project field, many (up to ten) task fields. For the task fields, I want them to go into their own row. I don't think an array is right - I am already using arrays to store checkbox data, but maybe I'm wrong on that one, I thought multiple rows is more appropriate. So the code...
project-new.php is the form
<form action="process.php" method="post">
<ul>
<li><label>Project Title:</label>
// the form object here is used to store data if incorrect values are entered
// and for error messages
<input type="text" name="title" value="<?php echo $form->value("title"); ?>" /><?php echo $form->error("title"); ?></li>
<li><label>Task:</label>
<input type="text" name="task" value="<?php echo $form->value("task"); ?>" /><?php echo $form->error("task"); ?></li>
<li><label>Task:</label>
<input type="text" name="task" value="<?php echo $form->value("task"); ?>" /><?php echo $form->error("task"); ?></li>
</ul>
<input type="hidden" name="subproject" value="1" />
<input type="submit" value="Submit Project" />
</form>
The two task fields are called the same thing as they need to get posted in process.php (is this where the error is?)
This form goes to process.php
if(isset($_POST['subproject'])) {
$this->procLogin();
}
function procProject() {
global $session, $form;
$retval = $session->newProject($_POST['title'], $_POST['task']);
}
// further code which deals with the retvals...
This then goes to session.php for validation which I have left out for this example as I don't think it is where the problem is, but assuming the user has passed the validation checkes, their details go to database.php for the INSERT command
function addNewProject($projecttitle, $task) {
$q = INSERT INTO projects VALUES ('$projecttitle', '$task');
return mysql_query($q, $this->connection);
}
The return vaules go back to process.php where it determines a success/failed insert attempt and then referrs the user to the appropriate location.
So i have tried to only include code which I see as relevent and only provided a snippet. If any more is required I can post more.
As far as I can tell, it comes down to how the values are posted out. I tried a 'concatonating' the INSERT but it would insert the data into the wrong fields, fail validation and fail overall.
I tried duplicate inserts, ie $q = INSERT... and $q1 = INSERT... but that just inserted the data in task 2, not both of them.
Any help is greatly appreciated!!