Vineet Basantani Vineet Basantani - 6 months ago 16
PHP Question

Only the first value is added to the DB and not the rest

The value Category is added to the database with the insert query. No other value is added to the table.
Here's my PHP:

<?php
$date="";
$category="";
$item="";
$vendor="";
$issue_morn=0.0;
$issue_noon=0.0;
$issue_night=0.0;
$wastage=0.0;
$receipt=0.0;
$open_stock=0.0;
$close_stock=0.0;
$monthly_open_stock=0.0;
$monthly_close_stock=0.0;
$unit="";
$sth = $conn->prepare('INSERT INTO annapoorna.inventory
(`date`, category, item, vendor, unit, open_stock, close_stock, recipt,
issue_morn, issue_noon, issue_night, wastage, monthly_open_stock, monthly_close_stock)
VALUES (:date, :category, :item, :vendor, :unit, :open_stock, :close_stock,:recipt, :issue_morn, :issue_noon,
:issue_night, :wastage, :monthly_open_stock, :monthly_close_stock)');
if(!empty($_POST['datepicker']))
{
$date=$_POST['datepicker'];
}
if(!empty($_POST['category']))
{
$category=$_POST['category'];
}
if(!empty($_POST['item']))
{
$item=$_POST['item'];
}
if(!empty($_POST['vendor']))
{
$vendor=$_POST['vendor'];
}

$sth->execute(array(':date'=>$date, ':category'=>$category, ':item'=>$item, ':vendor'=>$vendor,
':unit'=>$unit, ':open_stock'=>$open_stock,':close_stock'=>$close_stock,':recipt'=>$receipt,
':issue_morn'=>$issue_morn, ':issue_noon'=>$issue_noon, ':issue_night'=>$issue_noon,
':wastage'=>$wastage, ':monthly_open_stock'=>$monthly_open_stock,
':monthly_close_stock'=>$monthly_close_stock));


?>


Here's my HTML (and some PHP in it to fetch data from DB for drop down):

<form name="form" method="POST" style="display:inline;">
<select name="category" id="category" value="category" class="form-control ddplaceholder" style="width:220px;font-size:18px;font-family:Roboto;" onchange="document.form.submit();">
<option value="" disabled selected>Select Category</option>
<?php
$sth = $conn->prepare('Select name From category');
$sth->execute();
$data = $sth->fetchAll();
foreach ($data as $row ){
if($row['name']!="")
echo ' <option id=\"CategoryName\" nameCategoryNameVendorName\" value="' .$row['name']. '">'.$row['name'].'</option>';
}
?>
</select>

<select name="item_name_update" value="item_name_update" class="form-control ddplaceholder" style="width:220px; padding-left:40px;font-size:18px;font-family:Roboto;" onchange="document.form.submit();">
<option value="" disabled selected>Select Item</option>
<?php
$sth = $conn->prepare('Select item_name From item');
$sth->execute();
$data = $sth->fetchAll();
foreach ($data as $row ){
if($row['item_name']!="")
echo ' <option id=\"ItemName\" name=\"ItemName\" value="' .$row['item_name']. '">'.$row['item_name'].'</option>';
}
?> </select>
<select name="vendor_name_update" value="vendor_name_update" class="form-control ddplaceholder" style="width:220px; padding-left:40px;font-size:18px;font-family:Roboto;" onchange="document.form.submit();">
<option value="" disabled selected>Select Vendor</option>

<?php
$sth = $conn->prepare('Select name From vendor');
$sth->execute();
$data = $sth->fetchAll();
foreach ($data as $row ){
if($row['name']!="")
echo ' <option id=\"VendorName\" name=\"VendorName\" value="' .$row['name']. '">'.$row['name'].'</option>';
}
?>
</select>
</br>
Monthly Op Stock<input type="text" placeholder="Monthly op Stock"</>
Current Op Stock<input type="text" placeholder="Current op Stock"</>

<p>

<input type="button" onclick="window.location.href='EditItemList.php'" value="Edit Item List"/>
<input type="button" onclick="window.location.href='EditVendorList.php'" value="Edit Vendor List"/>
</p>
<hr>

<table class="inventory" style="float:left">
<tr>
<td>Unit</td>
<td>
<input type="text" placeholder="Unit"/>
</td>
</tr>
<tr>
<td>Opening Stock</td>
<td>
<input type="text" placeholder="Opening stock"/>
</td>
</tr>
<tr>
<td>Closing Stock</td>
<td>
<input type="text" placeholder="Closing ctock"/>
</td>
</tr>
<tr>
<td>Receipt</td>
<td>
<input type="text" placeholder="Receipt"/>
</td>
</tr>
</table>



<table class="inventory2">
<tr>
<td>Issue Morning</td>
<td>
<input type="text" placeholder="Issue Morning"/>
</td>
</tr>
<tr>
<td>Issue Noon</td>
<td>
<input type="text" placeholder="Issue Noon"/>
</td>
</tr>
<tr>
<td>Issue Night</td>
<td>
<input type="text" placeholder="Issue Night"/>
</td>
</tr>
<tr>
<td>Wastage</td>
<td>
<input type="text" placeholder="Wastage"/>
</td>
</tr>
</table>
</form>


Why is it not working?

Answer

You didn't specify a name attribute.

Without the name attribute, it's impossible for the browser to send anything. So here's example:

<input type="text" name="open_stock" placeholder="Opening stock"/>