Dans un de mes formulaire pour le Gym, j'ai la possibilité d'enregistrer des membres y creer un aperçu de la facture en PDF.
Voici mon code coté formulaire :
<div class="box-content nopadding">
<form action="new_submit.php" method="POST" class='form-horizontal form-bordered'>
<div class="control-group">
<label for="textfield" class="control-label">Membership ID :</label>
<div class="controls">
<input type="text" name="p_id" value="<?php echo time();?>" class="uneditable-input" readonly />
</div>
</div>
<div class="control-group">
<label for="textfield" class="control-label">Photo :</label>
<div class="controls">
<script language="JavaScript">
document.write(webcam.get_html(300, 220));
</script>
<script language="JavaScript">
webcam.set_api_url('test.php');
webcam.set_quality(100); // JPEG quality (1 - 100)
webcam.set_shutter_sound(true); // play shutter click sound
webcam.set_hook('onComplete', 'my_completion_handler');
function take_snapshot() {
// take snapshot and upload to server
webcam.snap();
}
</script>
<input type=button class="btn btn-primary" value="Take Snapshot" onClick="take_snapshot()">
</div>
</div>
<div class="control-group">
<label for="textfield" class="control-label">Name :</label>
<div class="controls"><span id="sprytextfield1">
<input type="text" name="p_name" id="textfield3" class="input-xlarge" data-rule-required="true" data-rule-minlength="4" placeholder="Member Name" maxlength="30">
<span class="textfieldRequiredMsg">A value is required.</span></span>
</div>
</div>
<div class="control-group">
<label for="emailfield" class="control-label">E-Mail :</label>
<div class="controls">
<input type="text" name="email" id="emailfield" class="input-xlarge" data-rule-minlength="5" placeholder="E-Mail" maxlength="60">
</div>
</div>
<div class="control-group">
<label for="textfield" class="control-label">Proof Given :</label>
<div class="controls"><span id="spryselect1">
<select name="proof" id="bbb" data-rule-required="true" class="country1">
<option value="">-- Please select --</option>
<option value="PAN Card">PAN Card</option>
<option value="Voter Card">Voter Card</option>
<option value="Driving License">Driving License</option>
<option value="Passport">Passport</option>
<option value="College/School ID">College/School ID</option>
<option value="Aadhaar Card">Aadhaar Card</option>
<option value="Ration Card">Ration Card</option>
<option value="Bank Passbook">Bank Passbook</option>
<option value="Others">Others</option>
</select>
<span class="selectRequiredMsg">Please select an item.</span></span></div>
<div class="city1"> </div>
</div>
<div class="control-group">
<label for="textfield" class="control-label">Age :</label>
<div class="controls"><span id="sprytextfield2">
<input type="text" name="age" id="textfield4" class="input-xlarge" data-rule-required="true" data-rule-minlength="1" placeholder="Age" onKeyPress="return checkIt(event)" maxlength="3">
<span class="textfieldRequiredMsg">A value is required.</span></span>
</div>
</div>
<div class="control-group">
<label for="textfield" class="control-label">Sex :</label>
<div class="controls"><span id="spryselect1">
<select name="sex" id="bbb" data-rule-required="true">
<option value="">-- Please select --</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
<span class="selectRequiredMsg">Please select an item.</span></span>
</div>
</div>
<div class="control-group">
<label for="textfield" class="control-label">Date :</label>
<div class="controls"><span id="sprytextfield3">
<input type="text" name="date" id="textfield22" class="input-medium datepick" value="<?php echo date('Y-m-d');?>">
<span class="textfieldRequiredMsg">A value is required.</span></span>
</div>
</div>
<div class="control-group">
<label for="textfield" class="control-label">Address :</label>
<div class="controls">
<input type="text" name="add" id="textfield5" class="input-xlarge" data-rule-required="true" data-rule-minlength="6" placeholder="Address">
</div>
</div>
<div class="control-group">
<label for="textfield" class="control-label">Contact :</label>
<div class="controls"><span id="sprytextfield4">
<input type="text" name="contact" id="textfield6" class="input-xlarge" data-rule-required="true" data-rule-minlength="10" placeholder="Mobile / Phone" onKeyPress="return checkIt(event)" maxlength="10">
<span class="textfieldRequiredMsg">A value is required.</span></span></div>
</div>
<div class="control-group">
<label for="textfield" class="control-label">Height :</label>
<div class="controls">
<input type="text" name="height" id="textfield" class="input-large" data-rule-required="true" data-rule-minlength="1" placeholder="Height" maxlength="10"> (In FEET)
</div>
</div>
<div class="control-group">
<label for="textfield" class="control-label">Weight :</label>
<div class="controls">
<input type="text" name="weight" id="textfield" class="input-large" data-rule-required="true" data-rule-minlength="1" placeholder="Weight" maxlength="10"> (In Kgs)
</div>
</div>
<div class="control-group">
<label for="textfield" class="control-label">Membership Type :</label>
<div class="controls"><span id="spryselect2">
<select name="mem_type" id="id" data-rule-required="true" class="country">
<option value="">-- Please select --</option>
<?php
$query = "select * from mem_types";
//echo $query;
$result = mysqli_query($con, $query);
if (mysqli_affected_rows($con) != 0) {
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo "<option value=" . $row['mem_type_id'] . ">" . $row['name'] . "</option>";
}
}
?>
</select>
<span class="selectRequiredMsg">Please select an item.</span></span></div>
<div class="city"></div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
</div>
Lorsque j'insère dans ma BDD les informations bien évidement dans ma table subcription j'ai une error 'Profile NOT Added, Check Again' je voudrais que chaque ligne de ma facture soient insérer dans ma bdd par ligne <?php
require 'db_conn.php';
page_protect();
$query2 = "select * from user_data WHERE wait='yes'";
//echo $query;
$result2 = mysqli_query($con, $query2);
if (mysqli_affected_rows($con) == 1) {
} else {
mysqli_query($con, "DELETE FROM user_data WHERE wait='yes'");
echo "<head><script>alert('Profile NOT Added, Check Again');</script></head></html>";
echo "<meta http-equiv='refresh' content='0; url=new_entry.php'>";
}
if (isset($_POST['p_name']) && isset($_POST['mem_type']) && isset($_POST['total']) && isset($_POST['age']) && isset($_POST['paid'])) {
function getRandomWord($len = 3)
{
$word = array_merge(range('a', 'z'), range('0', '9'));
shuffle($word);
return substr(implode($word), 0, $len);
}
$mem_type = $_POST['mem_type'];
$query1 = "select * from mem_types WHERE mem_type_id='$mem_type'";
//echo $query;
$result1 = mysqli_query($con, $query1);
if (mysqli_affected_rows($con) == 1) {
while ($row1 = mysqli_fetch_array($result1, MYSQLI_ASSOC)) {
$name_type = $row1['name'];
$details = $row1['details'];
$days = $row1['days'];
}
}
$proof = $_POST['proof'];
if (isset($_POST['other_proof'])) {
$other_proof = $_POST['other_proof'];
} else {
$other_proof = " ";
}
$invoice = substr(time(), 2, 10) . getRandomWord();
$date = $_POST['date'];
$age = rtrim($_POST['age']);
$full_name = rtrim($_POST['p_name']);
$email = rtrim($_POST['email']);
$address = rtrim($_POST['add']);
$contact = rtrim($_POST['contact']);
$sex = rtrim($_POST['sex']);
$height = rtrim($_POST['height']);
$weight = rtrim($_POST['weight']);
$total = $_POST['total'];
$paid = $_POST['paid'];
$mod_date = strtotime($date . "+ $days days");
$expiry = date("Y-m-d", $mod_date);
$wait = "no";
$time = $days * 86400;
$exp_time = $time + strtotime($date);
$query = "select * from user_data WHERE wait='yes'";
//echo $query;
$result = mysqli_query($con, $query);
if (mysqli_affected_rows($con) == 1) {
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$p_id = $row['newid'];
mysqli_query($con, "UPDATE user_data SET name='$full_name', address='$address', contact='$contact', email='$email', height='$height', weight='$weight', joining='$date', age='$age', proof='$proof', other_proof='$other_proof', sex='$sex' WHERE wait='yes'");
$bal = $total - $paid;
mysqli_query($con, "INSERT INTO subsciption (mem_id,name,sub_type,paid_date,total,paid,expiry,invoice,sub_type_name,bal,exp_time,renewal)
VALUES ('$p_id','$full_name','$mem_type','$date','$total','$paid','$expiry','$invoice','$name_type','$bal','$exp_time','yes')");
echo "<head><script>alert('Member Added ,');</script></head></html>";
mysqli_query($con, "UPDATE user_data SET wait='no' WHERE wait='yes'");
}
}
}
else {
echo "<head><script>alert('Profile NOT Added, Check Again');</script></head></html>";
echo "<meta http-equiv='refresh' content='0; url=new_entry.php'>";
}
?>
<!doctype html>
<head>
<meta charset="utf-8">
<title>Invoice</title>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="jquery-barcode.js"></script>
<script type="text/javascript">
function generateBarcode(){
var value = "<?php echo $invoice; ?>";
var btype = "code128";
var renderer = "css";
var quietZone = false;
if ($("#quietzone").is(':checked') || $("#quietzone").attr('checked')){
quietZone = true;
}
var settings = {
output:renderer,
bgColor: $("#bgColor").val(),
color: $("#color").val(),
moduleSize: $("#moduleSize").val(),
posX: $("#posX").val(),
posY: $("#posY").val(),
addQuietZone: $("#quietZoneSize").val()
};
if ($("#rectangular").is(':checked') || $("#rectangular").attr('checked')){
value = {code:value, rect: true};
}
if (renderer == 'canvas'){
clearCanvas();
$("#barcodeTarget").hide();
$("#canvasTarget").show().barcode(value, btype, settings);
} else {
$("#canvasTarget").hide();
$("#barcodeTarget").html("").show().barcode(value, btype, settings);
}
}
function showConfig1D(){
$('.config .barcode1D').show();
$('.config .barcode2D').hide();
}
function showConfig2D(){
$('.config .barcode1D').hide();
$('.config .barcode2D').show();
}
function clearCanvas(){
var canvas = $('#canvasTarget').get(0);
var ctx = canvas.getContext('2d');
ctx.lineWidth = 1;
ctx.lineCap = 'butt';
ctx.fillStyle = '#FFFFFF';
ctx.strokeStyle = '#000000';
ctx.clearRect (0, 0, canvas.width, canvas.height);
ctx.strokeRect (0, 0, canvas.width, canvas.height);
}
$(function(){
$('input[name=btype]').click(function(){
if ($(this).attr('id') == 'datamatrix') showConfig2D(); else showConfig1D();
});
$('input[name=renderer]').click(function(){
if ($(this).attr('id') == 'canvas') $('#miscCanvas').show(); else $('#miscCanvas').hide();
});
generateBarcode();
});
</script>
</head>
<body>
<header>
<a href="new_entry.php"><h1>Invoice (New Registration)</h1></a>
<address>
<p>Galaxy The Gym</p>
<p>M-21, Lane 2 ,Khalilullah Masjid</p><p>Jamia Nagar Oklha New Delhi 110025</p>
<p>Mobile:-9873712786</p><p>www.galaxythegym.com ([email protected])</p><br><p><div id="barcodeTarget" class="barcodeTarget"></div>
<canvas id="canvasTarget"></canvas> </span>
</address>
<span><img alt="" src="logo.png">
</header>
<article>
<table class="meta">
<img alt="" src="pic1.jpg" width="100" height="100">
<tr>
<th><span >Invoice #</span></th>
<td><span ><?php echo $invoice;?></span></td>
</tr>
<tr>
<th><span >Date</span></th>
<td><span ><?php echo $date; ?></span></td>
</tr>
<tr>
<th><span >Member ID / Reg ID</span></th>
<td><?php $regid = substr($p_id, 6, 10); echo $p_id . " / " . $regid; ?></span></td>
</tr>
</table>
<table class="meta">
<tr>
<th><span >Name</span></th>
<td><span ><?php echo $full_name; ?></span></td>
</tr>
<tr>
<th><span >Age, Sex</span></th>
<td><span ><?php echo $age . " / " . $sex; ?></span></td>
</tr>
<tr>
<th><span >Height / Weight</span></th>
<td><?php echo $height . " FEET / " . $weight . " Kg"; ?></span></td>
</tr>
</table>
<table class="inventory">
<thead>
<tr>
<th><span >Membership Type</span></th>
<th><span >Details</span></th>
<th><span >Subscription Expiry</span></th>
</tr>
</thead>
<tbody>
<tr>
<td><span ><?php echo $name_type; ?></span></td>
<td><span ><?php echo $details . " For " . $days; ?></span></td>
<td><span ><?php echo $expiry; ?></span></td>
</tr>
</tbody>
</table>
<table class="balance">
<tr>
<th><span >Total</span></th>
<td><span data-prefix>INR</span><span><?php echo $total; ?></span></td>
</tr>
<tr>
<th><span >Paid</span></th>
<td><span data-prefix>INR</span><span><?php echo $paid; ?></span></td>
</tr>
<tr>
<th><span >Due</span></th>
<td><span data-prefix>INR</span><span><?php echo $total - $paid; ?></span></td>
</tr>
</table>
</article>
</body>
</html>
Je ne sais pas comment insérer dans ma bdd chaque des lignesMerci à vous