Checkbox mysql php - php

<form action="execute_new.php" id="modalform" method="post">
<td width="147"> <strong>
<font color="#033">Sticker No:</font><font color="#FF0000">*</font></td>
<td width="146"><input type="text" name="stickerno" /></td>
<tr>
<td><strong>
<font color="#033">TO : </font></td>
</tr>
<tr>
<td >
<input name="fname" type="text" />
</td>
<td >
<input name="mname" type="text" />
</td>
<td width="143" align="right">
<input name="lname" type="text" />
</td>
</tr>
<tr>
<td>
First Name</font><font color="#FF0000">*</font>
</td>
<td >
Middle Name</font><font color="#FF0000">*</font>
</td>
<td>
Last Name</font><font color="#FF0000">*</font>
</td>
</tr>
</table><br>
<br>
<table>
<tr>
<td><strong>
<font color="#033"> ADDRESS:</font></font><font color="#FF0000">*</font> </td>
<td align="center"><input name="address" type="text" value="" size="70"></td>
</tr>
</table>
<p> </p>
<font color="#033">
<table border="15" bgcolor="#00FF66" bordercolor="#000000" width="650" cellpadding="1" cellspacing="1">
<br>
<br>
<tr>
<td >LICENSE NO:<font color="#FF0000">*</font></td>
<td align="center"><input type="text" name="license"/></td>
<td >BIRTH DATE:</td>
<td align="center"><input name="bdate" id="demo1" type="text"><img src="cal.gif" width="16" height="16" border="0"></td>
<tr>
<td >PLATE NO:<font color="#FF0000">*</font></td>
<td align="center"><input type="text" name="plateno"/></td>
<td >PUV BODY NAME:</td>
<td align="center"><input type="text" name="puvbname" /></td>
</tr>
<tr>
<td >TYPE OF VEHICLE:</td>
<td align="center"><select id="vehicletype" name="vehicletype" style="width:134px">
<option value="Private">Private</option>
<option value="Public">Public</option>
</select>
<td >PUV BODY NO:</td>
<td align="center"><input type="text" name="puvbno" /></td>
</tr>
<tr>
<td >OWNER OF VEHICLE:</td>
<td align="center"><input type="text" name="vehicleowner" /></td>
<td >ADDRESS:</td>
<td align="center"><input type="text" name="taddress" /></td>
</tr>
<tr>
<td >PLACE OF VIOLATION:<font color="#FF0000">*</font></td>
<td align="center"><input type="text" name="violationplace" /></td>
<td>DATE / TIME:<font color="#FF0000">*</font></td>
<td align="center"><input name="datetime" id="demo2" type="text"><img src="cal.gif" width="16" height="16" border="0">
</tr>
</table><br>
<table border="15" bordercolor="#000000" width="150" cellpadding="1" cellspacing="1">
<tr>Confiscated:</tr>
<br>
<tr><td><input type="radio" name="RadioGroup1" value="License ID" id="RadioGroup1_0" checked>License ID</tr><br>
<tr><td><input type="radio" name="RadioGroup1" value="License O.R." id="RadioGroup1_1">License O.R.</tr>
<tr>
<td> <input type="radio" name="RadioGroup1" value="TCP/TOP" id="RadioGroup1_2">
TCP/TOP</tr>
<tr><td><input type="radio" name="RadioGroup1" value="License Plate" id="RadioGroup1_3">
License Plate</tr>
<tr><td><input type="radio" name="RadioGroup1" value="Not Confiscated" id="RadioGroup1_4">
Not Confiscated</tr>
</tr></table><br />
<center><strong>You are hereby cited for committing the traffic violations / checked hereunder</strong><br /></center>
<br>
<br> <table width="100%px" border="7" cellspacing="1" cellpadding="1" bordercolordark="#000000" style="font-size:13px">
<tr>
<td><input type="checkbox" name="cbox[]" value="Unattended/Illegaly Parked Vehicle" />
Unattended / Illegaly Parked Vehicle</td>
<td><input type="checkbox" name="cbox[]" value="Out of Line Operation/Route Violation" />
Out of Line Operation/Route Violation</br></td>
<tr>
<td><input type="checkbox" name="cbox[]" value="Illegal Parking" />
Illegal Parking</td>
<td><input type="checkbox" name="cbox[]" value="Trip Cutting" />
Trip Cutting</br></td>
<tr>
<td><input type="checkbox" name="cbox[]" value="Illegal Topload" />
Illegal Topload</td>
<td>
<input type="checkbox" name="cbox[]" value="Over Charging" />
Over Charging</td></tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Truck Ban/Tricycle Ban" />
Truck Ban/Tricycle Ban</td>
<td><input type="checkbox" name="cbox[]" value="Refusal to Convey Passenger"/>
Refusal to Convey Passenger</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Driving in Slippers/Sleeveless shirt" />
Driving in Slippers/Sleeveless shirt</td>
<td>
<input type="checkbox" name="cbox[]" value="Overspeeding/Drag Racing/Reckless Driving" />Overspeeding/Drag Racing/Reckless Driving</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Driving w/o License/Expired/Invalid License" />
Driving w/o License/Expired/Invalid License</td>
<td><input type="checkbox" name="cbox[]" value="One-way Street Violation" />One-way Street Violation</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="No PUV ID" />
No PUV ID</td>
<td><input type="checkbox" name="cbox[]" value="Illegal Loading/Unloading" />Illegal Loading/Unloading</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Driving Dilapidated">
Driving Dilapidated</td>
<td><input type="checkbox" name="cbox[]" value="Traffic Obstruction"/>Traffic Obstruction</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Junk Vehicle" />
Junk Vehicle</td>
<td><input type="checkbox" name="cbox[]" value="Disregarding Traffic Sign/Light" />Disregarding Traffic Sign/Light</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="No Smoking 20% Discount Sticker" />
No "No Smoking"/20% Discount Sticker</td>
<td><input type="checkbox" name="cbox[]" value="Illegal Blowing of Horn" />Illegal Blowing of Horn</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="No Permit Decalsticker" />
No Permit Decalsticker</td>
<td><input type="checkbox" name="cbox[]" value="Failure to obey Police Order" />Failure to obey Police Order</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Stereo Set Operated at Excessive Sound Volume" />
Stereo Set Operated at Excessive Sound Volume</td>
<td>
<input type="checkbox" name="cbox[]" value="No Helmet/Head Gear" />
No Helmet/Head Gear</td>
<tr>
<td><input type="checkbox" name="cbox[]" value="No Trash Can/Receptacle" />
No Trash Can/Receptacle</td>
<td><input type="checkbox" name="cbox[]" value="Smoke Belching" />
Smoke Belching</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Colorum PUV" />
Colorum PUV</td>
<td><input type="checkbox" name="cbox[]" value="Failure to Switch Headlights" />Failure to Switch Headlights</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="No Plate" />
No Plate</td>
<td><input type="checkbox" name="cbox[]" value="No U-turn" /> No U-turn</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Driving under the Influence of Liquor" />
Driving under the Influence of Liquor</td>
<td><input type="checkbox" name="cbox[]" value="Dirty Plate" />
Dirty Plate</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Counter Flow" />
Counter Flow</td>
<td><input type="checkbox" name="cbox[]" value="Arrogant Driver/Conductor" />Arrogant Driver/Conductor</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Driver's/Conductor's Uniform/I.D." />
Driver's/Conductor's Uniform / I.D.</td>
<td><input type="text" name="oviolation" />
Other Traffic Violations(Specify)</td>
</tr></table>
<br>
</label>
<p align="center">
<p align="center"><strong>Apprehending Office ( Rank & Name )</strong><font color="#FF0000">*</font></p>
<label> </label>
<select name="type" size="1">
<option>Job Order</option>
<option>Permanent</option>
</select>
<input type="text" name="officer" placeholder="Officer Name"/>
</p>
<h5 align="center">PUBLIC ORDER & SAFETY OFFICE</h5>
<h5 align="center"> </h5>
<h5 align="center">
</h5>
</font>
<input type="submit" name="register" value="Add" class="adds"/>
<input type="reset" name="cancel" value="Reset" class="add"/>
<br />
</h5>
</form>
<?php
date_default_timezone_set('Asia/Manila');
$conn=mysql_connect("localhost","root","");
mysql_select_db("dbposo",$conn);
if(isset($_POST['register']))
{
$license=$_POST['license'];
$query = mysql_query("SELECT * FROM tblviolator WHERE license = '$license'");
$fetch_rows = mysql_num_rows($query);
if ( $fetch_rows > 0 )
{
echo "<script>alert('License # already exist')</script>";
header("Refresh: 0;url=new.php");
}
elseif( empty($_POST['stickerno']))
{
echo "<script>alert('Please check if all the * marker field is filled!')</script>";
header("Refresh: 0;url=new.php");
}
else
{
$stickerno=$_POST['stickerno'];
$fname=$_POST['fname'];
$mname=$_POST['mname'];
$lname=$_POST['lname'];
$address=$_POST['address'];
$bdate=$_POST['bdate'];
$plateno=$_POST['plateno'];
$puvbname=$_POST['puvbname'];
$vehicletype=$_POST['vehicletype'];
$puvbno=$_POST['puvbno'];
$vehicleowner=$_POST['vehicleowner'];
$taddress=$_POST['taddress'];
$violationplace=$_POST['violationplace'];
$datetime=$_POST['datetime'];
$confiscated=$_POST['RadioGroup1'];
$violation=$_POST['cbox'];
$oviolation=$_POST['oviolation'];
$type=$_POST['type'];
$officer=$_POST['officer'];
mysql_query("insert into tblviolator(license, stickerno, fname, mname, lname, address, bdate, plateno, puvbname, vehicletype, puvbno, vehicleowner, taddress, violationplace, datetime, confiscated, violation, oviolation, type, officer) values('$license','$stickerno','$fname','$mname','$lname','$address','$bdate','$plateno','$puvbname','$vehicletype','$puvbno','$vehicleowner','$taddress','$violationplace','$datetime','$confiscated','$violation','$oviolation','$type','$officer')",$conn) or die(mysql_error());
echo "<script>alert('Successfully Recorded, <br>
First penalty: 100php!')</script>";
header("Refresh: 0;url=new.php");
}
}
?>
What is my error here?

