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 }?>
I want to insert value in a database and it inserted empty. I want help for this necessary.
This is the variable of time :
$rm_time = $_POST['rm-time'];
PHP
if(empty($_POST['rm-name']) or empty($_POST['rm-details'])){
?>
<h3 style="margin-top: 30px;text-align: center;font-size: 25px;color: red;" dir="rtl">Error</h3>
<?php
}else{
$rm_name = $_POST['rm-name'];
$rm_details = $_POST['rm-details'];
$rm_date = $_POST['rm-date'];
$rm_time = $_POST['rm-time'];
$rm_insert_query = $db->query("INSERT INTO reminders (r_name, r_details, r_date, r_time) VALUES ('$rm_name', '$rm_details', '$rm_date', '$rm_time')");
}
}
?>
<form action="reminder.php?rm=make" method="post">
<table class="rm" width="auto" border="0px">
<tr>
<td class="rm-form-text">Reminder date/time :</td>
<td><input autofocus="" name="rm-date" type="date" id="rm" /> / <input name"rm-time" type="time" id="rm" /></td>
</tr>
<tr>
<td class="rm-form-text">Remimnder name :</td>
<td><input name="rm-name" type="text" id="rm" /></td>
</tr>
<tr>
<td class="rm-form-text">Reminder details :</td>
<td><textarea dir="rtl" name="rm-details" id="rm-ta"></textarea></td>
</tr>
<tr>
<td colspan="2"><input name="save-reminder" type="submit" class="sp-submit" value="Save!" /></td>
</tr>
</table>
</form>
<?
exit;
here your syntax is wrong.
Use
<input name= "rm-time" type="time" id="rm" />
instead of
<input name"rm-time" type="time" id="rm" />
change this
FROM : <input name"rm-time" type="time" id="rm" /></td>
TO : <input name="rm-time" type="time" id="rm" /></td>
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 } ?>
I have a form as shown below if I select company from dropdown disable collegename, course and year. If I select college disable company name and date of join. Please help regarding this. I need some help on how to disable text fields when we select value from drop down
<form name="form" method="post" action="" onSubmit="submit;">
<center><table border="1" cellspacing="0" style="width:650px">
<tr>
<td><b>Name</td>
<td><input type="text" name="name"></td></tr>
<tr>
<td><b>Father Name</td>
<td><input type="text" name="fname"></td></tr>
<tr><td><b>Gender</td>
<td><select name="gender">
<option value="na">Select</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</td></tr>
<tr>
<td><b>Email</td>
<td><input type="text" name="email"></td></tr>
<tr>
<td><b>Date Of Birth</td>
<td><input type="text" name="date" id="datepicker" required></td></tr>
<tr>
<td><b>Mobile Number</td>
<td><input type="text" name="mn"></td></tr>
<tr>
<td><b>Parent Number</td>
<td><input type="text" name="pn"></td></tr>
<tr>
<td><b>Address</td> <td><textarea name="address" rows="3" cols="50"></textarea></td>
</tr>
<tr>
<td><b>Coll/Comp ID Num</td>
<td><input type="text" name="idnum"></td></tr>
<tr><td><b>Company/College</td>
<td><select name="ccname">
<option value="na">Select</option>
<option value="company">Company</option>
<option value="college">College</option>
</td></tr>
<tr>
<td><b>College Name</td>
<td><input type="text" name="colname"></td></tr>
<tr>
<td><b>Course</td>
<td><input type="text" name="course"></td></tr>
<tr>
<td><b>Year</td>
<td><input type="text" name="year"></td></tr>
<tr>
<td><b>Company Name</td>
<td><input type="text" name="comname"></td></tr>
<tr>
<td><b>Date Of Join</td>
<td><input type="text" name="doj" id="datepicker" required></td></tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" value="submit"/></td>
</tr></center>
</table>
</form>
Use some thing like this if you have problem tell me
<script>
function getccname(val)
{
if(val == 'company')
{
document.getElementById("colname").disabled = true;
document.getElementById("course").disabled = true;
document.getElementById("year").disabled = true;
}
else if(val == 'college')
{
document.getElementById("comname").disabled = true;
document.getElementsByName("doj")[0].disabled = true;
document.getElementById("colname").disabled = false;
document.getElementById("course").disabled = false;
document.getElementById("year").disabled = false;
}
else
{
document.getElementById("comname").disabled = false;
document.getElementsByName("doj")[0].disabled = false;
document.getElementById("colname").disabled = false;
document.getElementById("course").disabled = false;
document.getElementById("year").disabled = false;
}
}
</script>
<form name="form" method="post" action="" onSubmit="submit;">
<center><table border="1" cellspacing="0" style="width:650px">
<tr>
<td><b>Name</td>
<td><input type="text" name="name"></td></tr>
<tr>
<td><b>Father Name</td>
<td><input type="text" name="fname"></td></tr>
<tr><td><b>Gender</td>
<td><select name="gender">
<option value="na">Select</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</td></tr>
<tr>
<td><b>Email</td>
<td><input type="text" name="email"></td></tr>
<tr>
<td><b>Date Of Birth</td>
<td><input type="text" name="date" id="datepicker" required></td></tr>
<tr>
<td><b>Mobile Number</td>
<td><input type="text" name="mn"></td></tr>
<tr>
<td><b>Parent Number</td>
<td><input type="text" name="pn"></td></tr>
<tr>
<td><b>Address</td> <td><textarea name="address" rows="3" cols="50"></textarea></td>
</tr>
<tr>
<td><b>Coll/Comp ID Num</td>
<td><input type="text" name="idnum"></td></tr>
<tr><td><b>Company/College</td>
<td><select name="ccname" onchange="getccname(this.value);">
<option value="na">Select</option>
<option value="company">Company</option>
<option value="college">College</option>
</td></tr>
<tr>
<td><b>College Name</td>
<td><input type="text" name="colname" id="colname"></td></tr>
<tr>
<td><b>Course</td>
<td><input type="text" name="course" id="course"></td></tr>
<tr>
<td><b>Year</td>
<td><input type="text" name="year" id="year"></td></tr>
<tr>
<td><b>Company Name</td>
<td><input type="text" name="comname" id="comname"></td></tr>
<tr>
<td><b>Date Of Join</td>
<td><input type="text" name="doj" id="datepicker"></td></tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" value="submit"/></td>
</tr></center>
</table>
</form>
Call a javascript function with your drop down list, use anything like that onclick="sample1();" , then disable your text field using
function sample1(){
document.getElementById("textfield").disabled=true;
}
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 }?>