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
}
Related
Ihave a problem when i want to view a data row in details. Below is the flow of the system:
1) At dashboard_engineer.php, there's 3 select options which is team, time from and time to.
2) user need to select 3 select option and press button "Search" to display the result.
3) The result will display at dashboard_engineer2.php.
4) The result will display all data rows and each row contains one View button which can view a data row in detail.
My problem is only in the first data row. When I click button View', it will redirect to dashboard_engineer2.php with empty data. But for the second data and next, I can view the details of selected data.
This only happen only at the first data that display after filtered. Below is my code.
dashboard_engineer.php
<?php
$smt = $conn->prepare("
SELECT *
FROM ot_team t
JOIN ot_users u
ON t.team_id = u.team_id
WHERE u.roles_id = 7
AND u.team_id <> 1
ORDER
BY u.fullname ASC
");
$smt->execute();
$data = $smt->fetchAll();
?>
<form method = 'post' action = 'dashboard_engineer2.php' >
<td width="40%">
<select class="form-control" name="team" id="team" required>
<option value="">Please select...</option>
<?php foreach ($data as $row2): ?>
<option value= <?php echo $row2["team_id"]; ?> ><?php echo $row2["fullname"]; ?></option>
<?php endforeach ?>
</select>
</td>
<td width="1%"></td>
<td width="20%"><input type="text" name="from" id="from" class="form-control" placeholder="From" required></td>
<td width="1%"></td>
<td width="20%"><input type="text" name="to" id="to" class="form-control" placeholder="To" required></td>
<td width="1%"></td>
<td width="10%"><button type="submit" value="Search" class="btn btn-primary" >Send</button><td>
</form>
<script>
$(document).ready(function(){
$.datepicker.setDefaults({
dateFormat: 'yy-mm-dd'
});
$(function(){
$("#from").datepicker().attr("autocomplete", "off");;
$("#to").datepicker().attr("autocomplete", "off");;
});
});
</script>
dashboard_engineer2.php
<?php
if(isset($_REQUEST["from"], $_REQUEST["to"], $_REQUEST["team"])){
$from = $_REQUEST['from'];
$to = $_REQUEST['to'];
$team = $_REQUEST['team'];
$result = '';
$query = "
SELECT *
FROM ot_report r
LEFT
JOIN ot_users u
ON r.badgeid = u.badgeid
WHERE u.team_id = '".$team."'
AND report_date BETWEEN '".$from."' AND '".$to."'
ORDER
BY r.report_id DESC
";
$sql = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
$sql -> execute();
if($sql->rowCount() > 0){
echo'
<table class = "table-bordered" width = "100%">
<thead>
<tr>
<th width = "10%"><input type="checkbox" id="checkAl"> All</th>
<th width = "3%">id</th>
<th width = "15%">Date</th>
<th width = "30%">Task Name</th>
<th width = "10%">Status</th>
<th colspan = "2" width = "7%">Action</th>
</tr>
</thead>
<tbody>';
$i=0;
while($row = $sql->fetch(PDO::FETCH_ASSOC)){
$datereport = $row['report_date'];
$datereport2 = strtotime($datereport);
$report_date = date('d M Y', $datereport2);
$report_id = $row["report_id"];
echo'<tr>';
echo '<td><input type="checkbox" id="checkItem" name="check[]" value='.$row['report_id'].'></td>';
echo '<td>'.$report_id.'</td>';
echo '<td>'.$report_date.'</td>';
echo '<td>'.$row["task_name"].'</td>';
echo '<td align="center"><strong>'.$row["report_status"].'</strong></td>';
echo '<td align="center">';
echo '<form action = "view_task/view_task.php" method = "post">';
echo '<input type = "hidden" name = "report_id" value = "'.$report_id.'">';
echo '<button type = "submit" class="btn-primary">View</button>';
echo '</form>';
echo "<form action = 'delete.php' method = 'post' onClick=\"return confirm('Do you want to remove team?')\">";
echo '<input type = "hidden" name = "from" value = "'.$from.'">';
echo '<input type = "hidden" name = "to" value = "'.$to.'">';
echo '<input type = "hidden" name = "team" value = "'.$team.'">';
echo '<input type = "hidden" name = "report_id" value = "'.$report_id.'">';
echo '<button type = "submit" class="btn-danger">Delete</button>';
echo '</form>';
echo '</td>';
echo '</tr>';
$i++;
}
echo '<tr>';
echo '<td><p align="center"><button type="submit" class="btn-danger btn-sm" name="save">DELETE</button></p></td>';
echo '</tr>';
echo '</form>';
}
else
{
echo '
<table class = "table-bordered" width = "100%">
<thead>
<tr>
<th width = "5%">id</th>
<th width = "12%">Date</th>
<th width = "23%">Task Name</th>
<th width = "10%">Status</th>
<th width = "7%">Action</th>
</tr>
<tr>
<td colspan="5">No report found</td>
</tr>';
}
echo '</body></table></div></div>';
}
?>
view_task.php
<?php
require_once "../../../../config/configPDO.php";
require_once "../../../../config/check.php";
if (isset ($_POST['report_id'])) {
$report_id = $_POST['report_id'];
}else if (isset ($_GET['report_id'])) {
$report_id = $_GET['report_id'];
}else {
die ("ID NOT DEFINED");
}
$sql = "SELECT * FROM ot_report LEFT JOIN ot_users ON ot_report.badgeid = ot_users.badgeid LEFT JOIN ot_team ON ot_team.team_id = ot_users.team_id WHERE report_id = :report_id";
$query = $conn->prepare($sql);
$query->execute(array(':report_id' => $report_id));
while($row = $query->fetch(PDO::FETCH_ASSOC)){
$report_id = $row["report_id"];
$task_name = $row["task_name"];
}
?>
<form action="update_task_name.php" method="POST">
<td><b>Task Name</b></td>
<td colspan = '2'><input type="text" class="form-control" name="task_name" value="<?php echo $task_name; ?>"/></td> //line 50
<input type="hidden" name="report_id" value="<?php echo $report_id ?>">
<td><input type="submit" class="btn btn-primary btn-block" value = "Save" onclick="confirm('Are you sure?')"></td>
</form>
Can anyone help?
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 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 want to have the same drop down Hardware_ID in Adding new record form WHERE I get the data from another table for my Update form.
This is the example for my Update (Edit) form.
Update Form
And this is my Adding new record form.
Adding new record Form
this is my code for Update Form. Im using the same code like my adding new record but I got an error(The error is in the Update Form).
<?php
//get the data
$Asset_ID = $_GET['Asset_ID'];
$Hardware_ID = $_GET['Hardware_ID'];
$Vendor_ID = $_GET['Vendor_ID'];
$PO_ID = $_GET['PO_ID'];
?>
<form action = 'Update_Asset2_Process.php' method = 'POST'>
<table border = '1' align = 'center' cellspacing='0' cellpadding='10'
bgcolor = "White">
<tr>
<th colspan = '2'>ASSET UPDATE FORM</th>
</tr>
<tr>
<td align='center'>Asset ID :</td>
<td><input type = "varchar" name = "Asset_ID" value = "<?php echo
$Asset_ID; ?>" readonly></td>
</tr>
<tr>
<td align='center'> Hardware ID: </td>
<td><input type = "varchar" name = "Hardware_ID" value = "<?php echo
$Hardware_ID?>">
<?php
$query = "SELECT * FROM hardware2 ORDER BY Hardware_ID";
$result = mysql_query($query);
if(mysql_num_rows($result))
{
while ($id = mysql_fetch_row($result))
{
echo "<option value='" . $id[0] . "'>" . $id[0] . " : " .
$id[1] . " </option>";
}
}
?>
</select>
</tr>
<tr>
<td align='center'>Vendor ID :</td>
<td><input type = "varchar" name = "Vendor_ID" value = "<?php echo
$Vendor_ID; ?>"></td>
</tr>
<tr>
<td align='center'>PO ID :</td>
<td><input type = "varchar" name = "PO_ID" value = "<?php echo $PO_ID; ?
>"></td>
</td>
</tr>
<tr>
<td colspan = '2' align = 'right'>
<input type = 'submit' name = 'submit' value = 'UPDATE'>
</td>
</tr>
Back to Asset
</table>
</form>
thanks for your help, Regards
Wrong select box syntax
<?php
//get the data
$Asset_ID = isset($_GET['Asset_ID']) ? $_GET['Asset_ID'] : 0;
$Hardware_ID = isset($_GET['Hardware_ID']) ? $_GET['Hardware_ID'] : 0;
$Vendor_ID = isset($_GET['Vendor_ID']) ? $_GET['Vendor_ID'] : 0;
$PO_ID = isset($_GET['PO_ID']) ? $_GET['PO_ID'] : 0;
?>
<form action = 'Update_Asset2_Process.php' method = 'POST'>
<table border = '1' align = 'center' cellspacing='0' cellpadding='10' bgcolor = "White">
<tr>
<th colspan = '2'>ASSET UPDATE FORM</th>
</tr>
<tr>
<td align='center'>Asset ID :</td>
<td><input type = "varchar" name = "Asset_ID" value = "<?php echo $Asset_ID; ?>" readonly></td>
</tr>
<tr>
<td align='center'> Hardware ID: </td>
<td><input type = "varchar" name = "Hardware_ID" value = "<?php echo $Hardware_ID?>">
<select id="Your_id" name="Your_name">
<?php
$query = "SELECT * FROM hardware2 ORDER BY Hardware_ID";
$result = mysql_query($query);
if(mysql_num_rows($result))
{
while ($id = mysql_fetch_row($result))
{
echo "<option value='".$id[0]."'>".$id[0]." : ".$id[1]."</option>";
}
}
?>
</select>
</tr>
<tr>
<td align='center'>Vendor ID :</td>
<td><input type = "varchar" name = "Vendor_ID" value = "<?php echo $Vendor_ID; ?>" /></td>
</tr>
<tr>
<td align='center'>PO ID :</td>
<td><input type = "varchar" name = "PO_ID" value = "<?php echo $PO_ID; ?>" /></td>
</td>
</tr>
<tr>
<td colspan = '2' align = 'right'>
<input type = 'submit' name = 'submit' value = 'UPDATE'>
</td>
</tr>
Back to Asset
</table>
</form>
Maybe no need the select box in this form
<?php
//get the data
$Asset_ID = isset($_GET['Asset_ID']) ? $_GET['Asset_ID'] : 0;
$Hardware_ID = isset($_GET['Hardware_ID']) ? $_GET['Hardware_ID'] : 0;
$Vendor_ID = isset($_GET['Vendor_ID']) ? $_GET['Vendor_ID'] : 0;
$PO_ID = isset($_GET['PO_ID']) ? $_GET['PO_ID'] : 0;
?>
<form action = 'Update_Asset2_Process.php' method = 'POST'>
<table border = '1' align = 'center' cellspacing='0' cellpadding='10' bgcolor = "White">
<tr>
<th colspan = '2'>ASSET UPDATE FORM</th>
</tr>
<tr>
<td align='center'>Asset ID :</td>
<td><input type = "varchar" name = "Asset_ID" value = "<?php echo $Asset_ID; ?>" readonly></td>
</tr>
<tr>
<td align='center'> Hardware ID: </td>
<td><input type = "varchar" name = "Hardware_ID" value = "<?php echo $Hardware_ID?>">
</tr>
<tr>
<td align='center'>Vendor ID :</td>
<td><input type = "varchar" name = "Vendor_ID" value = "<?php echo $Vendor_ID; ?>" /></td>
</tr>
<tr>
<td align='center'>PO ID :</td>
<td><input type = "varchar" name = "PO_ID" value = "<?php echo $PO_ID; ?>" /></td>
</td>
</tr>
<tr>
<td colspan = '2' align = 'right'>
<input type = 'submit' name = 'submit' value = 'UPDATE'>
</td>
</tr>
Back to Asset
</table>
</form>
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>