mysql not insert data from form
Posted: 15 Jan 2017, 14:09
i have two php files:
the index.php ---
and the input.php file
but my mysql insert don't work.please help me to find the error
the index.php ---
Code: Select all
<?php
$id ="3";
if(!empty($_POST["save"])) {
$conn = mysql_connect("localhost","website_rent","password");
mysql_select_db("website_rent",$conn);
$itemCount = count($_POST["item_name"]);
$itemValues=0;
$query = "INSERT INTO preturi (data_i,data_t,zi,noapte,id_proprietate) VALUES ";
$queryValue = "";
for($i=0;$i<$itemCount;$i++) {
if(!empty($_POST["item_name"][$i])) {
$itemValues++;
if($queryValue!="") {
$queryValue .= ",";
}
$queryValue .= "('" . $_POST["data_i"][$i] . "', '" . $_POST["data_t"][$i] . "', '" . $_POST["zi"][$i] . "', '" . $_POST["noapte"][$i] . "', '" . $id . "')";
}
}
$sql = $query.$queryValue;
if($itemValues!=0) {
$result = mysql_query($sql);
if(!empty($result)) $message = "Added Successfully.";
}
}
?>
<HTML>
<HEAD>
<TITLE>PHP jQuery Dynamic Textbox</TITLE>
<LINK href="style.css" rel="stylesheet" type="text/css" />
<SCRIPT src="http://code.jquery.com/jquery-2.1.1.js"></SCRIPT>
<SCRIPT>
function addMore() {
$("<DIV>").load("input.php", function() {
$("#product").append($(this).html());
});
}
function deleteRow() {
$('DIV.product-item').each(function(index, item){
jQuery(':checkbox', this).each(function () {
if ($(this).is(':checked')) {
$(item).remove();
}
});
});
}
</SCRIPT>
</HEAD>
<BODY>
<FORM name="frmProduct" method="post" action="">
<DIV id="outer">
<DIV id="header">
<DIV class="float-left"> </DIV>
<DIV class="float-left col-heading">Item Name</DIV>
</DIV>
<DIV id="product">
<?php require_once("input.php") ?>
</DIV>
<DIV class="btn-action float-clear">
<input type="button" name="add_item" value="Add More" onClick="addMore();" />
<input type="button" name="del_item" value="Delete" onClick="deleteRow();" />
<span class="success"><?php if(isset($message)) { echo $message; }?></span>
</DIV>
<DIV class="footer">
<input type="submit" name="save" value="Save" />
</DIV>
</DIV>
</form>
</BODY>
</HTML>
Code: Select all
<DIV class="product-item float-clear" style="clear:both;">
<DIV class="float-left"><input type="checkbox" name="item_index[]" /></DIV>
<DIV class="float-left"><input type="text" name="data_i[]" /></DIV>
<DIV class="float-left"><input type="text" name="data_t[]" /></DIV>
<DIV class="float-left"><input type="text" name="zi[]" /></DIV>
<DIV class="float-left"><input type="text" name="noapte[]" /></DIV>
</DIV>