how to update multiple checkbox - php

I want to update the subject and other fields by adding multiple subjects, but the issue is it only saves one of subject which I have checked.
How can I solve this issue ?
Below is my code :
<?php
$status = "";
if(isset($_POST['new']) && $_POST['new']==1)
{
$host="localhost";//host name
$username="root"; //database username
$word="";//database word
$db_name="tuichk";//database name
$tbl_name="data"; //table name
$con=mysqli_connect("$host", "$username", "$word","$db_name")or die("cannot connect");//connection string
$id=$_REQUEST['id'];
$name =$_REQUEST['name'];
$stu_ic = $_REQUEST['stu_ic'];
$address = $_REQUEST['address'];
$contact = $_REQUEST['contact'];
$checkbox1=$_REQUEST['subject'];
$chk="";
$update="update data set name='".$name."', stu_ic='".$stu_ic."', address='".$address."', contact='".$contact."', sub='".$checkbox1."' where id='".$id."'";
mysql_query($update) or die(mysql_error());
$status = "Record Updated Successfully. </br></br><a href='view.php'>View Updated Record</a>";
echo '<p style="color:#FF0000;">'.$status.'</p>';
}else {
?>
this is my html form
<form name="form" method="post" action="">
<input type="hidden" name="new" value="1" />
<input name="id" type="hidden" value="<?php echo $row['id'];?>" />
<p><input type="text" name="name" placeholder="Enter Name" required value="<?php echo $row['name'];?>" /><input type="text" name="stu_ic" placeholder="Enter Student IC" required value="<?php echo $row['stu_ic'];?>" /></p>
<p><input type="text" name="address" placeholder="Enter Address" required value="<?php echo $row['address'];?>" /><input type="text" name="contact" placeholder="Enter Contact" required value="<?php echo $row['contact'];?>" /></p>
<div style="text-align:center">
<div style="width:400px;border-radius:6px;margin:0px auto">
<table border="1">
<tr>
<td colspan="2">Select Subject:</td>
</tr>
<tr>
<td>Bahasa Melayu</td>
<td><input type="checkbox" name="subject" value="Bahasa Melayu"></td>
</tr>
<tr>
<td>English</td>
<td><input type="checkbox" name="subject" value="English"></td>
</tr>
<tr>
<td>Mathematics</td>
<td><input type="checkbox" name="subject" value="Mathematics"></td>
</tr>
<tr>
<td>Science</td>
<td><input type="checkbox" name="subject" value="Science"></td>
</tr>
<tr>
<td>Sejarah</td>
<td><input type="checkbox" name="subject" value="Sejarah"></td>
</tr>
<tr>
<td>Geography</td>
<td><input type="checkbox" name="subject" value="Geography"></td>
</tr>
<tr>
<td>Additional Mathematics</td>
<td><input type="checkbox" name="subject" value="Additional Mathematics"></td>
</tr>
<tr>
<td>Chemistry</td>
<td><input type="checkbox" name="subject" value="Chemistry"></td>
</tr>
<tr>
<td>Physics</td>
<td><input type="checkbox" name="subject" value="Physics"></td>
</tr>
<tr>
<td>Biology</td>
<td><input type="checkbox" name="subject" value="Biology"></td>
</tr><tr>
<td>Principle Of Accounting</td>
<td><input type="checkbox" name="subject" value="Principle Of Accounting"></td>
</tr><tr>
<td>Ekonomi Asas</td>
<td><input type="checkbox" name="subject" value="Ekonomi Asas"></td>
</tr><tr>
<td>Perdagangan</td>
<td><input type="checkbox" name="subject" value="Perdagangan"></td>
</tr>
</table>
</div>
</form>

HTML input should be
<input type="checkbox" name="subject[]" value="Subject1">
<input type="checkbox" name="subject[]" value="Subject2">
In PHP have many options.
Option 1:
save subjects as string
$subjects = implode(',', $_POST['subject']);
retrieve as string and convert to array
$subjects = explode(',', $field);
Option 2: can save as JSON and retrieve as JSON and decode it.

this is my code inc html form:
<?php
$status = "";
if(isset($_POST['new']) && $_POST['new']==1)
{
$host="localhost";//host name
$username="root"; //database username
$word="";//database word
$db_name="tuichk";//database name
$tbl_name="data"; //table name
$con=mysqli_connect("$host", "$username", "$word","$db_name")or die("cannot connect");//connection string
$id=$_REQUEST['id'];
$name =$_REQUEST['name'];
$stu_ic = $_REQUEST['stu_ic'];
$address = $_REQUEST['address'];
$contact = $_REQUEST['contact'];
$checkbox1=$_REQUEST['subject'];
$subjects = implode(',', $_POST['subject']);
$subjects = explode(',', $field);
$chk="";
$update="update data set name='".$name."', stu_ic='".$stu_ic."', address='".$address."', contact='".$contact."', sub='".$checkbox1."' where id='".$id."'";
mysql_query($update) or die(mysql_error());
$status = "Record Updated Successfully. </br></br><a href='view.php'>View Updated Record</a>";
echo '<p style="color:#FF0000;">'.$status.'</p>';
}else {
?>
<div>
<form name="form" method="post" action="">
<input type="hidden" name="new" value="1" />
<input name="id" type="hidden" value="<?php echo $row['id'];?>" />
<p><input type="text" name="name" placeholder="Enter Name" required value="<?php echo $row['name'];?>" /><input type="text" name="stu_ic" placeholder="Enter Student IC" required value="<?php echo $row['stu_ic'];?>" /></p>
<p><input type="text" name="address" placeholder="Enter Address" required value="<?php echo $row['address'];?>" /><input type="text" name="contact" placeholder="Enter Contact" required value="<?php echo $row['contact'];?>" /></p>
<div style="text-align:center">
<div style="width:400px;border-radius:6px;margin:0px auto">
<table border="1">
<tr>
<td colspan="2">Select Subject:</td>
</tr>
<tr>
<td>Bahasa Melayu</td>
<td><input type="checkbox" name="subject[]" value="Bahasa Melayu"></td>
</tr>
<tr>
<td>English</td>
<td><input type="checkbox" name="subject[]" value="English"></td>
</tr>
<tr>
<td>Mathematics</td>
<td><input type="checkbox" name="subject[]" value="Mathematics"></td>
</tr>
<tr>
<td>Science</td>
<td><input type="checkbox" name="subject[]" value="Science"></td>
</tr>
<tr>
<td>Sejarah</td>
<td><input type="checkbox" name="subject[]" value="Sejarah"></td>
</tr>
<tr>
<td>Geography</td>
<td><input type="checkbox" name="subject[]" value="Geography"></td>
</tr>
<tr>
<td>Additional Mathematics</td>
<td><input type="checkbox" name="subject[]" value="Additional Mathematics"></td>
</tr>
<tr>
<td>Chemistry</td>
<td><input type="checkbox" name="subject[]" value="Chemistry"></td>
</tr>
<tr>
<td>Physics</td>
<td><input type="checkbox" name="subject[]" value="Physics"></td>
</tr>
<tr>
<td>Biology</td>
<td><input type="checkbox" name="subject[]" value="Biology"></td>
</tr><tr>
<td>Principle Of Accounting</td>
<td><input type="checkbox" name="subject[]" value="Principle Of Accounting"></td>
</tr><tr>
<td>Ekonomi Asas</td>
<td><input type="checkbox" name="subject[]" value="Ekonomi Asas"></td>
</tr><tr>
<td>Perdagangan</td>
<td><input type="checkbox" name="subject[]" value="Perdagangan"></td>
</tr>
</table>
</div>
</form>
<p><input name="submit" type="submit" value="Update" /></p>
</form>
<?php } ?>

Related

Error To Database when Leave uncheck [duplicate]

This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Closed 5 years ago.
this is the output
<?php
include_once('connection.php');
$StdID = $_REQUEST['txtID'];
$StdImage = $_REQUEST['txtImage'];
$FullName = $_REQUEST['txtFullname'];
$Address = $_REQUEST['txtAdd'];
$Bday = $_REQUEST['txtBday'];
$Grade = $_REQUEST['txtGrade'];
$Height = $_REQUEST['txtHeight'];
$Weight = $_REQUEST['txtWeight'];
$BloodPressure = $_REQUEST['txtBlood'];
$Gname = $_REQUEST['txtGname'];
$Contact = $_REQUEST['txtContact'];
$BCG = $_REQUEST['chkBCG'];
$Cardiac = $_REQUEST['chkCardiac'];
$Asthma1 = $_REQUEST['chkAsthma1'];
$Alcohol = $_REQUEST['chkAlcohol'];
$OPV1 = $_REQUEST['chkOpv1'];
$Thyroid = $_REQUEST['chkThyroid'];
$Chicken = $_REQUEST['chkChicken'];
$Tobacco = $_REQUEST['chkYosi'];
$OPV2 = $_REQUEST['chkOPV2'];
$Diabetes = $_REQUEST['chkDiabetes'];
$Measles = $_REQUEST['chkMeasles1'];
$Opv3 = $_REQUEST['chkOpv3'];
$Hypertension = $_REQUEST['chkHypertension'];
$Mumps = $_REQUEST['chkMumps1'];
$Food1 = $_REQUEST['txtFood1'];
$DPT1 = $_REQUEST['chkDpt1'];
$Tuberculosis = $_REQUEST['chkTuber'];
$Ulcer = $_REQUEST['chkUlcer'];
$Food2 = $_REQUEST['txtFood2'];
$DPT2 = $_REQUEST['chkdpt2'];
$Asthma2 = $_REQUEST['chkAsthma2'];
$Dengue = $_REQUEST['chkdengue'];
$Food3 = $_REQUEST['txtfood3'];
$Dpt3 = $_REQUEST['chkDpt3'];
$Kidney = $_REQUEST['chkKidney'];
$Head = $_REQUEST['chkHead'];
$Measles2 = $_REQUEST['chkMeasles2'];
$Cancer = $_REQUEST['chkCancer'];
$Std = $_REQUEST['chkstd'];
$Scar = $_REQUEST['chkScar'];
$Hepa = $_REQUEST['chkHepa'];
$Hypertension2 = $_REQUEST['chkHypertension2'];
$Mole = $_REQUEST['chkMole'];
$Std2 = $_REQUEST['chkStd2'];
$Kidney2 = $_REQUEST['chkKidney2'];
$Tattoo = $_REQUEST['chkTattoo'];
$OthersImmu = $_REQUEST['txtothersimmu'];
$Birthmark = $_REQUEST['txtBirthmark'];
$OthersImmu2 = $_REQUEST['txtothersimmu2'];
$OthersIll = $_REQUEST['txtothersill'];
$OthersImmu3 = $_REQUEST['txtothersimmu3'];
$OthersIll2 = $_REQUEST['txtothersill2'];
$Mens = $_REQUEST['txtmens'];
$sql = "INSERT INTO tbl_medics VALUES ('$StdID', '$StdImage', '$FullName', '$Address', '$Bday', '$Grade', '$Height', '$Weight', '$BloodPressure', '$Gname','$Contact', '$BCG', '$Cardiac', '$Asthma1', '$Alcohol', '$OPV1', '$Thyroid', '$Chicken','$Tobacco', '$OPV2', '$Diabetes', 'Measles', '$Opv3', '$Hypertension', '$Mumps', '$Food1', '$DPT1', '$Tuberculosis', '$Ulcer', '$Food2', '$DPT2', '$Asthma2', '$Dengue', '$Food3', '$Dpt3', '$Kidney', '$Head', '$Measles2', '$Cancer', '$Std', '$Scar', '$Hepa', '$Hypertension2', '$Mole', '$Std2', '$Kidney2', '$Tattoo', '$OthersImmu', '$Birthmark', '$OthersImmu2', '$OthersIll', '$OthersImmu3', '$OthersIll2', '$Mens')";
if ($conn->query($sql) === TRUE) {
header("Location: MedicRecords.php?SuccessfullyAdded");
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
This is my Input
<form action="AddMedicRecords.php" method="POST" enctype="multipart/form-data" style="border:1px solid #ccc">
<?php $id = $_GET['id'];
$sql = "SELECT * FROM tblstdpro where StdID = '$id'";
$result = mysqli_query($conn,$sql);
$count = 0;
while($row = mysqli_fetch_array($result)){
?>
<div class="box-body">
<div class="form-group">
<label><b>Student Image Location</b></label>
<input type="text" class="form-control" value="<?php echo $row['StdImage'];?>" name="txtImage" type="readonly" readonly></br>
<label><b>LRN</b></label>
<input type="text" class="form-control" value="<?php echo $row['StdID'];?>" name="txtID" required></br>
<label><b>Full Name</b></label>
<input type="text" class="form-control" value="<?php echo $row['Lname'];?>, <?php echo $row['Fname'];?> <?php echo $row['Mname'];?>" name="txtfullname" required></br>
<label><b>Address</b></label></br>
<input type="text" class="form-control" value="<?php echo $row['Street']; ?> , <?php echo $row['Barangay']; ?> <?php echo $row['Munic']; ?>, <?php echo $row['Province']; ?>" name="txtadd" required></br>
<label><b>Birthday</b></label>
<input type="text" class="form-control" value="<?php echo $row['Bday'];?>" name="txtbday" required></br>
<label><b>Grade/ Course</b></label></br>
<input type="text" class="form-control" value="<?php echo $row['Track'];?> - <?php echo $row['YearLvl'];?>" name="txtgrade" required></br>
<label><b>Height</b></label>
<input type="" class="form-control" placeholder="Enter Height" name="txtheight" required></br>
<label><b>Weight</b></label>
<input type="" class="form-control" placeholder="Enter Weight" name="txtweight" required></br>
<label><b>Blood Pressure</b></label>
<input type="" class="form-control" placeholder="Enter BP" name="txtblood" required></br>
</br>
<label><b><h3>*Person to be Notified in Case of Emergency</h3></b></label>
</br>
<label><b>Name:</b></label>
<input type="text" class="form-control" value="<?php echo $row['Mother'];?>" name="txtGname" required></br>
<label><b>Contact No.</b></label>
<input type="text" class="form-control" class="form-control" value="<?php echo $row['Contact'];?>" name="txtContact"></br>
<label><h3>*Kindly Check the Box Provided on the Left Side</h3></label>
<table class="table table-hover">
<thead>
<tr>
<th>IMMUNIZATION</th>
<th>FAMILY HISTORY</th>
<th>PREVIOUS ILLNESS</th>
<th>PERSONAL HISTORY</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox" name="chkBCG" value="BCG"> BCG</td>
<td><input type="checkbox" name="chkCardiac" value="Cardiac Disease"> Cardiac Disease</td>
<td><input type="checkbox" name="chkAsthma1" value="Asthma"> Asthma</td>
<td><input type="checkbox" name="" value="chkAlcohol"> Alcohol Use</td>
</tr>
<tr>
<td><input type="checkbox" name="chkOpv1" value="OPV 1"> OPV 1</td>
<td><input type="checkbox" name="chkThyroid" value="Thyroid Disease"> Thyroid Disease</td>
<td><input type="checkbox" name="chkChicken" value="Chicken Pox"> Chicken Pox</td>
<td><input type="checkbox" name="chkYosi" value="Tobacco Use"> Tobacco Use</td>
</tr>
<tr>
<td><input type="checkbox" name="chkOpv2" value="OPV 2"> OPV 2</td>
<td><input type="checkbox" name="chkDiabetes" value="Diabetes Mellitus"> Diabetes Mellitus</td>
<td><input type="checkbox" name="chkMeasles1" value="Measles"> Measles</td>
<td>Allergy to Food, Drugs,Etc..</td>
</tr>
<tr>
<td><input type="checkbox" name="chkOpv3" value="OPV 3"> OPV 3</td>
<td><input type="checkbox" name="chkHypertension" value="Hypertension"> Hypertension</td>
<td><input type="checkbox" name="chkMumps" value="Mumps"> Mumps</td>
<td><input type="text" class="form-control" class="form-control" placeholder="Enter Allergy to Food, Drugs,Etc.." name="txtFood1"> </td>
</tr>
<td><input type="checkbox" name="ChkDpt1" value="DPT1"> DPT 1</td>
<td><input type="checkbox" name="chkTuber" value="Tuberculosis"> Tuberculosis</td>
<td><input type="checkbox" name="chkUlcer" value="Peptic Ulcer"> Peptic Ulcer</td>
<td><input type="text" class="form-control" class="form-control" placeholder="Enter Allergy to Food, Drugs,Etc.." name="txtFood2"> </td>
</tr>
<td><input type="checkbox" name="chkDpt2" value="DPT 2"> DPT 2</td>
<td><input type="checkbox" name="chkAstma2" value="Asthma"> Asthma</td>
<td><input type="checkbox" name="chkDengue" value="Dengue"> Dengue</td>
<td><input type="text" class="form-control" class="form-control" placeholder="Enter Allergy to Food, Drugs,Etc.." name="txtFood3"> </td>
</tr>
<tr>
<td><input type="checkbox" name="chkDpt3" value="DPT 3"> DPT 3</td>
<td><input type="checkbox" name="chkKidney" value="Kidney Disease"> Kidney Disease</td>
<td><input type="checkbox" name="chkHead" value="Head Injury"> Head Injury</td>
<td>Any Identification Mark:</td>
</tr>
<tr>
<td><input type="checkbox" name="chkMeasles2" value="Measles"> Measles</td>
<td><input type="checkbox" name="chkCancer" value="Cancer"> Cancer</td>
<td><input type="checkbox" name="chkStd" value="STD"> STD</td>
<td><input type="checkbox" name="chkScar" value="Scar"> 1. Scar</td>
</tr>
<tr>
<td><input type="checkbox" name="chkHepa" value="HEPA-B"> HEPA-B</td>
<td><input type="checkbox" name="chkSkin" value="Skin Disease"> Skin Disease</td>
<td><input type="checkbox" name="chkHypertension2" value="Hypertension"> Hypertension</td>
<td><input type="checkbox" name="chkMole" value="Mole"> 2. Mole</td>
</tr>
<tr>
<td>Others:</td>
<td><input type="checkbox" name="chkStd2" value="STD"> STD</td>
<td><input type="checkbox" name="chkKidney2" value="Kidney Problem"> Kidney Problem</td>
<td><input type="checkbox" name="chkTattoo" value="Tattoo"> 3. Tattoo</td>
</tr>
<tr>
<td><input type="text" class="form-control" class="form-control" placeholder="Enter Others" name="txtOthersImmu"> </td>
<td></td>
<td>Others:</td>
<td><input type="checkbox" name="txtBirthmark" value="Birthmark"> 4. Birthmark</td>
</tr>
<tr>
<td><input type="text" class="form-control" class="form-control" placeholder="Enter Others" name="txtOthersImmu2"> </td>
<td></td>
<td><input type="text" class="form-control" class="form-control" placeholder="Enter Others" name="txtOthersIll"> </td>
<td></td>
</tr>
<tr>
<td><input type="text" class="form-control" class="form-control" placeholder="Enter Others" name="txtOthersImmu3"> </td>
<td></td>
<td><input type="text" class="form-control" class="form-control" placeholder="Enter Others" name="txtOthersIll2"> </td>
<td></td>
</tr>
</tbody>
</table>
<label><b>FOR FEMALE ONLY: Date of Last Menstrual Period:</b></label>
<div class="form-group">
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input type="date" placeholder="Enter Birthday" class="form-control" data-inputmask="'alias': 'mm/dd/yyyy'" data-mask name="txtMens" >
</div>
<!-- /.input group -->
</div>
<!-- /.form group -->
<div class="clearfix">
<button type="submit" name="submit" class="btn btn-block btn-primary btn-lg">Add Student</button>
<button type="button" class="btn btn-block btn-danger btn-lg">Cancel</button>
</form></br></br>
</div>
</form>
<?php
}
?>
Errors Says this
Notice: Undefined index: txtFullname in C:\wamp64\www\TestingThesis\AddMedicRecords.php on line 9
Error: INSERT INTO tbl_medics VALUES ('014-321', 'StdImage/014-321.jpg', '', '', '', '', '', '', '', 'Mommy','097576346', 'BCG', '', '', '', '', '', '','', '', '', 'Measles', '', '', '', '', '', '', '', '', '', '', '', '', '', 'Kidney Disease', '', '', '', '', '', '', '', 'Mole', '', '', '', '', '', '', '', '', '', '')
Data truncated for column 'StdID' at row 1
How can this be done when there are so many uncheck it errors bet when i check it all it goes in, how can i put a default value if it is uncheck?
The major issue is, when you are dealing with a checkbox, then you have to check whether it is checked or not like:
$value = ''; // Default value
if( isset($_REQUEST['checkbox_name']) )
{
$value = $_REQUEST['checkbox_name'];
}
apart form that, your code is open to SQL Injections. And you are inserting data into table without providing column names. Any changes to the table will break the whole thing.
Input name is wrong, change it to txtFullname instead of txtfullname.
<label><b>Full Name</b></label> <input type="text" class="form-control" value="<?php echo $row['Lname'];?>, <?php echo $row['Fname'];?> <?php echo $row['Mname'];?>" name="txtFullname" required>
Also i fixed all you invalid html tags:
<?php
$id = $_GET['id'];
$sql = "SELECT * FROM tblstdpro where StdID = '$id'";
$result = mysqli_query($conn,$sql); $count = 0;
while($row = mysqli_fetch_array($result)){ ?>
<form action="AddMedicRecords.php" method="POST" enctype="multipart/form-data" style="border:1px solid #ccc">
<div class="box-body">
<div class="form-group"> <label><b>Student Image Location</b></label> <input type="text" class="form-control" value="<?php echo $row['StdImage'];?>" name="txtImage" readonly><br>
<label><b>LRN</b></label> <input type="text" class="form-control" value="<?php echo $row['StdID'];?>" name="txtID" required><br>
<label><b>Full Name</b></label> <input type="text" class="form-control" value="<?php echo $row['Lname'];?>, <?php echo $row['Fname'];?> <?php echo $row['Mname'];?>" name="txtFullname" required><br>
<label><b>Address</b></label><br> <input type="text" class="form-control" value="<?php echo $row['Street']; ?> , <?php echo $row['Barangay']; ?> <?php echo $row['Munic']; ?>, <?php echo $row['Province']; ?>" name="txtadd" required><br>
<label><b>Birthday</b></label> <input type="text" class="form-control" value="<?php echo $row['Bday'];?>" name="txtbday" required><br>
<label><b>Grade/ Course</b></label><br> <input type="text" class="form-control" value="<?php echo $row['Track'];?> - <?php echo $row['YearLvl'];?>" name="txtgrade" required><br>
<label><b>Height</b></label> <input type="" class="form-control" placeholder="Enter Height" name="txtheight" required><br>
<label><b>Weight</b></label> <input type="" class="form-control" placeholder="Enter Weight" name="txtweight" required><br>
<label><b>Blood Pressure</b></label> <input type="" class="form-control" placeholder="Enter BP" name="txtblood" required><br> <br>
<label><h3>*Person to be Notified in Case of Emergency</h3></label> <br>
<label><b>Name:</b></label> <input type="text" class="form-control" value="<?php echo $row['Mother'];?>" name="txtGname" required><br>
<label><b>Contact No.</b></label> <input type="text" class="form-control" value="<?php echo $row['Contact'];?>" name="txtContact"><br>
<label><h3>*Kindly Check the Box Provided on the Left Side</h3></label>
<table class="table table-hover">
<thead>
<tr>
<th>IMMUNIZATION</th>
<th>FAMILY HISTORY</th>
<th>PREVIOUS ILLNESS</th>
<th>PERSONAL HISTORY</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox" name="chkBCG" value="BCG"> BCG</td>
<td><input type="checkbox" name="chkCardiac" value="Cardiac Disease"> Cardiac Disease</td>
<td><input type="checkbox" name="chkAsthma1" value="Asthma"> Asthma</td>
<td><input type="checkbox" name="" value="chkAlcohol"> Alcohol Use</td>
</tr>
<tr>
<td><input type="checkbox" name="chkOpv1" value="OPV 1"> OPV 1</td>
<td><input type="checkbox" name="chkThyroid" value="Thyroid Disease"> Thyroid Disease</td>
<td><input type="checkbox" name="chkChicken" value="Chicken Pox"> Chicken Pox</td>
<td><input type="checkbox" name="chkYosi" value="Tobacco Use"> Tobacco Use</td>
</tr>
<tr>
<td><input type="checkbox" name="chkOpv2" value="OPV 2"> OPV 2</td>
<td><input type="checkbox" name="chkDiabetes" value="Diabetes Mellitus"> Diabetes Mellitus</td>
<td><input type="checkbox" name="chkMeasles1" value="Measles"> Measles</td>
<td>Allergy to Food, Drugs,Etc..</td>
</tr>
<tr>
<td><input type="checkbox" name="chkOpv3" value="OPV 3"> OPV 3</td>
<td><input type="checkbox" name="chkHypertension" value="Hypertension"> Hypertension</td>
<td><input type="checkbox" name="chkMumps" value="Mumps"> Mumps</td>
<td><input type="text" class="form-control" placeholder="Enter Allergy to Food, Drugs,Etc.." name="txtFood1"> </td>
</tr>
<td><input type="checkbox" name="ChkDpt1" value="DPT1"> DPT 1</td>
<td><input type="checkbox" name="chkTuber" value="Tuberculosis"> Tuberculosis</td>
<td><input type="checkbox" name="chkUlcer" value="Peptic Ulcer"> Peptic Ulcer</td>
<td><input type="text" class="form-control" placeholder="Enter Allergy to Food, Drugs,Etc.." name="txtFood2"> </td>
</tr>
<td><input type="checkbox" name="chkDpt2" value="DPT 2"> DPT 2</td>
<td><input type="checkbox" name="chkAstma2" value="Asthma"> Asthma</td>
<td><input type="checkbox" name="chkDengue" value="Dengue"> Dengue</td>
<td><input type="text" class="form-control" placeholder="Enter Allergy to Food, Drugs,Etc.." name="txtFood3"> </td>
</tr>
<tr>
<td><input type="checkbox" name="chkDpt3" value="DPT 3"> DPT 3</td>
<td><input type="checkbox" name="chkKidney" value="Kidney Disease"> Kidney Disease</td>
<td><input type="checkbox" name="chkHead" value="Head Injury"> Head Injury</td>
<td>Any Identification Mark:</td>
</tr>
<tr>
<td><input type="checkbox" name="chkMeasles2" value="Measles"> Measles</td>
<td><input type="checkbox" name="chkCancer" value="Cancer"> Cancer</td>
<td><input type="checkbox" name="chkStd" value="STD"> STD</td>
<td><input type="checkbox" name="chkScar" value="Scar"> 1. Scar</td>
</tr>
<tr>
<td><input type="checkbox" name="chkHepa" value="HEPA-B"> HEPA-B</td>
<td><input type="checkbox" name="chkSkin" value="Skin Disease"> Skin Disease</td>
<td><input type="checkbox" name="chkHypertension2" value="Hypertension"> Hypertension</td>
<td><input type="checkbox" name="chkMole" value="Mole"> 2. Mole</td>
</tr>
<tr>
<td>Others:</td>
<td><input type="checkbox" name="chkStd2" value="STD"> STD</td>
<td><input type="checkbox" name="chkKidney2" value="Kidney Problem"> Kidney Problem</td>
<td><input type="checkbox" name="chkTattoo" value="Tattoo"> 3. Tattoo</td>
</tr>
<tr>
<td><input type="text" class="form-control" placeholder="Enter Others" name="txtOthersImmu"> </td>
<td></td>
<td>Others:</td>
<td><input type="checkbox" name="txtBirthmark" value="Birthmark"> 4. Birthmark</td>
</tr>
<tr>
<td><input type="text" class="form-control" placeholder="Enter Others" name="txtOthersImmu2"> </td>
<td></td>
<td><input type="text" class="form-control" placeholder="Enter Others" name="txtOthersIll"> </td>
<td></td>
</tr>
<tr>
<td><input type="text" class="form-control" placeholder="Enter Others" name="txtOthersImmu3"> </td>
<td></td>
<td><input type="text" class="form-control" placeholder="Enter Others" name="txtOthersIll2"> </td>
<td></td>
</tr>
</tbody>
</table> <label><b>FOR FEMALE ONLY: Date of Last Menstrual Period:</b></label>
<div class="form-group">
<div class="input-group">
<div class="input-group-addon"> <i class="fa fa-calendar"></i> </div> <input type="date" placeholder="Enter Birthday" class="form-control" data-inputmask="'alias': 'mm/dd/yyyy'" data-mask name="txtMens"> </div>
<!-- /.input group -->
</div>
<!-- /.form group -->
<div class="clearfix"> <button type="submit" name="submit" class="btn btn-block btn-primary btn-lg">Add Student</button> <button type="button" class="btn btn-block btn-danger btn-lg">Cancel</button> <br><br> </div>
</div>
</div>
</form>
<?php }?>

How to insert bulk data with same name field in php mysql

I had tried to insert bulk data with same name field contains multiple rows. But only single row is inserted.
How to insert bulk data as different values to insert into the database.
INSERT INTO table_name (username, luck_number, test, tester) VALUES (('$username', '$luck_number', '$test', '$tester').
<tr>
<td>1</td>
<input type="hidden" name="username" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number" value="" />
</td>
<td>
<input type="text" name="big" value="" />
</td>
<td>
<input type="text" name="test" value="" />
</td>
<td>
<input type="text" name="tester" value="" />
</td>
</tr>
<tr>
<td>2</td>
<input type="hidden" name="username" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number" value="" />
</td>
<td>
<input type="text" name="big" value="" />
</td>
<td>
<input type="text" name="test" value="" />
</td>
<td>
<input type="text" name="tester" value="" />
</td>
</tr>
<tr>
<td>3</td>
<input type="hidden" name="username" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number" value="" />
</td>
<td>
<input type="text" name="big" value="" />
</td>
<td>
<input type="text" name="test" value="" />
</td>
<td>
<input type="text" name="tester" value="" />
</td>
</tr>
#nisha,In your scenario only single row is inserted because variables are same name so it's overridden, Please try below code, It will give you array of fields so you can easily create for-loop & do multiple insert with your query.
<form method="post" name="userdata">
<tr>
<td>1</td>
<input type="hidden" name="username[]" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number[]" value="" />
</td>
<td>
<input type="text" name="big[]" value="" />
</td>
<td>
<input type="text" name="test[]" value="" />
</td>
<td>
<input type="text" name="tester[]" value="" />
</td>
</tr>
<tr>
<td>2</td>
<input type="hidden" name="username[]" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number[]" value="" />
</td>
<td>
<input type="text" name="big[]" value="" />
</td>
<td>
<input type="text" name="test[]" value="" />
</td>
<td>
<input type="text" name="tester[]" value="" />
</td>
</tr>
<tr>
<td>3</td>
<input type="hidden" name="username[]" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number[]" value="" />
</td>
<td>
<input type="text" name="big[]" value="" />
</td>
<td>
<input type="text" name="test[]" value="" />
</td>
<td>
<input type="text" name="tester[]" value="" />
</td>
</tr>
<input type="submit" name="submit">
</form>
**Note:**you can worry about the security issue letter. read the answer with the comment.
Store them in array by adding [ ] this in your input field
<tr>
<td>1</td>
<form action="" method="POST">
<input type="hidden" name="username" value="<?php echo $login_session; ?>"/>
<td><input type="text" name="luck_number[]" value=""/></td>
<td><input type="text" name="big[]" value=""/></td>
<td><input type="text" name="test[]" value=""/></td>
<td><input type="text" name="tester[]" value=""/></td>
</tr>
<tr>
<td>2</td>
<input type="hidden" name="username" value="<?php echo $login_session; ?>"/>
<td><input type="text" name="luck_number[]" value=""/></td>
<td><input type="text" name="big[]" value=""/></td>
<td><input type="text" name="test[]" value=""/></td>
<td><input type="text" name="tester[]" value=""/></td>
</tr>
<tr>
<td>3</td>
<input type="hidden" name="username" value="<?php echo $login_session; ?>"/>
<td><input type="text" name="luck_number[]" value=""/></td>
<td><input type="text" name="big[]" value=""/></td>
<td><input type="text" name="test[]" value=""/></td>
<td><input type="text" name="tester[]" value=""/></td>
</tr>
<tr></td><input type="submit" name="submit" value="submit"/><tr></td>
</form>
<?php
//connect with your database
for($i=0;$i<count($_POST['luck_number']);$i++)
{
//set the value for variable
$luck_number=$_POST['luck_number'][$i];
$test=$_POST['test'][$i];
$tester=$_POST['tester'][$i];
//run your query
//INSERT INTO table_name (username, luck_number, test, tester) VALUES (('$username', '$luck_number', '$test', '$tester').
}
First of all change all field names by adding [] at the end.
Second step, to parsing all values you may use something like this
for($i=0; $i < $count($_GET['username']); $i++)
{
$username = $_GET['username'][$i];
$luck_number= $_GET['luck_number'][$i];
$big= $_GET['big'][$i];
$test= $_GET['test'][$i];
$tester= $_GET['tester'][$i];
// insert into database
}
The reason of inserting single row instead of multiple rows is your input field name. You are using same name in different input field so when the server gets the reply it replace the duplicate name and the last occurrence is outputted.
The thing you have to do is to use array. If you use known number of rows then you can simply use a for loop to insert data.
<tr>
<td>1</td>
<input type="hidden" name="username[]" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number[]" value="" />
</td>
<td>
<input type="text" name="big[]" value="" />
</td>
<td>
<input type="text" name="test[]" value="" />
</td>
<td>
<input type="text" name="tester[]" value="" />
</td>
</tr>
<tr>
<td>2</td>
<input type="hidden" name="username[]" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number[]" value="" />
</td>
<td>
<input type="text" name="big[]" value="" />
</td>
<td>
<input type="text" name="test[]" value="" />
</td>
<td>
<input type="text" name="tester[]" value="" />
</td>
</tr>
<tr>
<td>3</td>
<input type="hidden" name="username[]" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number[]" value="" />
</td>
<td>
<input type="text" name="big[]" value="" />
</td>
<td>
<input type="text" name="test[]" value="" />
</td>
<td>
<input type="text" name="tester[]" value="" />
</td>
</tr>
<?php
for ($i=0; $i<count($_POST['username']); $i++)
{
mysql_query("INSERT INTO table_name (`username`, `luck_number`, `test`, `tester`) VALUES (('".$_POST['username'][$i]."', '".$_POST['luck_number'][$i]."', '".$_POST['test'][$i]."', '".$_POST['tester'][$i]."')");
}
?>
Note: Sanitizing variable is always been a good practice and strongly recommended.

Edit Database in PHP-Site

I'm very new to php and databases. So I need you to help me out please.
I want to edit the data of my database online in my php site. But the form is empty and I don't know why.
I don't know if you need more information so this is the code of the table with the form. If you need more let me know.
<table>
<?php
$con=mysqli_connect("x","y","z","xyz");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Transparente");
while($row = mysqli_fetch_array($result))
mysqli_close($con);
?>
<form method="post" action="edit_data.php">
<input type="text" name="id" value="<? echo "$row[id]"?>">
<tr>
<td>Firma</td>
<td>
<input type="text" name="name"
size="40" value="<? echo "$row[Name]"?>">
</td>
</tr>
<tr>
<td>Wer</td>
<td>
<input type="text" name="wer" size="40"
value="<? echo "$row[Wer]"?>">
</td>
</tr>
<tr>
<td>Erhalten</td>
<td>
<input type="text" name="erhalten" size="40"
value="<? echo "$row[Erhalten]"?>">
</td>
</tr>
<tr>
<td>Digital</td>
<td>
<input type="text" name="digital" size="40"
value="<? echo "$row[Digital]"?>">
</td>
</tr>
<tr>
<td>Betrag in Euro</td>
<td>
<input type="text" name="betrag" size="40"
value="<? echo "$row[Betrag]"?>">
</td>
</tr>
<tr>
<td>Bezahlt am</td>
<td>
<input type="text" name="bezahlt" size="40"
value="<? echo "$row[Bezahlt]"?>">
</td>
</tr>
<tr>
<td>Anmerkung</td>
<td>
<input type="text" name="anmerkung" size="40"
value="<? echo "$row[Anmerkung]"?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
</table>
Try below code
1)If data base contain more rows it shows multiple form
2)You need to show one form you need to restrict in query using where class
<?php
$con=mysqli_connect("x","y","z","xyz");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Transparente");
while($row = mysqli_fetch_array($result))
{
?>
<table>
<form method="post" action="edit_data.php">
<input type="text" name="id" value="<?php echo $row['id'];?>">
<tr>
<td>Firma</td>
<td>
<input type="text" name="name"
size="40" value="<?php echo $row['Name'];?>">
</td>
</tr>
<tr>
<td>Wer</td>
<td>
<input type="text" name="wer" size="40"
value="<?php echo $row['Wer']?>">
</td>
</tr>
<tr>
<td>Erhalten</td>
<td>
<input type="text" name="erhalten" size="40"
value="<?php echo $row['Erhalten']?>">
</td>
</tr>
<tr>
<td>Digital</td>
<td>
<input type="text" name="digital" size="40"
value="<?php echo $row['Digital']?>">
</td>
</tr>
<tr>
<td>Betrag in Euro</td>
<td>
<input type="text" name="betrag" size="40"
value="<?php echo $row['Betrag']?>">
</td>
</tr>
<tr>
<td>Bezahlt am</td>
<td>
<input type="text" name="bezahlt" size="40"
value="<?php echo "$row[Bezahlt]"?>">
</td>
</tr>
<tr>
<td>Anmerkung</td>
<td>
<input type="text" name="anmerkung" size="40"
value="<?php echo $row['Anmerkung'];?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
</table>
<?php } ?>
Edit:
change query like below
$result = mysqli_query($con,"SELECT * FROM Transparente where id={$_REQUEST['id']}");
<table>
<?php
$con=mysqli_connect("x","y","z","xyz");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Transparente");
while($row = mysqli_fetch_array($result))
?>
<form method="post" action="edit_data.php">
<input type="text" name="id" value="<? echo "$row[id]"?>">
<tr>
<td>Firma</td>
<td>
<input type="text" name="name"
size="40" value="<? echo "$row[Name]"?>">
</td>
</tr>
<tr>
<td>Wer</td>
<td>
<input type="text" name="wer" size="40"
value="<? echo "$row[Wer]"?>">
</td>
</tr>
<tr>
<td>Erhalten</td>
<td>
<input type="text" name="erhalten" size="40"
value="<? echo "$row[Erhalten]"?>">
</td>
</tr>
<tr>
<td>Digital</td>
<td>
<input type="text" name="digital" size="40"
value="<? echo "$row[Digital]"?>">
</td>
</tr>
<tr>
<td>Betrag in Euro</td>
<td>
<input type="text" name="betrag" size="40"
value="<? echo "$row[Betrag]"?>">
</td>
</tr>
<tr>
<td>Bezahlt am</td>
<td>
<input type="text" name="bezahlt" size="40"
value="<? echo "$row[Bezahlt]"?>">
</td>
</tr>
<tr>
<td>Anmerkung</td>
<td>
<input type="text" name="anmerkung" size="40"
value="<? echo "$row[Anmerkung]"?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
</table>
<?php mysqli_close($con);?>
// close connection at the end of the code
You are not opening the while loop.Try this it will show you the values in the form
<table>
<?php
$con=mysqli_connect("x","y","z","xyz");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Transparente");
while($row = mysqli_fetch_array($result))
{
mysqli_close($con);
?>
<form method="post" action="edit_data.php">
<input type="text" name="id" value="<? echo "$row[id]"?>">
<tr>
<td>Firma</td>
<td>
<input type="text" name="name"
size="40" value="<? echo "$row[Name]"?>">
</td>
</tr>
<tr>
<td>Wer</td>
<td>
<input type="text" name="wer" size="40"
value="<? echo "$row[Wer]"?>">
</td>
</tr>
<tr>
<td>Erhalten</td>
<td>
<input type="text" name="erhalten" size="40"
value="<? echo "$row[Erhalten]"?>">
</td>
</tr>
<tr>
<td>Digital</td>
<td>
<input type="text" name="digital" size="40"
value="<? echo "$row[Digital]"?>">
</td>
</tr>
<tr>
<td>Betrag in Euro</td>
<td>
<input type="text" name="betrag" size="40"
value="<? echo "$row[Betrag]"?>">
</td>
</tr>
<tr>
<td>Bezahlt am</td>
<td>
<input type="text" name="bezahlt" size="40"
value="<? echo "$row[Bezahlt]"?>">
</td>
</tr>
<tr>
<td>Anmerkung</td>
<td>
<input type="text" name="anmerkung" size="40"
value="<? echo "$row[Anmerkung]"?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
</table>
<?php }?>

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 add multiple input textfield values into db using php

How to insert multiple textfields value into mysqldb?
<?php
if(isset($_POST['save'])){
foreach($_POST['color'] as $key => $value)
{
if($color!="")
{
$color = $value['code'];
echo $color;
$rgb = hex2rgba($color);
$rgba = hex2rgba($color, 0.7);
/*echo $rgba;
echo $value['key'];
echo $value['code'];
echo $value['order_color'];*/
$sql = "INSERT INTO tbl_colors values('','$rgba','".$value['key']."','".$value['code']."','".$value['order_color']."')";
$rs = mysql_query($sql) or die("Bad Query==><br><br>$sql<br><br>".mysql_error());
}
}
?>
<form action="" method="post" name="recommend">
<tr>
<td><input type="text" value="" name="color[][key]" class="email" style="width:450px;font- size:15px;font-weight:bold;"></td>
td><input type="text" value="" name="color[][code]" class="email"></td>
<td><input type="text" value="" name="color[][order_color]" class="email" style="width:50px;"></td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td><input type="text" value="" name="color[][key]" class="email" style="width:450px;font- size:15px;font-weight:bold;"></td>
td><input type="text" value="" name="color[][code]" class="email"></td>
<td><input type="text" value="" name="color[][order_color]" class="email" style="width:50px;"></td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td colspan="5" align="center"><input type="submit" name="save" value="Add Color" /></td>
</tr>
</form>
{
<?php
if(isset($_POST['save'])){
foreach($_POST['color'] as $key => $value)
{
$color = $value['code'];
echo $color;
$rgb = hex2rgba($color);
$rgba = hex2rgba($color, 0.7);
/*echo $rgba;
echo $value['key'];
echo $value['code'];
echo $value['order_color'];*/
$sql = "INSERT INTO tbl_colors values('','$rgba','".$value['key']."','".$value['code']."','".$value['order_color']."')";
$rs = mysql_query($sql) or die("Bad Query==><br><br>$sql<br><br>".mysql_error());
}
}
?>
<form action="" method="post" name="recommend">
<tr>
<td><input type="text" value="" name="color[1][key]" class="email" style="width:450px;font- size:15px;font-weight:bold;"></td>
td><input type="text" value="" name="color[1][code]" class="email"></td>
<td><input type="text" value="" name="color[1][order_color]" class="email" style="width:50px;"></td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td><input type="text" value="" name="color[2][key]" class="email" style="width:450px;font- size:15px;font-weight:bold;"></td>
td><input type="text" value="" name="color[2][code]" class="email"></td>
<td><input type="text" value="" name="color[2][order_color]" class="email" style="width:50px;"></td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td colspan="5" align="center"><input type="submit" name="save" value="Add Color" /></td>
</tr>
</form>
}
Row1, Row2, Row3 are your table rows you need to name them to your table row.
<?php
if(isset($_POST['colorkey'])){
$colorkey = $_POST['colorkey'];
$colorcode = $_POST['colorkcode'];
$colorcode = $_POST['colororder'];
$sql = ("INSERT INTO tbl_colors (Row1, Row2, Row3) VALUES ('$colorkey', '$colorcode', '$colorcode')");
}
?>
<form action="" method="post" name="recommend">
<tr>
<td><input type="text" value="" name="colorkey" class="email" style="width:450px;font- size:15px;font-weight:bold;"></td>
td><input type="text" value="" name="colorcode" class="email"></td>
<td><input type="text" value="" name="colororder" class="email" style="width:50px;"></td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td><input type="text" value="" name="colorkey" class="email" style="width:450px;font- size:15px;font-weight:bold;"></td>
td><input type="text" value="" name="colorcode" class="email"></td>
<td><input type="text" value="" name="colororder" class="email" style="width:50px;"></td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td colspan="5" align="center"><input type="submit" name="save" value="Add Color" /></td>
</tr>
</form>

Categories