Basic form to enter name & marks of six students. Submitting will draw a bargraph. Save the PHP file as "gengraphs.php"
By : nazly
<?php
if($t1){
header("Content-type: image/jpeg");
$imPoint=ImageCreate(400,425); $bgColor=ImageColorAllocate($imPoint,255,255,255); $stColor=ImageColorAllocate($imPoint,0,0,0); $color[0]=ImageColorAllocate($imPoint,255,0,0); $color[1]=ImageColorAllocate($imPoint,0,255,0); $color[2]=ImageColorAllocate($imPoint,0,0,255); $color[3]=ImageColorAllocate($imPoint,255,0,255); $color[4]=ImageColorAllocate($imPoint,0,255,255); $color[5]=ImageColorAllocate($imPoint,255,255,0); for($i=0;$i<11;$i++){ ImageString($imPoint,2,5,220-($i*20),$i*10,$stColor); } for($i=0;$i<6;$i++){ $total=2*$stMarks[$i]; ImageFilledRectangle($imPoint,50+($i*50),225-$total,75+($i*50),225,$color[$i]); ImageString($imPoint,3,55+($i*50),225-$total-15,$stMarks[$i],$stColor); ImageFilledREctangle($imPoint,110,260+($i*25),125,275+($i*25),$color[$i]); ImageString($imPoint,3,150,260+($i*25),$stName[$i],$stColor); } ImageLine($imPoint,25,225,350,225,$stColor); ImageLine($imPoint,25,10,25,225,$stColor); ImageRectangle($imPoint,100,250,250,410,$stColor); ImageJPEG($imPoint); ImageDestroy($imPoint); } else{ echo "This is just a sample script as values are not validated. Make sure you enter integer values on the marks text box<br>"; echo "<form name=\"a\" action=\"gengraphs.php\" method=\"post\"><input type=\"hidden\" name=\"t1\" value=\"1\">"; for($i=0;$i<6;$i++) { $textVal=$i+1; echo "Student Name : <input type=\"text\" name=\"stName[$i]\" value=\"Name$textVal\" maxlength=\"10\"> Marks : <input type=\"text\" name=\"stMarks[$i]\" value=\"0\" maxlength=\"3\"><br>"; } echo "<input type=\"submit\" value=\"Draw Graph\"></form>"; } ?>
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.