I already found a question called "Check if at least 1 checkbox is ticked in PHP", but that did not meet my needs because I am an organized person and that didn't seem like an organized way of doing it. I have this checkbox code:
<h1>_________</h1>
<p>Which records would you like to see?<br />
Enter as little or as many criteria as you want and then press Submit.</p>
<form method = "get" action = "http://www.its-a-secret.com/validation.php">
<div>
<span>
<label for = "lastname" id = "txtlabel">Last Name</label>
<input type = "text" name = "lastname" />
</span>
<span>
<label for = "firstname" id = "txtlabel">First Name</label>
<input type = "text" name = "firstname" />
</span>
<span>
<label for = "company" id = "txtlabel">Company</label>
<?php
session_start();
mysql_connect("______","_______","________");
mysql_select_db("____");
$sql = "SELECT DISTINCT company FROM _____";
$result = mysql_query($sql);
print "<select name = 'company' id = 'company'> \n";
print " <option></option> \n";
while ($row = mysql_fetch_array($result)) {
print " <option value='" . $row['company'] . "'>" . $row['company'] . "</option> \n";
}
print " </select> \n";
?>
</span>
<span id = "spanaccttype">
<label for = "accttype" id = "txtlabel">Account type</label>
<?php
mysql_connect("_____","_____","_______");
mysql_select_db("_____");
$sql = "SELECT DISTINCT accttype FROM _____";
$result = mysql_query($sql);
print "<select name = 'accttype' id = 'accttype'> \n";
print " <option></option> \n";
while ($row = mysql_fetch_array($result)) {
print " <option value='" . $row['accttype'] . "'>" . $row['accttype'] . "</option> \n";
}
print " </select> \n";
?>
</span>
<span id = "spanproductname">
<label for = "productname" id = "txtlabel">Product Name</label>
<?php
mysql_connect("______","______","______");
mysql_select_db("_____");
$sql = "SELECT DISTINCT productname FROM ______";
$result = mysql_query($sql);
print "<select name = 'productname' id = 'productname'> \n";
print " <option></option> \n";
while ($row = mysql_fetch_array($result)) {
print " <option value='" . $row['productname'] . "'>" . $row['productname'] . "</option> \n";
}
print " </select> \n";
?>
</span>
<span id = "spansharetype">
<label for = "sharetype" id = "txtlabel">Share Type</label>
<?php
mysql_connect("_____","_____","______");
mysql_select_db("_____");
$sql = "SELECT DISTINCT sharetype FROM _____";
$result = mysql_query($sql);
print "<select name = 'sharetype' id = 'sharetype'> \n";
print " <option></option> \n";
while ($row = mysql_fetch_array($result)) {
print " <option value='" . $row['sharetype'] . "'>" . $row['sharetype'] . "</option> \n";
}
print " </select> \n";
?>
</span>
<span id = "spanclosed">
<label for = "closed" id = "txtlabel">Closed?</label>
<?php
mysql_connect("_________","______","__");
mysql_select_db("____");
$sql = "SELECT DISTINCT closed FROM _____";
$result = mysql_query($sql);
print "<select name = 'closed' id = 'closed'> \n";
print " <option></option> \n";
while ($row = mysql_fetch_array($result)) {
print " <option value='" . $row['closed'] . "'>" . $row['closed'] . "</option> \n";
}
print " </select> \n";
?>
</span>
<span id = "spanvaluegreaterthan">
<label for = "valuegreaterthan" id = "txtlabel">Value Greater Than $</label>
<input type = "number" name = "valuegreaterthan" />
</span>
<br />
<span id = "spanwhatcolumnstoshowquestion">What columns would you like to show? (Note if none are checked none of the below will be shown.)</span>
<table id = "showwhichcolumns">
<tr>
<td><input type = "checkbox" id = "showcolumncompany" name = "showcolumncompany" value = "showcolumncompany" title = "Show column company" /><label for = "showcolumncompany" id = "check">Company</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumnaccountnumber" name = "showcolumnaccountnumber" value = "showcolumnaccountnumber" title = "Show column account number" /><label for = "showcolumnaccountnumber" id = "check">Account #</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumncontractdate" name = "showcolumncontractdate" value = "showcolumncontractdate" title = "Show column contract date" /><label for = "showcolumncontractdate" id = "check">Contract Date</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumnclosed" name = "showcolumnclosed" value = "showcolumnclosed" title = "Show column close" /><label for = "showcolumnclosed" id = "check">Closed?</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumndateclosed" name = "showcolumndateclosed" value = "showcolumndateclosed" /><label for = "showcolumndateclosed" id = "check">Date Closed</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumndob" name = "showcolumndob" value = "showcolumndob" /><label for = "showcolumndob" id = "check">DOB</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumnproductname" name = "showcolumnproductname" value = "showcolumnproductname" /><label for = "showcolumnproductname" id = "check">Product Name</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumncommissionpercent" name = "showcolumncommissionpercent" value = "showcolumncommissionpercent" /><label for = "showcolumncommissionpercent" id = "check">Commission %</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumncommissionpayoutpercent" name = "showcolumncommissionpayoutpercent" value = "showcolumncommissionpayoutpercent" /><label for = "showcolumncommissionpayoutpercent" id = "check">Commission Payout (%)</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumncommissionpayoutdollars" name = "showcolumncommissionpayoutdollars" value = "showcolumncommissionpayoutdollars" /><label for = "showcolumncommissionpayoutdollars" id = "check">Commission Payout ($)</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumntrailcomm" name = "showcolumntrailcomm" value = "showcolumntrailcomm" /><label for = "showcolumntrailcomm" id = "check">Trail Comm?</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumnguaranteepercent" name = "showcolumnguaranteepercent" value = "showcolumnguaranteepercent" /><label for = "showcolumnguaranteepercent" id = "check">Guarantee %</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumnaccounttype" name = "showcolumnaccounttype" value = "showcolumnaccounttype" title = "Show column account type" /><label for = "showcolumnaccounttype" id = "check">Account Type</label></td>
</table>
<p>
<input type = "submit" value = "Submit" id = "gobutton" />
</p>
The form submits to a page called validation.php and this is the code for that page (I hardly have anything yet):
<?php
$lastname = $_REQUEST["lastname"];
$firstname = $_REQUEST["firstname"];
$company = $_REQUEST["company"];
$accttype = $_REQUEST["accttype"];
$productname = $_REQUEST["productname"];
$sharetype = $_REQUEST["sharetype"];
$closed = $_REQUEST["closed"];
$valuegreaterthan = $_REQUEST["valuegreaterthan"];
header("Location: http://www.its-a-secret/?lastname=" . htmlspecialchars($lastname) . "&firstname=" . htmlspecialchars($firstname) . "&company=" . htmlspecialchars($company));
?>
I would like to delete the HTML special characters, instead of changing them, I would also want the First Name and Last Name to only have one capital letter by just telling the user, and if they don't I want the SQL to be able to validate with the First Name or Last Name being all capital or something crazy like that. I also want the First Name and Last Name to have all there space(s), if there are any. I want there to be at least one checkbox checked. I also want there to be a positive number that is a number in the number textbox.
I'm not sure what you are trying to do, but here is my guess code:
if(isset($_GET['showcolumnxx']) || isset($_GET['showcolumnxx']) || isset($_GET['showcolumnxx'] || etc.)) {
$newUrl = "http://something.site.end/otherpageshere/[screenAfterValidation].php";
header('Location: ' . $newUrl);
} else {
print "<p style = "color: red;">You must at least check one checkbox.</p>\n";
}
This may help. I am just echoing in the same page. You can change it according to your need.
<?php
if(!empty($_GET['check'])) {
foreach($_GET['check'] as $check) {
echo $check."<br />";
}
}
?>
<form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>">
<span id = "spanwhatcolumnstoshowquestion">What columns would you like to show? (Note if none are checked none of the below will be shown.)</span>
<table id = "showwhichcolumns">
<tr>
<td><input type = "checkbox" id = "showcolumncompany" name = "check[]" value = "showcolumncompany" title = "Show column company" /><label for = "showcolumncompany" id = "check">Company</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumnaccountnumber" name = "check[]" value = "showcolumnaccountnumber" title = "Show column account number" /><label for = "showcolumnaccountnumber" id = "check">Account #</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumncontractdate" name = "check[]" value = "showcolumncontractdate" title = "Show column contract date" /><label for = "showcolumncontractdate" id = "check">Contract Date</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumnclosed" name = "check[]" value = "showcolumnclosed" title = "Show column close" /><label for = "showcolumnclosed" id = "check">Closed?</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumndateclosed" name = "check[]" value = "showcolumndateclosed" /><label for = "showcolumndateclosed" id = "check">Date Closed</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumndob" name = "check[]" value = "showcolumndob" /><label for = "showcolumndob" id = "check">DOB</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumnproductname" name = "check[]" value = "showcolumnproductname" /><label for = "showcolumnproductname" id = "check">Product Name</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumncommissionpercent" name = "check[]" value = "showcolumncommissionpercent" /><label for = "showcolumncommissionpercent" id = "check">Commission %</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumncommissionpayoutpercent" name = "check[]" value = "showcolumncommissionpayoutpercent" /><label for = "showcolumncommissionpayoutpercent" id = "check">Commission Payout (%)</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumncommissionpayoutdollars" name = "check[]" value = "showcolumncommissionpayoutdollars" /><label for = "showcolumncommissionpayoutdollars" id = "check">Commission Payout ($)</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumntrailcomm" name = "check[]" value = "showcolumntrailcomm" /><label for = "showcolumntrailcomm" id = "check">Trail Comm?</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumnguaranteepercent" name = "check[]" value = "showcolumnguaranteepercent" /><label for = "showcolumnguaranteepercent" id = "check">Guarantee %</label></td>
</tr>
<tr>
<td><input type = "checkbox" id = "showcolumnaccounttype" name = "check[]" value = "showcolumnaccounttype" title = "Show column account type" /><label for = "showcolumnaccounttype" id = "check">Account Type</label></td>
</table>
<p>
<input type = "submit" value = "Submit" id = "gobutton" />
</p>
</form>
Related
I am new to programming and I am in need of of assistance. I have a HTML form on a page called addbooking.php with the following code:
<form method = "post" action = "" >
<table cellspacing="15">
<tr>
<th>Bookingid </th>
<td><input type = "text" name = "bookingid"/> </td>
</tr>
<tr>
<th>Booking Name </th>
<td><input type = "text" name = "bookingname" /> </td>
</tr>
<tr>
<th> <label for = "Cabin Type">Cabin Type </label> </th>
td><select name = "Cabin Type" id = "Cabin Type">
<option select>Select a Cabin Type</option>
<option value = "Luxury Cabin">Luxury Cabin </option>
<option value = "Contemporary Cabin">Contemporary Cabin </option>
<option value = "Original Cabin">Original Cabin </option>
</select>
</td>
</tr>
<tr>
<th>Length of Stay </th>
<td><input type = "text" name = "lengthofstay" /> </td>
</tr>
<tr>
<th>Details About Guests </th>
<td><textarea cols = "30" rows = "5" type = "text" name="guests_description"
/> </textarea> </td>
</tr>
<tr>
<th>Booking Start Date </th>
<td><input type = "text" name = "startdate" /> </td>
</tr>
<tr>
<th>Booking End Date </th>
<td><input type = "text" name = "enddate" /> </td>
</tr>
<tr>
<th>Other Relavant Information </th>
<td><textarea cols = "30" rows = "5" type = "text" name="other_information"
/> </textarea> </td>
</tr>
<tr>
<th> </th>
<td> <input type = "submit" value = "Create Booking!" name =
"bookingdetails" /> </td>
</tr>
</table>
</form>
I also have php code on the same page which looks like the following:
<?php
include ('dbconnect.php');
// get values from the form
function getPosts(){
$posts = array();
$posts[0] = $_POST['bookingid'];
$posts[1] = $_POST['bookingname'];
$posts[2] = $_POST['lengthofstay'];
$posts[3] = $_POST['guests_description'];
$posts[4] = $_POST['startdate'];
$posts[5] = $_POST['enddate'];
$posts[6] = $_POST['other_information'];
return $posts;
}
if (isset($_POST['bookingdetails'])) {
$data = getPosts();
if (empty($bookingname)){
$errors[] = "Please enter the your booking name.";
}
if(empty($errors)){
foreach($errors as $error){
echo $error . "<br/>";
}
else{
$insert_Query = "insert into bookings
(Bookingid,Bookingname,Lengthofstay,Details_about_guests,
Booking_start_date,Booking_end_date,Other_relavant_information)
values ('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]',
'$data[5]','$data[6]')";
$result = mysqli_query($db, $insert_Query);
if ($result)
{
echo "<font color = 'green' . <p>Successfully Booked</p> </font>";
}
else{
echo "<p> Something went Wrong </p>" . mysqli_error ($db);
}
}
}
?>
I also have a table in my database called cabins which looks like:
Now, what I need some assistance with is how do I assign each of the prices from the Cabin_Price column to each item in the drop down menu on the form and then when the "booking details" button is pressed multiply the chosen value/option for e.g '1200' by what ever value is entered in the 'Length of Stay' field for e.g '4' using php. Below is a picture of what I mean:
Change your menu so that the values of the options are the cabin ID. Then when you're processing the form, you look up the price, and multiply by the length of stay. So the menu should look like:
<select name = "Cabin Type" id = "Cabin Type">
<option select>Select a Cabin Type</option>
<option value = "1">Luxury Cabin </option>
<option value = "2">Contemporary Cabin </option>
<option value = "3">Original Cabin </option>
</select>
And when the form is submitted, you do a query like:
$stmt = $dbh->prepare("SELECT cabin_price FROM cabins WHERE cabin_id = :id");
$stmt->bindParam(":id", $_POST["Cabin Type"]);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$price = $row['cabin_price'];
$total_price = $price * $_POST['lengthofstay'];
I have a table in MySql table with many rows of records (existingbankproducts table):
The code I use to select is from the database is below:
$stmt2 = $DB_con->prepare("SELECT * FROM applicantpersonaldetails apd "
. "INNER JOIN existingbankproducts ext ON apd.ApplicantID = ext.ApplicantID "
. "WHERE apd.AccountID ='{$accountId}' AND apd.applicantType ='main';");
$stmt2->execute();
if ($stmt2->rowCount() > 0) {
while ($row = $stmt2->fetch(PDO::FETCH_ASSOC)) {
?>
<?php
}
} else {
?>
<div class="">
<div class="alert alert-warning">
<span class="glyphicon glyphicon-info-sign"></span> No Data Found ...
</div>
</div>
<?php
}
I want to select them and insert to my HTML table, the code is below:
<table>
<tr>
<th>Financial Institution</th>
<th>Product Type</th>
<th>Balance</th>
<th>Monthly Commitment</th>
</tr>
<tr>
<td><input type = "text" name = "finanIns1" id = "finanIns1" value = ""readonly></td>
<td>
<input list = "proTypeList" name = "proType1" id = "proType1"readonly >
</td>
<td id = "balance"><input type = "number" name = "balance1" id = "balance1" value = "" min = "0"readonly></td>
<td id = "MonthyComm"><input type = "number" name = "monthlyComm1" id = "monthlyComm1" value = "" min = "0"readonly></td>
</tr>
<tr>
<td><input type = "text" name = "finanIns2" id = "finanIns2" value = ""readonly></td>
<td>
<input list = "proTypeList" name = "proType2" id = "proType2" readonly>
</td>
<td id = "balance"><input type = "number" name = "balance2" id = "balance2" value = "" min = "0"readonly></td>
<td id = "MonthyComm"><input type = "number" name = "monthlyComm2" id = "monthlyComm2" value = "" min = "0"readonly></td>
</tr>
</table>
Actually, there are more rows, this is an example.
Also, I put value="<?php echo $row['Financialinstitution'] " ?> as an example, However, all the records are coming out.
Is there any way to display the result according to the HTML table in order.
1st : You need to loop the record set like this
2nd : your input value should filled with right column like this
<input type = "text" name = "finanIns1" id = "finanIns1" value="<?php echo $row['Financialinstitution']; ?>" readonly>
Note : you need to echo the each column desired td input . i have echo only one column
3rd : using prepared statement is good . as well you need to use bindparam . like this
$stmt2 = $DB_con->prepare("SELECT * FROM applicantpersonaldetails apd "
. "INNER JOIN existingbankproducts ext ON apd.ApplicantID = ext.ApplicantID "
. "WHERE apd.AccountID =:accountId AND apd.applicantType ='main';");
$stmt2->bindParam(':accountId', $accountId, PDO::PARAM_INT);
//if account id data type is varchar change the last parameter to `PDO::PARAM_str`
$stmt2->execute();
PHP :
if ($stmt2->rowCount() > 0) {
?>
<table>
<tr>
<th>Financial Institution</th>
<th>Product Type</th>
<th>Balance</th>
<th>Monthly Commitment</th>
</tr>
<?php
while ($row = $stmt2->fetch(PDO::FETCH_ASSOC)) {
?>
<tr>
<td><input type = "text" name = "finanIns1" id = "finanIns1" value="<?php echo $row['Financialinstitution']; ?>" readonly></td>
// like above td you need to echo all your data for following td
<td>
<input list = "proTypeList" name = "proType1" id = "proType1" readonly >
</td>
<td id = "balance"><input type = "number" name = "balance1" id = "balance1" value = "" min = "0"readonly></td>
<td id = "MonthyComm"><input type = "number" name = "monthlyComm1" id = "monthlyComm1" value = "" min = "0"readonly></td>
</tr>
<?php
}
} else {
?>
<div class="">
<div class="alert alert-warning">
<span class="glyphicon glyphicon-info-sign"></span> No Data Found ...
</div>
</div>
<?php
}
Whatever i understand from your question you can look like below:
if ($stmt2->rowCount() > 0) {
while ($row = $stmt2->fetch(PDO::FETCH_ASSOC)) {
?>
<tr>
<td><input type = "text" name = "finanIns1" id = "finanIns1" value = "<?php $row['columnName']?>" readonly></td>
<td>
<input list = "proTypeList" name = "proType1" id = "proType1"readonly >
</td>
<td id = "balance"><input type = "number" name = "balance1" id = "balance1" value = "<?php $row['columnName']?>" min = "0"readonly></td>
<td id = "MonthyComm"><input type = "number" name = "monthlyComm1" id = "monthlyComm1" value = "" min = "0"readonly></td>
</tr>
<tr>
<td><input type = "text" name = "finanIns2" id = "finanIns2" value = "<?php $row['columnName']?>" readonly></td>
<td>
<input list = "proTypeList" name = "proType2" id = "proType2" readonly>
</td>
<td id = "balance"><input type = "number" name = "balance2" id = "balance2" value = "<?php $row['columnName']?>" min = "0"readonly></td>
<td id = "MonthyComm"><input type = "number" name = "monthlyComm2" id = "monthlyComm2" value = "<?php $row['columnName']?>" min = "0"readonly></td>
</tr>
<?php
?>
<?php
}
I just get this error below. It does work on localhost. Any ideas?
Any advise on how to google this error would help a lot as well, as I am not sure where the problem might be.
"The requested URL /edit.php was not found on this server."
<?php
include ('includes/connection.php');
include ('includes/functions.php');
include ('includes/header.php');
$jobId = $_GET["id"];
$query = "SELECT * FROM Freight, WHERE id = '$jobId'";
$result = mysqli_query($connection, $query);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$jobArrival = $row["Arrival"];
$jobDeparture = $row["Departure"];
$jobClient = $row["Client"];
$jobAirportOfDeparture = $row["AirportOfDeparture"];
$jobAirportOfArrival = $row["AirportOfArrival"];
$jobAdditionalInfo = $row["AdditionalInfo"];
$jobBoxType = $row["BoxType"];
$jobTemp = $row["Temp"];
// prideti is dezes table
// $pavadinimas = $row["pavadinimas"];
// $likutis = $row["likutis"];
if (isset($_POST['update'])) {
$jobArrival = validateFormData($_POST['jobArrival']);
$jobDeparture = validateFormData($_POST['jobDeparture']);
$jobClient = validateFormData($_POST['jobClient']);
$jobAirportOfDeparture = validateFormData($_POST['jobAirportOfDeparture']);
$jobAirportOfArrival = validateFormData($_POST['jobAirportOfArrival']);
$jobAdditionalInfo = validateFormData($_POST['jobAdditionalInfo']);
$jobBoxType = validateFormData($_POST['jobBoxType']);
$jobTemp = validateFormData($_POST['jobTemp']);
$query = "UPDATE Freight SET Arrival = '$jobArrival',
Departure = '$jobDeparture',
Client = '$jobClient',
AirportOfDeparture = '$jobAirportOfDeparture',
AirportOfArrival = '$jobAirportOfArrival',
AdditionalInfo = '$jobAdditionalInfo',
BoxType = '$jobBoxType',
Temp = '$jobTemp'
WHERE id = '$jobId'";
$result = mysqli_query($connection, $query);
if ($result) {
header("Location: formdisplay.php");
} else {
"Klaida" . mysqli_error($connection);
}
}
}
}
else {
echo "Nera irasu!!!!!!!!!!!!!!";
}
if (isset($_POST['istrinti'])) {
$query = "DELETE FROM Freight WHERE id ='$jobId'";
$result = mysqli_query($connection, $query);
if ($result) {
header("Location: formdisplay.php?alert=deleted");
}
else {
echo "Error" . mysqli_error($connection);
}
}
mysqli_close($connection);
?>
<h1> Iraso koregavimas</h1>
<table>
<tr>
<td>Arrival</td>
<td>Departure</td>
<td>Client</td>
<td>Airport Of Departure</td>
<td>Airport Of Arrival</td>
<td>Additional Info</td>
<td>Box Type</td>
<td>Temp</td>
</tr>
<tr>
<form method="POST" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>?id=<?php echo $jobId; ?>">
<td>
<input type = "text"
value = "<?php echo $jobArrival ?>"
name = "jobArrival">
</td>
<td>
<input type = "text"
value = "<?php echo $jobDeparture ?>"
name = "jobDeparture">
</td>
<td>
<input type = "text"
value = "<?php echo $jobClient ?>"
name = "jobClient">
</td>
<td>
<input type = "text"
value = "<?php echo $jobAirportOfDeparture ?>"
name = "jobAirportOfDeparture">
</td>
<td>
<input type = "text"
value = "<?php echo $jobAirportOfArrival ?>"
name = "jobAirportOfArrival">
</td>
<td>
<input type = "text"
value = "<?php echo $jobAdditionalInfo ?>"
name = "jobAdditionalInfo">
</td>
<td>
<input type = "text"
value = "<?php echo $jobBoxType ?>"
name = "jobBoxType">
</td>
<td>
<input type = "text"
value = "<?php echo $jobTemp ?>"
name = "jobTemp">
</td>
<td>
<input type = "submit"
name = "update"
value = "update"
href = "formdisplay.php"></td>
<td>
<input type ="submit"
name ="istrinti"
value ="istrinti"
href ="formdisplay.php">
</td>
</form>
</tr>
</table>
The key here is likely the / in /edit.php. Try including just edit.php instead, or more directly pathing it to the directory.
Good luck!
Problem SOLVED. Problem on line 143, few wrong spaces.
Took me only a week to find it :)
Code has to look like this <form method="POST" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>?id=<?php echo $jobId ?>">
I am keeping the value(inserted by user) of a text box in a variable $no. But it is not showing anything when I write an echostatement. I don't understand why??
I believe I am not inserting the value properly. I would like some help.
Thank you.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1" />
<title>Attendence form</title>
<link type = "text/css" rel = "stylesheet" href = "style.css">
</head>
<body>
<form action = "<?php $_SERVER['PHP_SELF']; ?>" method = "post">
<table>
<tr>
<th>Department</th>
<th>Year</th>
<th>Course</th>
<th>Lecture No</th>
<th>Date</th>
</tr>
<tr>
<td>
<select name = "dept">
<option value = "cse">CSE</option>
<option value = "eee">EEE</option>
</select>
</td>
<td>
<select name = "year">
<option value = "1st">1st</option>
<option value = "2nd">2nd</option>
</select>
</td>
<td>
<select name = "course">
<option value = "cse2200">CSE 2200</option>
<option value = "cse2201">CSE 2201</option>
<option value = "cse2213">CSE 2202</option>
<option value = "eee2217">EEE 2217</option>
<option value = "math2207">MATH 2207</option>
</select>
</td>
<td>
<input type = "text" name = "days" />
</td>
<td>
<?php echo date("Y/m/d"); ?>
</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td>
<input type = "submit" name = "submit" value = "Take attendence" />
</td>
<td>
<input type = "submit" name = "view" value = "View Attendence" />
</td>
</tr>
</table>
<hr />
<table>
<?php
$year = $_POST['year'];
$dept = $_POST['dept'];
$course = $_POST['course'];
$no = $_POST['days'];
$date = date("Y/m/d");
echo $days;
if(isset($_POST['submit']) && !isset($_POST['calculate']) && !isset($_POST['view'])){
if($year == '1st')
$roll = 1400000;
else if($year == '2nd')
$roll = 1300000;
if($dept == 'cse')
$roll = $roll + 7000;
else if($dept == 'eee')
$roll = $roll + 3000;
$i = 1;
echo '<tr><th>Attendence Form:</th></tr>';
while($i <= 10){
$roll = $roll + 1;
echo '<tr> <td> <input type = "checkbox" value = "'. $roll . '" name = "present[]">'.$roll.'</input> </td></tr>';
$i++;
}
?>
<td>
<input type = "submit" name = "calculate" value = "Calculate" />
</td>
<?php
}
else if(isset($_POST['calculate'])){
$dbc = mysqli_connect('localhost', 'root', '', 'rankodatabase')
or die('Error connecting database');
foreach($_POST['present'] as $p){
$query1 = "SELECT * FROM attendence WHERE roll = '$p' AND course = '$course'";
$result1 = mysqli_query($dbc, $query1)
or die('Error in select query1');
$p_days = 0;
while($row = mysqli_fetch_array($result1)){
$p_days++;
echo 'roll'. $row['roll'] . ' course' . $row['course'] . ' date' . $row['date'] . ' percentage' . $row['percentage'] . '<br />';
}
echo 'Lecture' . $no;
/*$percentage = ($p_days / $no_of_lecture) * 100;
$query2 = "INSERT INTO attendence VALUES('$p', '$course', '$date', '$percentage')";
$result2 = mysqli_query($dbc, $query2)
or die('Error in insert query2'); */
}
//$query = "INSERT INTO attendence VALUES('"
}
?>
</table>
</form>
</body>
</html>
HI I NEED YOUR HELP..
I have this VIEW which show all items according to its company
<?php foreach($item_list as $item2):?>
<tr>
<input type = "hidden" name = "status[]" value ="5" >
<td><input type = "text" name = "item_id[]" value ="<?php echo $item2->item_id ?>" ></td>
<td><?php echo $item2->item_desc?></td>
<td><?php echo $item2->serial_num ?></td>
<td><input type = "checkbox" name = "JobStatus[]" value = "quotation" ></td>
<td><input type = "checkbox" name = "JobStatus[]" value = "job order" ></td>
</tr>
<?php endforeach; ?>
---------------------------------------- html output ---------------------------------------
<tr>
<input type = "hidden" name = "status[]" value ="5" >
<td><input type = "text" name = "item_id[]" value ="146" ></td>
<td>sample item 01</td>
<td>123</td>
<td><input type = "radio" name = "JobStatus[]" value = "quotation" ></td>
<td><input type = "radio" name = "JobStatus[]" value = "job order" ></td>
</tr>
<tr>
<input type = "hidden" name = "status[]" value ="5" >
<td><input type = "text" name = "item_id[]" value ="147" ></td>
<td>sample item 02</td>
<td>21344</td>
<td><input type = "radio" name = "JobStatus[]" value = "quotation" ></td>
<td><input type = "radio" name = "JobStatus[]" value = "job order" ></td>
</tr>
My problem is that I want to insert this to new value (status, item_id, item_desc, serial_num, JobStatus) to quotation table in mysql. If Click I on radio item_id 146 row it will insert all values under item_id 146 likewise to item_id 147 it will insert all item values under 147 item_id
So you want the radio button to be checked according to it's job status?????
If so, try something along these lines ( i don't know how your your database is set up so you will have to alter the following):
<?php foreach($query as $item):?>
<td><input type = "text" name = "item_id" value ="<?php echo $item->item_id ?>" ></td>
<td><?php echo $item->item_desc?></td>
<td><?php echo $item->serial_num ?></td>
<td><input type="radio" name="JobStatus" value="quotation" <?php $item->job_status == 'quotation' ? echo "checked" : null; ?> ></td>
<td><input type="radio" name="JobStatus" value="job order" <?php $item->job_status == 'job order' ? echo "checked" : null; ?> ></td>
</tr>
<?php endforeach; ?>
Enclose the whole loop inside a form tag with action="index.php/controller/method"
In your controller,
public function method() {
$items = $this->input->post('item_id', TRUE);
$job_status = $this->input->post('JobStatus', TRUE);
$stati = $this->input->post('status', TRUE);
foreach($items as $key => $row) {
$this->your_model->insert_new($row, $job_status[$key], $stati[$key]);
}
}
In your_model, write the database query to insert these data wherever you need. Of course you need to change the names - method, controller and your_model to suit your application.