if you select more than one checkbox then $_POST['cbox'] becomes array .so try this
if(is_array($_POST['cbox']))
$violation=implode(',',$_POST['cbox']);
else
$violation=$_POST['cbox'];

To avoid injection better use http://php.net/manual/de/function.mysql-real-escape-string.php

If you check more than one option for the checkbox the variable $violation will be an array. Try to check multiple options and just safe the first one.
Probably if you want to store it as varchar you shoud concatenate all values.

Related

Pass variable from form to next page and put in sql statment php

Here is what I am trying to do. I have a dropdown (and or excel type look) that I need to pull data from the database. When I have an item selected I need to pass the info to the next page via a session. I have the drop down pulling from the database but I need to list Name and address in the dropdown.
If this is not possible I can do a list of items from a search but I will need to make the id a link to pass the id to the next page where I need to build a report.
If you can give me some info on this I would appreciate it.
Here is what I have for code on the dropdown
Code: Select all
<?php
// declare database connection variables.
$host = "localhost";
$username = "root";
$password = "";
$db_name = "sample";
$tbl_name = "tbl_report";
// connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql = "SELECT id, name, address FROM $tbl_name";
$result = mysql_query($sql) or die(mysql_error());
$dropdown = "<form action='report.php' method='post'>";
$dropdown .= "<select name='items' class='select'>";
while ($row = mysql_fetch_assoc($result)) {
$dropdown .= '<option value="' . $row['id'] . '">' .
$row['name'] . ' - ' . $row['address'] . '</option>';;
}
$dropdown .= "\r\n</select>";
$dropdown .= "<input type='submit' name='submit' value='Submit'>";
$dropdown .= "</form>"; //closing the form tag
echo $dropdown;
?>
What I need to do is pass the ID to the next page and have the $id show up in the code for my next sql statement.
Here is the code that I have for the next page sql statement.
select * from $tbl_name where id = (this is where I get hung up on.)
What I need is a way to pass the $row['id'] to the next page and put that in the sql code and then use the get method to display the info on the form of that page.
Here is the setup of the pages. select-report.php (this is where the drop down is) --> report.php.
Here is the form for report.php where i need to carry over the value of id and do a sql of select * from $tbl_name where id=[$post=items]; Then i need to use the $get to put all the items in the form below:
<form id="form1" name="form1" method="post" action="">
<table width="100%" border="0" cellspacing="4" cellpadding="4">
<tr>
<td width="20%">Water Purveyor
<input name="water-purveyor" type="text" id="water-purveyor" size="35" />
</td>
<td colspan="2">Facility Contact
<input type="text" name="facility-contact" id="facility-contact" /></td>
<td colspan="2">Facility Address
<input type="text" name="facility-address" id="facility-address" /></td>
</tr>
<tr>
<td>Manufacturer
<input type="text" name="manufacturer" id="manufacturer" /></td>
<td width="20%">State
<select name="state" id="state">
</select></td>
<td width="20%">Model #
<input name="model-num" type="text" id="model-num" size="10" /></td>
<td width="20%">Serial #
<input name="serial-num" type="text" id="serial-num" size="10" /></td>
<td width="20%">Meter #
<input name="meter-num" type="text" id="meter-num" size="10" /></td>
</tr>
<tr>
<td>Owner
<input type="text" name="owner" id="owner" /></td>
<td>Phone #
<input name="phone-num" type="text" id="phone-num" size="12" /></td>
<td>Caged
<input type="checkbox" name="caged" id="caged" /></td>
<td>Locked
<input type="checkbox" name="locked" id="locked" /></td>
<td>Code key
<input name="code-key" type="text" id="code-key" size="6" /></td>
</tr>
<tr>
<td colspan="2">Owner Address
<input name="owner-address" type="text" id="owner-address" size="50" /></td>
<td>Owner City
<input type="text" name="owner-city" id="owner-city" /></td>
<td>Owner State
<select name="owner-state" id="owner-state">
</select></td>
<td>Owner Zip
<input name="owner-zip" type="text" id="owner-zip" size="10" /></td>
</tr>
<tr>
<td>Contact
<input type="text" name="contact" id="contact" /></td>
<td>Contact Phone
<input name="contact-phone" type="text" id="contact-phone" size="10" /></td>
<td> </td>
<td>Other</td>
<td> </td>
</tr>
<tr>
<td colspan="2">Facility Name
<input name="facility-name" type="text" id="facility-name" size="40" /></td>
<td colspan="3">Assembly Address
<input name="assembly-address" type="text" id="assembly-address" size="75" /></td>
</tr>
<tr>
<td colspan="5">Onsite Location
<input name="onsite-location" type="text" id="onsite-location" size="75" /></td>
</tr>
<tr>
<td colspan="5">email Address
<input name="email" type="text" id="email" size="125" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>SHUTOFF VALVES</td>
<td colspan="2"><table width="100%" border="0" cellspacing="4" cellpadding="4">
<tr>
<td>N/A</td>
<td>Good</td>
<td>Poor</td>
<td>Fail</td>
</tr>
</table></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Valve 1</td>
<td colspan="2"><table width="100%" border="0" cellspacing="4" cellpadding="4">
<tr>
<td><input type="checkbox" name="v1-na" id="v1-na" /></td>
<td><input type="checkbox" name="v1-good" id="v1-good" /></td>
<td><input type="checkbox" name="v1-poor" id="v1-poor" /></td>
<td><input type="checkbox" name="v1-fail" id="v1-fail" /></td>
</tr>
</table></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Valve 2</td>
<td colspan="2"><table width="100%" border="0" cellspacing="4" cellpadding="4">
<tr>
<td><input type="checkbox" name="v2-na" id="v2-na" /></td>
<td><input type="checkbox" name="v2-good" id="v2-good" /></td>
<td><input type="checkbox" name="v2-poor" id="v2-poor" /></td>
<td><input type="checkbox" name="v2-fail" id="v2-fail" /></td>
</tr>
</table></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Assembly Replacement?
<input type="checkbox" name="assembly-replacement" id="assembly-replacement" /></td>
<td>if yes Serial #
<input type="text" name="assembly-replacement-serial" id="assembly-replacement-serial" /></td>
<td>New Installation
<input type="checkbox" name="new-install" id="new-install" /></td>
<td>Permit #
<input type="text" name="permit-num" id="permit-num" /></td>
<td> </td>
</tr>
<tr>
<td>Containment
<input type="checkbox" name="containment" id="containment" /></td>
<td>Isolation
<input type="checkbox" name="isolation" id="isolation" /></td>
<td colspan="2">Assembly Ground Clearance
<input type="text" name="assembly-ground-clearance" id="assembly-ground-clearance" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Domestic
<input type="checkbox" name="domestic" id="domestic" /></td>
<td>Irrigation
<input type="checkbox" name="irrigation" id="irrigation" /></td>
<td>Fire Line
<input type="checkbox" name="fire-line" id="fire-line" /></td>
<td>Alarmed Fire Line
<input type="checkbox" name="alarmed-fire-line" id="alarmed-fire-line" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2"><strong><em><u>Double Check Balve Assembly Repair</u></em></strong></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Repairs</td>
<td>Check Valve 1</td>
<td> </td>
<td>Check Valve 2</td>
<td> </td>
</tr>
<tr>
<td rowspan="3"> </td>
<td>Cleaned
<input type="checkbox" name="cv1-repair-cleaned" id="cv1-repair-cleaned" /></td>
<td> </td>
<td>Cleaned
<input type="checkbox" name="cv2-repair-cleaned" id="cv2-repair-cleaned" /></td>
<td> </td>
</tr>
<tr>
<td><strong>Replaced</strong></td>
<td> </td>
<td><strong>Replaced</strong></td>
<td> </td>
</tr>
<tr>
<td>Rubber Kit
<input type="checkbox" name="cv1-rubber-kit" id="cv1-rubber-kit" /></td>
<td> </td>
<td>Rubber Kit
<input type="checkbox" name="cv2-rubber-kit" id="cv2-rubber-kit" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>Other
<input type="checkbox" name="cv1-other" id="cv1-other" /></td>
<td> </td>
<td>Other
<input type="checkbox" name="cv2-other" id="cv2-other" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td colspan="2">Comments
<textarea name="cv1-other-comments" id="cv1-other-comments" cols="45" rows="5"></textarea></td>
<td colspan="2">Comments
<textarea name="cv2-other-comments" id="cv2-other-comments" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2">Initial Test By
<input name="initial-test-by" type="text" id="initial-test-by" size="50" /></td>
<td colspan="2">Certified Tester #
<input type="text" name="certified-tester-num" id="certified-tester-num" /></td>
<td>Test Date/Time
<input type="text" name="test-date-time" id="test-date-time" /></td>
</tr>
<tr>
<td>Pass
<input type="checkbox" name="initial-test-pas" id="initial-test-pas" /></td>
<td>Fail
<input type="checkbox" name="initial-test-fail" id="initial-test-fail" /></td>
<td colspan="2">Calib Expire Date
<input type="text" name="calib-expire-date" id="calib-expire-date" /></td>
<td>Guage Serial #
<input type="text" name="gague-serial-num" id="gague-serial-num" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2">Repair Test By
<input name="repair-test-by" type="text" id="repair-test-by" size="50" /></td>
<td colspan="2">Repair Date/Time
<input type="text" name="repair-date-time" id="repair-date-time" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2">Final Test by
<input name="final-test-by" type="text" id="final-test-by" size="50" /></td>
<td colspan="2">Certified Tester #
<input type="text" name="ft-certified-tester-num" id="ft-certified-tester-num" /></td>
<td>Test Date/Time
<input type="text" name="ft-date-time" id="ft-date-time" /></td>
</tr>
<tr>
<td>Pass
<input type="checkbox" name="ft-pass" id="ft-pass" /></td>
<td>Fail
<input type="checkbox" name="ft-fail" id="ft-fail" /></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="5">Comments
<textarea name="comments" id="comments" cols="80" rows="5"></textarea></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2">Video upload <input type="file" name="uploadvideo" /></td>
<td colspan="2">Image 1 <input type="file" name="uploadimage" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="2">Image 2 <input type="file" name="uploadimage2" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="2">Image 3 <input type="file" name="uploadimage3" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="2">Image 4 <input type="file" name="uploadimage4" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="2">Image 5 <input type="file" name="uploadimage5" /></td>
<td> </td>
</tr>
</table>
</form>
you can use jquery when to get the selected value like this
$("#dropdownid").change(function({ var vals = $(this).val(); })
then when you are redirecting to next page then add it as get parameter
(report.php)
if(isset($_REQUEST['submit'])){
$option = $_POST['items'];
mysql_query("SELECT * FROM `table_name` WHERE FIELD_NAME = '$options'");
}
if(isset($_REQUEST['submit'])){
$option = $_REQUEST['items'];
mysql_query("SELECT * FROM `table_name` WHERE FIELD_NAME = '$options'");
}
You can pass value to next page using php session.
$_SESSION ['name'] = $value;
and you can get value using php session from next page.
$value = $_SESSION ['name'];

storing multiple static data into database

I have a table with these columns (database)
like this http://netelity.com/table.JPG.
and i have a static form through which user define the installments. Static 24 input boxes are there like this
<form name="installment" method="post" action="" enctype="multipart/form-data" onsubmit="return validate()">
<table id="dt_hScroll" class="table table-striped">
<thead>
<tr>
<th>SL No.</th>
<th>Amount</th>
<th>Due Date</th>
</tr>
<tr>
<td> 1. </td>
<td>
<input type="text" name="installment1" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date1" class="tcal span4" value="<?php //echo date("Y-m-d"); ?>" />
</td>
</tr>
<tr>
<td> 2. </td>
<td>
<input type="text" name="installment2" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date2" class="tcal span4" />
</td>
</tr>
<tr>
<td> 3. </td>
<td>
<input type="text" name="installment3" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date3" class="tcal span4" />
</td>
</tr>
<tr>
<td> 4. </td>
<td>
<input type="text" name="installment4" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date4" class="tcal span4" />
</td>
</tr>
<tr>
<td> 5. </td>
<td>
<input type="text" name="installment5" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date5" class="tcal span4" />
</td>
</tr>
<tr>
<td> 6. </td>
<td>
<input type="text" name="installment6" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date6" class="tcal span4" />
</td>
</tr>
<tr>
<td> 7. </td>
<td>
<input type="text" name="installment7" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date7" class="tcal span4" />
</td>
</tr>
<tr>
<td> 8. </td>
<td>
<input type="text" name="installment8" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date8" class="tcal span4" />
</td>
</tr>
<tr>
<td> 9. </td>
<td>
<input type="text" name="installment9" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date9" class="tcal span4" />
</td>
</tr>
<tr>
<td> 10. </td>
<td>
<input type="text" name="installment10" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date10" class="tcal span4" />
</td>
</tr>
<tr>
<td> 11. </td>
<td>
<input type="text" name="installment11" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date11" class="tcal span4" />
</td>
</tr>
<tr>
<td> 12. </td>
<td>
<input type="text" name="installment12" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date12" class="tcal span4" />
</td>
</tr>
<tr>
<td> 13. </td>
<td>
<input type="text" name="installment13" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date13" class="tcal span4" />
</td>
</tr>
<tr>
<td> 14. </td>
<td>
<input type="text" name="installment14" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date14" class="tcal span4" />
</td>
</tr>
<tr>
<td> 15. </td>
<td>
<input type="text" name="installment15" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date15" class="tcal span4" />
</td>
</tr>
<tr>
<td> 16. </td>
<td>
<input type="text" name="installment16" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date16" class="tcal span4" />
</td>
</tr>
<tr>
<td> 17. </td>
<td>
<input type="text" name="installment17" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date10" class="tcal span4" />
</td>
</tr>
<tr>
<td> 18. </td>
<td>
<input type="text" name="installment18" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date18" class="tcal span4" />
</td>
</tr>
<tr>
<td> 19. </td>
<td>
<input type="text" name="installment19" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date19" class="tcal span4" />
</td>
</tr>
<tr>
<td> 20. </td>
<td>
<input type="text" name="installment20" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date20" class="tcal span4" />
</td>
</tr>
<tr>
<td> 21. </td>
<td>
<input type="text" name="installment21" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date21" class="tcal span4" />
</td>
</tr>
<tr>
<td> 22. </td>
<td>
<input type="text" name="installment22" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date22" class="tcal span4" />
</td>
</tr>
<tr>
<td> 23. </td>
<td>
<input type="text" name="installment23" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date23" class="tcal span4" />
</td>
</tr>
<tr>
<td> 24. </td>
<td>
<input type="text" name="installment24" id="installment" class="span4" value="0" />
</td>
<td>
<input type="text" name="due_date24" class="tcal span4" />
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" name="save" id="save" value="Save" class="btn btn-info span3" />
<input type="hidden" readonly="readonly" name="roll_no" value="<?php echo $roll_no; ?>" class="span5" />
</td>
<td></td>
</tr>
</thead>
</table>
</form>
Here i am not getting how to store it in that table. Actually all the 24 inputs are not mandatory. If user fills only 2 then also it should store it in the database table.
I tried to do like this
if(isset($_POST['save']))
{
$roll_no = $_POST['roll_no'];
$ins_amt1 = $_POST['installment1'];
$due_date1 = $_POST['due_date1'];
$ins_amt2 = $_POST['installment2'];
$due_date2 = $_POST['due_date2'];
$ins_amt3 = $_POST['installment3'];
$due_date3 = $_POST['due_date3'];
$ins_amt4 = $_POST['installment4'];
$due_date4 = $_POST['due_date4'];
$ins_amt5 = $_POST['installment5'];
$due_date5 = $_POST['due_date5'];
$ins_amt6 = $_POST['installment6'];
$due_date6 = $_POST['due_date6'];
$ins_amt7 = $_POST['installment7'];
$due_date7 = $_POST['due_date7'];
$ins_amt8 = $_POST['installment8'];
$due_date8 = $_POST['due_date8'];
$ins_amt9 = $_POST['installment9'];
$due_date9 = $_POST['due_date9'];
$ins_amt10 = $_POST['installment10'];
$due_date10 = $_POST['due_date10'];
$ins_amt11 = $_POST['installment11'];
$due_date11 = $_POST['due_date11'];
$ins_amt12 = $_POST['installment12'];
$due_date12 = $_POST['due_date12'];
$ins_amt13 = $_POST['installment13'];
$due_date13 = $_POST['due_date13'];
$ins_amt14 = $_POST['installment14'];
$due_date14 = $_POST['due_date14'];
$ins_amt15 = $_POST['installment15'];
$due_date15 = $_POST['due_date15'];
$ins_amt16 = $_POST['installment16'];
$due_date16 = $_POST['due_date16'];
$ins_amt17 = $_POST['installment17'];
$due_date17 = $_POST['due_date17'];
$ins_amt18 = $_POST['installment18'];
$due_date18 = $_POST['due_date18'];
$ins_amt19 = $_POST['installment19'];
$due_date19 = $_POST['due_date19'];
$ins_amt20 = $_POST['installment20'];
$due_date20 = $_POST['due_date20'];
$ins_amt21 = $_POST['installment21'];
$due_date21 = $_POST['due_date21'];
$ins_amt22 = $_POST['installment22'];
$due_date22 = $_POST['due_date22'];
$ins_amt23 = $_POST['installment23'];
$due_date23 = $_POST['due_date23'];
$ins_amt24 = $_POST['installment24'];
$due_date24 = $_POST['due_date24'];
$items = array();
$installment[] =array($ins_amt1, $ins_amt2, $ins_amt3, $ins_amt4, $ins_amt5, $ins_amt6, $ins_amt7, $ins_amt8, $ins_amt9, $ins_amt10, $ins_amt11, $ins_amt12, $ins_amt13, $ins_amt14, $ins_amt15, $ins_amt16, $ins_amt17, $ins_amt18, $ins_amt19, $ins_amt20, $ins_amt21, $ins_amt22, $ins_amt23, $ins_amt24);
//$in_values= serialize($installment);
$due_date[] = array($due_date1, $due_date2, $due_date3, $due_date4, $due_date5, $due_date6, $due_date7, $due_date8, $due_date9, $due_date10, $due_date11, $due_date12, $due_date13, $due_date14, $due_date15, $due_date16, $due_date17, $due_date18, $due_date19, $due_date20, $due_date21, $due_date22, $due_date23, $due_date24);
//$in_dates= serialize($due_date);
//$s1 = "insert into installment(id, fee_id, student_id, amount, due_date, paid_date, status, rec_no) values ('', ".$fee_id.", '".$roll_no."', ".$in_values.", '".$in_dates."', '', 'unpaid', ''";
foreach($installment as $row_key => $value)
{
$item = $value;
$uom = $due_date[$row_key];
$items[] = sprintf("(%d, %d, '%s', %d, '%s', '%s', '%s', '%s')", '',
$fee_id,
mysql_real_escape_string($roll_no),
intval($item),
$uom,
'',
'',
''
);
}
$msql = 'INSERT INTO installment (id, fee_id, student_id, amount, due_date, paid_date, status, rec_no) VALUES '.implode(', ', $items);
But it is taking only one data. Can somebody please suggest.
The data has to be saved like this:
Like This http://netelity.com/saveddata.JPG
A normal INSERT statement should look like:
INSERT INTO table_name (column1,column2,column3,...)
VALUES (value1,value2,value3,...);
So try changing
$msql = 'INSERT INTO installment (id, fee_id, student_id, amount, due_date, paid_date, status, rec_no) VALUES '.implode(', ', $items);
To:
$values = implode(', ', $items);
$msql = 'INSERT INTO installment (id, fee_id, student_id, amount, due_date, paid_date, status, rec_no) VALUES ('.$values.');
And don't forget to actually run the sql command. I don't see that in your script anywhere :)

image upload not processing

It is a regitration page in php where image is also uploading along with other user data but it is always showing error please help me to figure out the problem.It is always showing fail but i am using correct image. I also want to know how to set default value for profile image in phpmyadmin and how to query to update it when user enter his choice along with other user data that is to be inserted into database with insert query. and how to do insertion and updation at same time i.e inserting user data and updating default image.
<?php
include_once 'conn.inc';
if(isset($_POST["btnsave"])) {
$filename=$_FILES['file']['name'];
$size=$_FILES['file']['name'];
$extenstion=pathinfo($filename,PATHINFO_EXTENSION);
if($extenstion=='jpeg' || $extenstion=='png' || $extenstion=='jpg' && $size<=30000) {
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
}
else {
echo "failhhhhhhhhhh";
}
$name=mysql_real_escape_string($_POST["txtname"]);
$fname=mysql_real_escape_string($_POST["txtfname"]);
$gender=mysql_real_escape_string($_POST["gender"]);
$image=$_FILES['file']['name'];
$des=mysql_real_escape_string($_POST["des"]);
$job=mysql_real_escape_string($_POST["txtjob"]);
$country=mysql_real_escape_string($_POST["txtcountry"]);
$state=mysql_real_escape_string($_POST["txtstate"]);
$city=mysql_real_escape_string($_POST["txtcity"]);
$contact=mysql_real_escape_string($_POST["txtcontact"]);
$contactst=mysql_real_escape_string($_POST["contactst"]);
$email=mysql_real_escape_string($_POST["txtemail"]);
$emailst=mysql_real_escape_string($_POST["emailst"]);
$query="insert into tblregistration values
('','$name','$fname','$gender','$image','$des','$job','$country','$state','$city','$contact','$contactst','$email','$emailst')" or die('neverve'.mysql_error());
$res=mysql_query($query) or die('error 1'.mysql_error());
if(mysql_affected_rows())
{
echo "success";
}
else {
echo "failure";
}
}
?>
html form
<form method="post" action="registration.php" enctype="multipart/form-data">
<table>
<tr>
<td><label for="txtname">Name</label></td>
<td><input type="text" name="txtname" value="Enter your name"/></td>
</tr>
<tr>
<td><label for="txtfname">Father Name</label></td>
<td><input type="text" name="txtfname" value="Enter your father's name"/></td>
</tr>
<tr>
<td><label>Gender</label></td>
<td>Male<input type="radio" name="gender" checked="checked" value="m" />
Female<input type="radio" name="gender" value="f" />
</td>
</tr>
<tr>
<td>
<input onchange="readURL(this);" type="file" name="file" /></td>
<td><img alt="Image Display Here" id="test" src="./upload/icon3.jpg" height="100px" width="100px" /></td>
</tr>
<tr>
<td><label>Designation</label></td>
<td><select name="des">
<option value="-1">Select Designation</option>
<option value="Employed">Employed</option>
<option value="selfemployed">Self-Employed</option>
<option value="retired">Retired</option>
</select></td>
</tr>
<tr>
<td>
<label>Title of Job</label></td>
<td><input type="text" name="txtjob" value="title of job" /></td>
</tr>
<tr>
<td>
<label>Country</label></td>
<td><input type="text" name="txtcountry" value="Enter your country" /></td>
</tr>
<tr>
<td>
<label>State</label></td>
<td><input type="text" name="txtstate" value="Enter your State" /></td>
</tr>
<tr>
<td>
<label>City</label></td>
<td><input type="text" name="txtcity" value="Enter your city" /></td>
</tr>
<tr>
<td>
<label>Contact no</label></td>
<td><input type="tel" name="txtcontact" value="Enter your contact no" />
Private<input type="radio" name="contactst" value="0" /> Public<input type="radio" name="contactst" checked="checked" value="1"/>
</td>
</tr>
<tr>
<td>
<label>Email</label></td>
<td><input type="email" name="txtemail" value="Enter your email" />
Private<input type="radio" name="emailst" value="0" /> Public<input type="radio" name="emailst" checked="checked" value="1" />
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="btnsave" value="submit" /></td>
</tr>
</table>
</form>
$size=$_FILES['file']['name']; please check this condition
Replace
$size=$_FILES['file']['name'];
with
$size=$_FILES['file']['size'];

How to use associate arrays to get the id from the checkbox and appropreate value from the text field

Hi everyone, i'm new to programming. I need to develop a rating system with check boxes and text-fields where user clicks the subjects from the list and add his rating/experience in the text field. All these subjects and ratings are added to the database with the subject id and the rating. So the issue is, I don't know how to write the associate array to get the selected subjects and their appropriate rating to insert into the database. Can anyone please provide me some codes or samples similar to this. So, I can get some idea how to do this. Thanks in advance :)
This is the HTML sample code
<form action="" method="post">
<table width="372" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="24"><input type="checkbox" name="subid1" value="1" id="subid1"></td>
<td width="203">Maths</td>`enter code here`
<td width="145"><input type="text" name="sub1" id="sub1"></td>
</tr>
<tr>
<td><input type="checkbox" name="subid2" value="2" id="subid2" /></td>
<td>Physics</td>
<td><input type="text" name="subid2" id="subid2" /></td>
</tr>
<tr>
<td><input type="checkbox" name="subid3" value="3" id="subid3" /></td>
<td>Computing</td>
<td><input type="text" name="subid3" id="subid3" /></td>
</tr>
<tr>
<td><input type="checkbox" name="subid4" value="4" id="subid4" /></td>
<td>Chemistry</td>
<td><input type="text" name="subid4" id="subid4" /></td>
</tr>
<tr>
<td><input type="checkbox" name="subid5" value="5" id="subid5" /></td>
<td>Biology</td>
<td><input type="text" name="subid5" id="subid5" /></td>
</tr>
<tr>
<td><input type="checkbox" name="subid7" value="6" id="subid7" /></td>
<td>Human Biology</td>
<td><input type="text" name="subid6" id="subid6" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="button" id="button" value="Submit" /></td>
<td> </td>
</tr>
</table>
</form>
This will do the job on client side:
<input type="checkbox" name="cb[myID1]" value="1" />
<input type="text" name="t[myID1]" value="" />
<input type="checkbox" name="cb[myID2]" value="1" />
<input type="text" name="t[myID2]" value="" />
and this can be used on server side:
$usedTexts = array();
if ( array_key_exists("t", $_POST) && is_array($_POST["t"])
&& array_key_exists("cb", $_POST) && is_array($_POST["cb"])
)
{
$usedTexts = array_intersect_key($_POST["t"], $_POST["cb"]);
}
see manual for server side: http://us3.php.net/array_intersect_key
edit: fixed to POST; added array_key_exists() and is_array()

