e_Katerina
Новичок
на форме есть поля и раскрывающиеся списки, проблема в том, что в массив записывается только значение первого раскрывающегося списка остальные поля добавляются в массив
<form method="POST" action='reg.php'>
<table>
<tr>
<td>Наименование картриджа</td>
<td><input type="text" name="name_cartridge" value="HP" required /></td>
</tr>
<tr>
<td>Дата</td>
<td><input type="date" name="data" value="" /></td>
</tr>
<tr>
<td>Состояние</td>
<td>
<?php
include_once ("conect.php");
include_once ("select.php");
?>
</td>
</tr>
<tr>
<td>Отдел</td>
<td><?php
include_once ("conect.php");
include_once ("department.php");
?></td>
</tr>
<tr>
<td>Тип</td>
<td>
<?php
include_once ("conect.php");
include_once ("type.php");
?>
</td>
</tr>
<tr>
<td>Количество</td>
<td><input type="number" size="3" name="numer" min="1" max="10"></td>
</tr>
<tr>
<td><input type='submit' value='Сохранить'</td>
<td><button type="button" onClick="history.back();">Отменить</button></td>
</tr>
</table>
</form>
Формирование раскрывающегося списка:
"select.php"
<form method="post" name='condition' action='reg.php'>
<?php
function names()
{
$query="SELECT `condition`
FROM `condition`";
$query_res=mysql_query($query);
$names = array();
while($row = mysql_fetch_assoc($query_res))
{
$names[] = $row;
}
return $names;
}
$names = names();
echo "<select name='condition'>";
echo "<option value selected=''> </option>";
foreach($names as $item)
{
echo "<option value=' ".$item['condition']." '> ".$item['condition']."</option>";
}
echo "</select>";
echo $_post ['condition'];
?>
</form>
Обработка полученных результатов с формы:
<form method="POST" action="stat.php" >
<?php
$name_cartridge=$_POST['name_cartridge'];
$date=$_POST['data'];
$condition=$_POST ['condition'];
$department=$_POST['department'];
$type=$_POST['type'];
$numer=$_POST['numer'];
var_dump($_POST);
include ('conect.php');
$qery="INSERT INTO `stat`.`log` (`name_cartridge` ,`date` ,`condition` ,`department`, `type`,`count`) VALUES ( '$name_cartridge', '$date', '$condition', '$department', '$type', '$numer')";
$result=mysql_query ($qery) or die( mysql_error());
print_r("INSERT INTO `stat`.`log` (`name_cartridge` ,`date` ,`condition` ,`department`, `type`,`count`)
VALUES ( '$name_cartridge', '$date', '$condition', '$department', '$type', '$numer')");
if ($result)
{
echo '<center><p><b>Ошибка при добавлении данных!</b></p></center>';}
else
{echo '<center><p><b>Данные добавлены </b></p></center>';}
?>
<input type='submit' value='Продолжить'>
</form>
Массив выводит :
array(4) { ["name_cartridge"]=> string(2) "HP" ["data"]=> string(10) "2016-05-09" ["condition"]=> string(26) " заправленный " ["numer"]=> string(1) "7" } INSERT INTO `stat`.`log` (`name_cartridge` ,`date` ,`condition` ,`department`, `type`,`count`) VALUES ( 'HP', '2016-05-09', ' заправленный', '', '', '7')
<form method="POST" action='reg.php'>
<table>
<tr>
<td>Наименование картриджа</td>
<td><input type="text" name="name_cartridge" value="HP" required /></td>
</tr>
<tr>
<td>Дата</td>
<td><input type="date" name="data" value="" /></td>
</tr>
<tr>
<td>Состояние</td>
<td>
<?php
include_once ("conect.php");
include_once ("select.php");
?>
</td>
</tr>
<tr>
<td>Отдел</td>
<td><?php
include_once ("conect.php");
include_once ("department.php");
?></td>
</tr>
<tr>
<td>Тип</td>
<td>
<?php
include_once ("conect.php");
include_once ("type.php");
?>
</td>
</tr>
<tr>
<td>Количество</td>
<td><input type="number" size="3" name="numer" min="1" max="10"></td>
</tr>
<tr>
<td><input type='submit' value='Сохранить'</td>
<td><button type="button" onClick="history.back();">Отменить</button></td>
</tr>
</table>
</form>
Формирование раскрывающегося списка:
"select.php"
<form method="post" name='condition' action='reg.php'>
<?php
function names()
{
$query="SELECT `condition`
FROM `condition`";
$query_res=mysql_query($query);
$names = array();
while($row = mysql_fetch_assoc($query_res))
{
$names[] = $row;
}
return $names;
}
$names = names();
echo "<select name='condition'>";
echo "<option value selected=''> </option>";
foreach($names as $item)
{
echo "<option value=' ".$item['condition']." '> ".$item['condition']."</option>";
}
echo "</select>";
echo $_post ['condition'];
?>
</form>
Обработка полученных результатов с формы:
<form method="POST" action="stat.php" >
<?php
$name_cartridge=$_POST['name_cartridge'];
$date=$_POST['data'];
$condition=$_POST ['condition'];
$department=$_POST['department'];
$type=$_POST['type'];
$numer=$_POST['numer'];
var_dump($_POST);
include ('conect.php');
$qery="INSERT INTO `stat`.`log` (`name_cartridge` ,`date` ,`condition` ,`department`, `type`,`count`) VALUES ( '$name_cartridge', '$date', '$condition', '$department', '$type', '$numer')";
$result=mysql_query ($qery) or die( mysql_error());
print_r("INSERT INTO `stat`.`log` (`name_cartridge` ,`date` ,`condition` ,`department`, `type`,`count`)
VALUES ( '$name_cartridge', '$date', '$condition', '$department', '$type', '$numer')");
if ($result)
{
echo '<center><p><b>Ошибка при добавлении данных!</b></p></center>';}
else
{echo '<center><p><b>Данные добавлены </b></p></center>';}
?>
<input type='submit' value='Продолжить'>
</form>
Массив выводит :
array(4) { ["name_cartridge"]=> string(2) "HP" ["data"]=> string(10) "2016-05-09" ["condition"]=> string(26) " заправленный " ["numer"]=> string(1) "7" } INSERT INTO `stat`.`log` (`name_cartridge` ,`date` ,`condition` ,`department`, `type`,`count`) VALUES ( 'HP', '2016-05-09', ' заправленный', '', '', '7')