<SCRIPT language="javascript">
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
if(rowCount < 10){ // limit the user from creating fields more than your limits
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
for(var i=0; i <colCount; i++) {
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[0].cells[i].innerHTML;
}
}else{
alert("Maximum Number of Books is 10");
}
}
function deleteRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for(var i=0; i<rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox && true == chkbox.checked) {
if(rowCount <= 1) { // limit the user from removing all the fields
alert("Cannot Remove all the Books.");
break;
}
table.deleteRow(i);
rowCount--;
i--;
}
}
}
</SCRIPT>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div style="border:auto solid 1px; font-size:15px; background-color:red; width:100%;">
<form action="" enctype="multipart/form-data" id="pdf_form" method="post" name="pdf_form">
<table id="dataTable" class="form" border="1">
<tbody>
<p>
<td >
<input type="checkbox" name="chk[]" checked="checked" />
</td>
<td>
<label for="title">Title of PDF</label>
<input type="text" id="title" name="title[]">
<td>
<label for="pdffile">PDF supported. 2MB Maximum)</label>
<input type="file" id="pdffile" name="pdffile[]">
</td>
<td>
<label for="category">Category</label>
<select id="category" name="category[]">
<option>Science</option>
<option>Technology</option>
<option>Biblical</option>
<option>Business</option>
<option>Medical</option>
<option>Engineering</option>
<option>World</option>
</select>
</td>
</p>
</tr>
</tbody>
</table>
<p>
<input type="button" value="Add PDF" onClick="addRow('dataTable')" />
<input id="button" name="submit" type="submit" value="Save PDF(s)" />
<p>(All actions apply only to entries with check marked check boxes only.)</p>
</p>
</form>
</div>
<!-- //PHP for Upload -->
<?php
$con = mysqli_connect("localhost", "root","", "pdf") or die ("Error".mysqli_error($con));
if($_SERVER["REQUEST_METHOD"] == "POST") {
if(isset($_POST['submit']) && $_FILES['pdffile']['size'] > 0)
{
$fileName = $_FILES['pdffile']['name'];
$tmpName = $_FILES['pdffile']['tmp_name'];
$fileSize = $_FILES['pdffile']['size'];
$fileType = $_FILES['pdffile']['type'];
$item_title = $_POST['title'];
$item_category = $_POST['category'];
for($count = 0; $count<count($item_title); $count++){
$title = mysqli_real_escape_string($con,$item_title[$count]);
$category = mysqli_real_escape_string($con,$item_category[$count]);
$pdfname = mysqli_real_escape_string($con, $fileName[$count]); //document name
$tmpname = mysqli_real_escape_string($con, $tmpName[$count]);
$folder = "uploads/";
if(!get_magic_quotes_gpc())
{
$pdfname = addslashes($pdfname);
}
$doc_path = move_uploaded_file($tmpname, $folder.$pdfname);
$sql = "INSERT INTO zipcode (country, city, zipCode) VALUES('$title', '$category', '$pdfname')";
if ($con->query($sql) === TRUE) {
echo "<div style="border:auto solid 1px; font-size:15px; color:green; background-color:auto; width:100%;"> PDF with Title $title Added Successfully. </div>";
}
else {
echo "Error: " . $sql . "<br>" . $con->error;
};
}
}
}
?>
</body>
</html>
8
solved How can i Store HTML arrays into Mysql using PHP in each columns