Hi
I have a PHP generated page which gives the user the option of adding up to 10 rows at once. It goes to a page which inserts the data into the database. But it's adding 10 rows into the database even if only 2 or 3 are are filled out.
How do I tell it not to input rows that have no legitimate variables (user hasn't filled out)?
Thank you.
Richard
First page...
<table border='0' align='left'>";
for ($i = 1; $i <= $stores; $i++) {
echo "<tr bgcolor='#FFFFCC'>
<th>Zone</th><th>Store Name</th><th>Store #</th><th>Store Address</th><th>City</th><th>State</th><th> </th>
<tr bgcolor='#99CCFF'>
<form action='power_add2.php' method='post'>
<td align='center'><input type='text' name='zone[]' size='7'></td>
<td align='center'><input type='text' name='store_name[]' size='15'></td>
<td align='center'><input type='text' name='store_no[]' size='7'></td>
<td align='center'><textarea name='store_add[]' size='12'></textarea></td>
<td align='center'><input type='text' name='city[]' size='15'></td>
<td align='center'><input type='text' name='state[]' size='12'></td></tr>";
}
?>
<tr><td><input type='Submit' value='http://www.phpbuilder.com/board/archive/index.php/Add Stores'></td></tr>
</form>
</td></tr></table>
.......................................
Second page...
include ("connection stuff");
While(List($key,)=each($store_name)) {
$sql = "insert into stores (zone, store_name, store_no, store_add, city, state) values ('$zone[$key]', '$store_name[$key]', '$store_no[$key]', '$store_add[$key]', '$city[$key]', '$state[$key]')";
$sql_result = mysql_query($sql);
echo "$zone[$key] $store_name[$key] $store_no[$key] $store_add[$key] $city[$key] $state[$key]<br>";
}
MYSQL_CLOSE();
I have a PHP generated page which gives the user the option of adding up to 10 rows at once. It goes to a page which inserts the data into the database. But it's adding 10 rows into the database even if only 2 or 3 are are filled out.
How do I tell it not to input rows that have no legitimate variables (user hasn't filled out)?
Thank you.
Richard
First page...
<table border='0' align='left'>";
for ($i = 1; $i <= $stores; $i++) {
echo "<tr bgcolor='#FFFFCC'>
<th>Zone</th><th>Store Name</th><th>Store #</th><th>Store Address</th><th>City</th><th>State</th><th> </th>
<tr bgcolor='#99CCFF'>
<form action='power_add2.php' method='post'>
<td align='center'><input type='text' name='zone[]' size='7'></td>
<td align='center'><input type='text' name='store_name[]' size='15'></td>
<td align='center'><input type='text' name='store_no[]' size='7'></td>
<td align='center'><textarea name='store_add[]' size='12'></textarea></td>
<td align='center'><input type='text' name='city[]' size='15'></td>
<td align='center'><input type='text' name='state[]' size='12'></td></tr>";
}
?>
<tr><td><input type='Submit' value='http://www.phpbuilder.com/board/archive/index.php/Add Stores'></td></tr>
</form>
</td></tr></table>
.......................................
Second page...
include ("connection stuff");
While(List($key,)=each($store_name)) {
$sql = "insert into stores (zone, store_name, store_no, store_add, city, state) values ('$zone[$key]', '$store_name[$key]', '$store_no[$key]', '$store_add[$key]', '$city[$key]', '$state[$key]')";
$sql_result = mysql_query($sql);
echo "$zone[$key] $store_name[$key] $store_no[$key] $store_add[$key] $city[$key] $state[$key]<br>";
}
MYSQL_CLOSE();