Saving a form with text and checboxes to text file

I an working on a HTML form to help me keep track on information when I play roll playing games.
The form has a grid of checkboxes that are used to track health. I also have a text box that I track other stats in.
I want to have a 2 buttons: LOAD and SAVE.
When save is hit the current status (whether or not a box is marked), if every form element is saved to a text file Save/save.txt. Any information in a existing text file should be replaced. I only care about the current settings.
when load is hit the data is loaded from the text file and the form is filled out like it was when it was saved.
How do I get this form to save / load?
<form action="HP_Tracker.php" method="post">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><center><b>W</b></center></td>
<td> </td>
</tr>
<tr>
<td bgcolor="ffffff"><input name="W1" type="checkbox" value="" /></td>
<td bgcolor="000000"><input name="S24" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="ffffff"><input name="W2" type="checkbox" value="" /></td>
<td bgcolor="000000"><input name="S23" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="F0F0F5"><input name="W3" type="checkbox" value="" /></td>
<td bgcolor="0A0A0F"><input name="S22" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="E0E0EB"><input name="W4" type="checkbox" value="" /></td>
<td bgcolor="14141F"><input name="S21" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="D1D1E0"><input name="W5" type="checkbox" value="" /></td>
<td bgcolor="1F1F2E"><input name="S20" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="C2C2D6"><input name="W6" type="checkbox" value="" /></td>
<td bgcolor="29293D"><input name="S19" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="B2B2CC"><input name="W7" type="checkbox" value="" /></td>
<td bgcolor="33334C"><input name="S18" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="A3A3C2"><input name="W8" type="checkbox" value="" /></td>
<td bgcolor="3D3D5C"><input name="S17" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="9494B8"><input name="W9" type="checkbox" value="" /></td>
<td bgcolor="47476B"><input name="S16" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="8585AD"><input name="W10" type="checkbox" value="" /></td>
<td bgcolor="52527A"><input name="S15" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="7575A3"><input name="W11" type="checkbox" value="" /></td>
<td bgcolor="5C5C8A"><input name="S14" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="666699"><input name="W12" type="checkbox" value="" /></td>
<td bgcolor="666699"><input name="S13" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="5C5C8A"><input name="W13" type="checkbox" value="" /></td>
<td bgcolor="7575A3"><input name="S12" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="52527A"><input name="W14" type="checkbox" value="" /></td>
<td bgcolor="8585AD"><input name="S11" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="47476B"><input name="W15" type="checkbox" value="" /></td>
<td bgcolor="9494B8"><input name="S10" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="3D3D5C"><input name="W16" type="checkbox" value="" /></td>
<td bgcolor="A3A3C2"><input name="S9" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="33334C"><input name="W17" type="checkbox" value="" /></td>
<td bgcolor="B2B2CC"><input name="S8" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="29293D"><input name="W18" type="checkbox" value="" /></td>
<td bgcolor="C2C2D6"><input name="S7" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="1F1F2E"><input name="W19" type="checkbox" value="" /></td>
<td bgcolor="D1D1E0"><input name="S6" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="14141F"><input name="W20" type="checkbox" value="" /></td>
<td bgcolor="E0E0EB"><input name="S5" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="0A0A0F"><input name="W21" type="checkbox" value="" /></td>
<td bgcolor="F0F0F5"><input name="S4" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="000000"><input name="W22" type="checkbox" value="" /></td>
<td bgcolor="FFFFFF"><input name="S3" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="000000"><input name="W23" type="checkbox" value="" /></td>
<td bgcolor="FFFFFF"><input name="S2" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="000000"><input name="W24" type="checkbox" value="" /></td>
<td bgcolor="FFFFFF"><input name="S1" type="checkbox" value="" /></td>
</tr>
<tr>
<td> </td>
<td><center><b>S</b></center></td>
</tr>
</table>
<hr />
Initiative<br />
<input name="Initiative" type="text" size="4" />
<br /><br />
<input name="Save" type="submit" value="SAVE" />
</form>
Try that:
<?php
if (!empty($_POST)) {
$data = implode(',', $_POST);
$fileName = 'yourFile.txt';
$file = fopen($fileName, 'a+');
fwrite($file, $data);
fclose($file);
chmod(0777);
}

Categories