Hey guys i am using this script to make dynamic webform (add new input if needed).
<form method="post" action="">
<table class="dd" width="100%" id="data">
<tr>
<td>Vin</td>
<td width="99%"><input name="vin1" id="vin1" type="text" /></td>
</tr>
</table>
<input name="sub" type="submit" value="Submit values"/>
<input type="button" id="addnew" name="addnew" value="Add new item" />
<input type="hidden" id="items" name="items" value="1" />
</form>
<?php var_dump ($_POST); ?>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type='text/javascript'>
//<![CDATA[
$(document).ready(function() {
var currentItem = 1;
$('#addnew').click(function(){
currentItem++;
$('#items').val(currentItem);
var strToAdd = '<tr><td>Vin</td><td width="17%"><input name="vin'+currentItem+'" id="vin'+currentItem+'" type="text" /></td></tr>';
$('#data').append(strToAdd);
});
});
//]]>
</script>
It works well and also name each input with number so in my case its : vin1, vin2, vin3... Problem is i am not sure how to tell PHP to process this data. Because i am using something like:
public function fetchByVinEvidence() {
$success = false;
try{
$con = new PDO( DB_HOST, DB_USER, DB_PASS );
$con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sql = "SELECT * FROM evidence_calculations WHERE vin = :vin LIMIT 5";
$stmt = $con->prepare( $sql );
$stmt->bindValue( "vin", $this->vin, PDO::PARAM_STR );
$stmt->execute();
while ($row = $stmt->fetch()){
echo "<tr>";
echo "<td>#4</td>";
echo "<td>".$row['street']."</td>";
echo "<td>".$row['city']."</td>";
echo "<td>".$row['claim_number']."</td>";
echo "<td>".$row['country']."</td>";
echo "<td><a href =\"javascript:void(0)\" onclick = \"document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'\">detail</a></td>";
echo "</tr>";
}
}catch(PDOExeption $e){
echo $e->getMessage();
echo $con->errorInfo();
}
return $success;
}
For a single input but how can i edit it for multiple input, i am new in PHP OOP so i am really not sure how to make proper cycle, how to limit everything to not let user to send milion things to database at once and so on. Can you guys help me a bit to edit my PHP script to be able to work with data from multiple form?
Thanks!