looping sql query for form.
Posted: Tue Dec 11, 2007 5:00 pm
Hi i am trying o add a form that creates links on a site. the user can create up to 3 at a time, what i need is so they can fill out 1-3 links and when the form is proccessed it it adds them all to the database here is my code so far..
i get an error saying "inputs" is an undefined variable..
EDIT:
i am not doing the sql just yet, once the echo works ill add the sql
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
echo <<<FRM
<form id="form1" name="form1" method="get" action="index.php">
<table>
<tr>
<td><label>
<input type="text" name="text_1" id="text_1" />
</label></td>
<td><label>
<input type="text" name="link_1" id="link_1" />
</label></td>
<td><label>
<input type="text" name="location_1" id="location_1" />
</label></td>
</tr>
<tr>
<td><label>
<input type="text" name="text_2" id="text_2" />
</label></td>
<td><label>
<input type="text" name="link_2" id="link_2" />
</label></td>
<td><label>
<input type="text" name="location_2" id="location_2" />
</label></td>
</tr>
<tr>
<td><label>
<input type="text" name="text_3" id="text_3" />
</label></td>
<td><label>
<input type="text" name="link_3" id="link_3" />
</label></td>
<td><label>
<input type="text" name="location_3" id="location_3" />
</label></td>
</tr>
</table>
<label>
<input type="submit" name="Submit" id="Submit" value="Submit" />
</label>
</p>
</form>
FRM;
if(isset($_GET['Submit'])){
for($i = 0; $i >= 3; $i++){
$inputs[$i]['text'] = (isset($_GET['text_'.$i])) ? $_GET['text_'.$i] : '';
$inputs[$i]['link'] = (isset($_GET['link_'.$i])) ? $_GET['link_'.$i] : '';
$inputs[$i]['location'] = (isset($_GET['location_'.$i])) ? $_GET['location_'.$i] : '';
}
foreach($inputs as $row){
echo 'New link '.$row['text'].' '.$row['link'].' '.$row['location'].'<br />';
}
}
?>i get an error saying "inputs" is an undefined variable..
EDIT:
i am not doing the sql just yet, once the echo works ill add the sql