dimanche 19 avril 2015

populating html form field form data in mysql database

I want to get the book Name and Lending period fields to be filled after i enter the book id and press 'Fill' button which is of type 'submit'. So far i have tried this code and it doesnt give any result.Also the text fields display this part of code which is in the value attribute (<?php echo htmlspecialchars($row['BookName']); ?>) when the form is loaded.



<?php
$pbookid = $_POST['pbookid'];

$con = mysqli_connect('localhost','root','','kcsldb');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}


$sql = "SELECT `BookName`,`LendPer` FROM `book`,`copy` WHERE `BookId` = '$pbookid' AND copy.ISBN = book.ISBN";

$result = mysqli_query($con,$sql);

$row = mysqli_fetch_array($result);

mysqli_close($con);
?>
<form name="FormNewLoan" class="cleanform" method="POST" action="?" onsubmit="">
<fieldset>
<div class="formcontainerleft">
<p>
<label>Student No.</label>
<input type="text" name="NewLoansNo" size="6" maxlength="6" onblur="return validateSNo(document.FormNewLoan.NewLoansNo.value,'NewLoansNo-validation')"><span class="errormsg">*</span>
<br>
<span class="errorMsg" id="NewLoansNo-validation"></span>
</p>
<p>
<label>Book ID</label>
<input type="text" name="NewLoanbookId" size="23" maxlength="16"><span class="errormsg">*</span><input type="submit" value="Fill">
<br>
<span class="errorMsg" id="NewLoanbookId-validation"></span>
</p>
<p>
<label>Book Name</label>
<input type="text" name="NewLoanbname" size="50" readonly value="<?php echo htmlspecialchars($row['BookName']); ?>">
</p>
</div>
<div class="formcontainerright">
<p>
<label>Lending Period</label>
<input type="text" name="NewLoanlenPer" id="NewLoanlenPer" readonly value="<?php echo htmlspecialchars($row['LendPer']); ?>">
</p>
<p>
<label>Date</label>
<input name="NewLoanDate" id="NewLoanDateId">
</p>
<p>
<label>Due Date</label>
<input name="NewLoanDueDate" id="NewLoanDueDateId">
</p>

Aucun commentaire:

Enregistrer un commentaire