working on a form to update particular user details if required. as you can see there is also a print button.
i want to know how i can print out the div=formData if print button is clicked.
according to my current code when print is pressed the whole form itself gets printed.
i need only the values that are updated to be printed.
check out my code n please help
<html>
<head>
<style type="text/css">
.up {
float:right;
background-color:#1b5b88;
border:2px solid;
padding:4px;
color:white;
}
.over{
float:right;
background-color:#1b5b88;
border:4px solid;
border-color:#CEE3F6;
padding:2px;
color:white;
}
</style>
<script type="text/javascript">
function Clickheretoprint()
{
var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,";
disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25";
var content_vlue = document.getElementById("formData").innerHTML;
var docprint=window.open("","",disp_setting);
docprint.document.open();
docprint.document.write('<html><head><title>Print Results</title>');
docprint.document.write('</head><body onLoad="self.print()"><center>');
docprint.document.write(content_vlue);
docprint.document.write('</center></body></html>');
docprint.document.close();
docprint.focus();
}
</script>
</head>
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("sdc_cpds") or die ("error can select db");
$cpname=$_GET["name"];
$cpcourse=$_GET["course"];
$cpdate=$_GET["course_date"];
$query=mysql_query("SELECT * FROM course_participant WHERE name='$cpname' AND course='$cpcourse' AND course_date='$cpdate' UNION SELECT * FROM past_participant WHERE name='$cpname' AND course='$cpcourse' AND course_date='$cpdate'");
$row=mysql_fetch_array($query);
$name=$row['name'];
$address=$row['res_address'];
$contact_no=$row['cont_no'];
$email=$row['email'];
$gender=$row['gender'];
$age=$row['age'];
$marital_status=$row['marital_stat'];
$university=$row[university];
$facdept=$row['facdept'];
$course=$row['course'];
$course_date=$row[course_date];
$reg_date=$row['reg_date'];
$completion=$row['completion'];
$current=$row['current'];
?>
<form method="POST" action="http://localhost/drupal/node/19" name="f1">
<strong>PERSONAL DATA</strong>
<div style="background-color:#F2F2F2; padding:10px; border:1px solid; border-color:#084B8A; width:650px;">
<table>
<tr>
<td>Name:</td><td width="500"><input name="name" type="text" size="60" value="<?php echo $name; ?>"/></td>
</tr>
<tr>
<td>Residential Address:</td><td width="300"><textarea cols="45" rows="5" name="resad"/><?php echo $address; ?></textarea></td>
</tr>
<tr>
<td>NIC:</td><td width="300"><input name="NIC" type="text" size="9" value="<?php echo $nic; ?>"/>V</td>
</tr>
<tr>
<td>Contact No.:</td><td width="300"><input name="contact" type="text" size="12" value="<?php echo $contact_no; ?>"/></td>
</tr>
<tr>
<td>e-mail Address:</td><td width="300"><input name="email" type="text" size="30" value="<?php echo $email; ?>"/></td>
</tr>
<tr>
<td>Gender:</td><td width="300">
<input type="radio" name="sex" <?php if($gender==="Male") printf("checked"); ?> value="Male">MALE</radio>
<input name="sex" type="radio" <?php if($gender==="Female") printf("checked"); ?> value="Female">FEMALE</radio>
</td>
</tr>
<tr>
<td>Age:</td><td width="300"><input name="age" type="text" size="2" value="<?php echo $age; ?>"/></td>
</tr>
<tr>
<td>Marital Status:</td>
<td width="300">
<input type="radio" name="mar" value="Married"<?php if($marital_status==="Married") printf("checked"); ?>>MARRIED</radio> <input type="radio" name="mar" value="Single"<?php if($marital_status==="Single") printf("checked"); ?>>UNMARRIED</radio>
</td>
</tr>
<tr>
<td>University:</td>
<td>
<select name="uni">
<option>COLOMBO</option>
<option>PERADENIYA</option>
</select>
</td>
</tr>
<tr>
<td>Faculty/Dept:</td>
<td>
<select name="facdept">
<option>UCSC</option>
<option>SCIENCE</option>
</select>
</td>
</tr>
</table>
</div>
<br/>
<strong>ACADEMIC QUALIFICATIONS</strong>
<div style="background-color:#F2F2F2; padding:10px; border:1px solid; border-color:#084B8A; width:650px;">
<table>
<tr>
<th>Degree</th>
<th>Class</th>
<th>Year Awarded</th>
<th>University</th>
</tr>
<tr>
<?php
$result3=mysql_query("SELECT * FROM academic_qual WHERE name='$cpname' AND course='$cpcourse' AND course_date='$cpdate'");
$i=0;
WHILE($row3=mysql_fetch_array($result3)){
$deg[$i]=$row3['degree'];
$class[$i]=$row3['class'];
$year[$i]=$row3['year'];
$deg_uni[$i]=$row3['deg_uni'];
$i++;
}
echo "<td>";
echo "<input type='text' value='$deg[0]' name='degree0'/>";
echo "</td>";
echo "<td>";
echo "<input type='text' value='$class[0]' name='class0'/>";
echo "</td>";
echo "<td>";
echo "<input type='text' value='$year[0]' name='year0'/>";
echo "</td>";
echo "<td>";
echo "<input type='text' value='$deg_uni[0]' name='deg_uni0'/>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo "<input type='text' value='$deg[1]' name='degree1'/>";
echo "</td>";
echo "<td>";
echo "<input type='text' value='$class[1]' name='class1'/>";
echo "</td>";
echo "<td>";
echo "<input type='text' value='$year[1]' name='year1'/>";
echo "</td>";
echo "<td>";
echo "<input type='text' value='$deg_uni[1]' name='deg_uni1'/>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo "<input type='text' value='$deg[2]' name='degree2'/>";
echo "</td>";
echo "<td>";
echo "<input type='text' value='$class[2]' name='class2'/>";
echo "</td>";
echo "<td>";
echo "<input type='text' value='$year[2]' name='year2'/>";
echo "</td>";
echo "<td>";
echo "<input type='text' value='$deg_uni[2]' name='deg_uni2'/>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo "<input type='text' value='$deg[3]' name='degree3'/>";
echo "</td>";
echo "<td>";
echo "<input type='text' value='$class[3]' name='class3'/>";
echo "</td>";
echo "<td>";
echo "<input type='text' value='$year[3]' name='year3'/>";
echo "</td>";
echo "<td>";
echo "<input type='text' value='$deg_uni[3]' name='deg_uni3'/>";
echo "</td>";
echo "</tr>";
?>
</table>
</div>
<br/>
<strong>COURSE DATA</strong>
<div style="background-color:#F2F2F2; padding:10px; border:1px solid; border-color:#084B8A; width:650px;">
<table>
<tr>
<td>Course:</td>
<td>
<input type=text" name="course" value="<?php echo $course; ?>"/>
</td>
</tr>
<tr>
<td>Date of Course:</td>
<td>
<input type="text" name="course_date" size="10" value="<?php echo $course_date; ?>"/>
</td>
</tr>
<tr>
<td>
Date Registered:
</td>
<td>
<input name="reg_date" type="text" size="10"/>
</td>
</tr>
<tr>
<td>Completion:</td><td width="300">
<input name="com" type="radio" value="yes" <?php if($completion==="yes") printf("checked"); ?>>YES</radio>
<input name="com" type="radio" value="no" <?php if($completion==="no") printf("checked"); ?>>NO</radio>
<input name="com" type="radio" value="cur" <?php if($completion==="cur") printf("checked"); ?>>CURRENT</radio>
</td>
</table>
</div>
<input type="submit" value="SAVE CHANGES" name="sc" style="float:right;" class="up" onmouseover="this.className='over'" onmouseout="this.className='up'"/>
<input type="submit" value="PRINT" name="print2" onClick="window.print()" style="float:right;" class="up" onmouseover="this.className='over'" onmouseout="this.className='up' onclick="javascript:Clickheretoprint();"/>
</form>
<br/>
</html>
<html>
<body>
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("sdc_cpds") or die ("error can select db");
$name=$_POST['name'];
$address=$_POST['resad'];
$contact_no=$_POST['contact'];
$e_mail=$_POST['email'];
$gender=$_POST['sex'];
$age=$_POST['age'];
$marrage=$_POST['mar'];
$university=$_POST['uni'];
$facdept=$_POST['facdept'];
$course=$_POST['course'];
$course_date=$_POST['course_date'];
$reg_date=$_POST['reg_date'];
$completion=$_POST['com'];
$current=$_POST['cur'];
$query="UPDATE `sdc_cpds`.`course_participant` SET `name` = '$name', `res_address`='$address' , `cont_no`='$contact_no',`email`='$e_mail',`gender`='$gender',`age`='$age',`marital_stat`='$marrage',`university`='$university',`facdept`='$facdept',`course`='$course',`reg_date`='$reg_date',`completion`='$completion' WHERE `name` ='$name' AND `course`='$course' AND `course_date`='$course_date'" ;
$query2="UPDATE `sdc_cpds`.`past_participant` SET `name` = '$name', `res_address`='$address' , `cont_no`='$contact_no',`email`='$e_mail',`gender`='$gender',`age`='$age',`marital_stat`='$marrage',`university`='$university',`facdept`='$facdept',`course`='$course',`reg_date`='$reg_date',`completion`='$completion' WHERE `name` ='$name' AND `course`='$course' AND `course_date`='$course_date'" ;
$res1=mysql_query($query);
$res2=mysql_query($query2);
$deg0=$_POST['degree0'];
$class0=$_POST['class0'];
$year0=$_POST['year0'];
$deg_uni0=$_POST['deg_uni0'];
$deg1=$_POST['degree1'];
$class1=$_POST['class1'];
$year1=$_POST['year1'];
$deg_uni1=$_POST['deg_uni1'];
$deg2=$_POST['degree2'];
$class2=$_POST['class2'];
$year2=$_POST['year2'];
$deg_uni2=$_POST['deg_uni2'];
$deg3=$_POST['degree3'];
$class3=$_POST['class3'];
$year3=$_POST['year3'];
$deg_uni3=$_POST['deg_uni3'];
$res4=mysql_query("DELETE FROM academic_qual WHERE `name` ='$name' AND `course`='$course' AND `course_date`='$course_date'");
$res5=mysql_query("INSERT INTO academic_qual (name, course, course_date, degree, class, year, deg_uni)
VALUES ('$name','$course','$course_date', '$deg0', '$class0', '$year0', '$deg_uni0')");
$res6=mysql_query("INSERT INTO academic_qual (name, course, course_date, degree, class, year, deg_uni)
VALUES ('$name','$course','$course_date', '$deg1', '$class1', '$year1', '$deg_uni1')");
$res7=mysql_query("INSERT INTO academic_qual (name, course, course_date, degree, class, year, deg_uni)
VALUES ('$name','$course','$course_date', '$deg2', '$class2', '$year2', '$deg_uni2')");
$res8=mysql_query("INSERT INTO academic_qual (name, course, course_date, degree, class, year, deg_uni)
VALUES ('$name','$course','$course_date', '$deg3', '$class3', '$year3', '$deg_uni3')");
if($res1 && $res2 && $res3 && $res4 && $res5 || $res6 || $res7 || $res8){
echo "<b>DATABASE HAS BEEN UPDATED!</b>";
}
else{
echo "<b>UPDATE ERROR!</b>";
}
echo "<br/><a href='http://localhost/drupal/node/2'>Back to Search</a>";echo "<br>";
echo "<br>";
echo "<div id='formData'; onclick='javascript:Clickheretoprint();'>";
echo "Personal Data";
echo $name;echo "<br>";echo $address; echo "<br>";echo $contact_no;echo "<br>";echo $e_mail;echo "<br>";echo $gender;echo "<br>";echo $age;echo "<br>";echo $marrage;echo "<br>";echo $university;echo "<br>";echo $facdept;echo "<br>";
echo "Academic Qualifications";
echo "<table>";
echo "<tr style='background-color:#A9D0F5'><th></th><th>Degree</th><th>Class</th><th>Year Awarded</th><th>University</th>";
while($row = mysql_fetch_array( $result )) {
echo "<tr style='background-color:#CEE3F6'>";
echo "<td>";echo $row['degree1'];echo "</td>";
echo "<td>";echo $row['class1'];echo "</td>";
echo "<td>";echo $row['year1'];echo "</td>";
echo "<td>";echo $row['deg_uni1'];echo "</td>";
echo "<td>";echo $row['degree2'];echo "</td>";
echo "<td>";echo $row['class2'];echo "</td>";
echo "<td>";echo $row['year2'];echo "</td>";
echo "<td>";echo $row['deg_uni2'];echo "</td>";
echo "<td>";echo $row['degree3'];echo "</td>";
echo "<td>";echo $row['class3'];echo "</td>";
echo "<td>";echo $row['year3'];echo "</td>";
echo "<td>";echo $row['deg_uni3'];echo "</td>";
echo "</tr>";
}
echo "</table>";
echo "Course Data";
echo $course;echo "<br>";echo $course_date;echo "<br>";echo $reg_date;echo "<br>";echo $completion;echo "<br>";echo $current;echo "<br>";
echo "<div >";
?>
</body>
</html>