I have created a dynamic form and I am trying to send the form data to mysql through PHP but its not working. Data is not getting sent even from the very first row without adding a dynamic row. I'm new to this topic, so I'm out of ideas to solve it. How can I make this form a correct one and send accurate data to mysql?
In my form I have 3 fields that are not dynamic.
Here is the form code:
<form name="newbillform" method="POST" action="save_purchase_details.php">
<table style=" border:1px solid black" cellpadding="5px" cellspacing="0px" align="center" border="0">
<tr>
<td colspan="4" style="background:#0066FF; color:#FFFFFF; fontsize:20px" align="center">
ADD NEW PURCHASE RECORD
</td>
</tr>
<tr>
<td>Date:</td>
<td>
<input type="date" name="p_date"/>
</td>
</tr>
<tr>
<td>Invoice Number:</td>
<td>
<input type="text" name="invoice_no" size="50">
</td>
</tr>
<tr>
<td>Balance:</td>
<td>
<input type="text" name="balance" size="50">
</td>
</tr>
</table>
<h2 style="padding-left:10px;">Enter Product Details Below:-</h2>
<table id="product_details" style="margin-top:8px;" align='center' border='1' width="900px">
<tr id="row1">
<td>
<input type="text" name="qty[]" value="" placeholder="Quantity" size="6">
</td>
<td>
<input type="text" name="pack[]" value="" placeholder="Pack" size="6">
</td>
<td>
<input type="text" name="item_name[]" value="" placeholder="Item Name" size="16">
</td>
<td>
<input type="text" name="batch[]" value="" placeholder="Batch" size="6">
</td>
<td>
<input type="text" name="expiry[]" value="" placeholder="Expiry" size="6">
</td>
<td>
<input type="text" name="mrp[]" value="" placeholder="M.R.P" size="6">
</td>
<td>
<input type="text" name="rate[]" value="" placeholder="Rate" size="6">
</td>
<td>
<input type="text" name="vat[]" value="" placeholder="VAT" size="6">
</td>
<td>
<input type="text" name="discount[]" value="" placeholder="Discount" size="6">
</td>
<td>
<input type="button" class="button-add-row" onclick="add_row();" value="ADD ROW" size="8">
</td>
</tr>
</table>
<center>
<input type="submit" name="submit_row" value="SUBMIT">
</center>
</form>
Here is the javascript code:
<script type="text/javascript">
function add_row()
{
$rowno = $("#product_details tr").length;
$rowno = $rowno + 1;
$("#product_details tr:last").after("<tr id='row"+$rowno+"'><td><input type='text' name='qty[]' placeholder='Quantity' size='6'></td><td><input type='text' name='pack[]' placeholder='Pack' size='6'></td><td><input type='text' placeholder='Item Name' name='item_name[]' size='16'></td><td><input type='text' name='batch[]' placeholder='Batch' size='6'></td><td><input type='text' name='expiry[]' placeholder='Expiry' size='6'></td><td><input type='text' name='mrp[]' placeholder='M.R.P' size='6'></td><td><input type='text' name='rate[]' placeholder='Rate' size='6'></td><td><input type='text' name='vat[]' placeholder='VAT' size='6'></td><td><input type='text' name='discount[]' placeholder='Discount' size='6'></td><td><input type='button' class='button-add-row' value='DELETE' onclick=delete_row('row"+$rowno+"')></td></tr>");
}
function delete_row(rowno)
{
$('#'+rowno).remove();
}
</script>
Here is the PHP code:
<?php
$connect = mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("store_records",$connect) or die(mysql_error());
if(isset($_POST['submit_row']))
{
$amount;
$grand_total;
for($i = 0; $i < count($_POST['item_name']); $i++)
{
$qty = $_POST['qty'][$i];
$p_date = $_POST['p_date'];
$invoice_no = $_POST['invoice_no'];
$balance = $_POST['balance'];
$pack = $_POST['pack'][$i];
$item_name = $_POST['item_name'][$i];
$batch = $_POST['batch'][$i];
$expiry = $_POST['expiry'][$i];
$mrp = $_POST['mrp'][$i];
$rate = $_POST['rate'][$i];
$vat = $_POST['vat'][$i];
$discount = $_POST['discount'][$i];
$amount = $balance+($qty*$rate)-$discount;
$grand_total = $amount+(($amount*$vat)/100);
$query =mysql_query("insert into bill_records values('', '$p_date', '$invoice_no', '$balance', '$qty','$pack','$item_name', '$batch', '$expiry', '$mrp', '$rate', '$vat', '$discount', '$amount', '$grand_total')");
}
}
?>
It would be of great help. Thank You..
So I volunteered to create a user form at work and thought I'd add a fun little twist and do it in HTML/CSS/PHP/mySQL rather than MS word.
Basically, this is a form I'll be using to add and delete user from my database. I've already finished the initial form, created a PHP file to save everything in my database and linked it properly.
My question is, how do I create a page with a drop down list of all Names/Last Names/IDs where the person browsing it could click "submit" and get all the information about the user?
I've been googling for hours now, but to no avail as it seems that some people have similar problems, but are missing some large puzzle piece that I need as well.
I know it sounds a bit confusing, so here's my code so that you can get a better idea:
HTML:
#charset "UTF-8";
table,
th,
td {} table {
border-collapse: collapse;
}
td {
padding: 3px;
}
input[type="text"],
textarea {
background-color: #F8FCFF;
border: 2px solid #eeeeee;
color: #333333;
font-size: 0.9em;
font-style: normal;
font-weight: 400;
font-family: Tahoma;
Helvetica;
}
body {
background-color: #e6e6e6;
margin: 0 auto;
}
f {
font-style: normal;
font-weight: 550;
font-family: sans-serif;
source-sans-pro;
}
bigbold {
font-style: normal;
font-weight: bold;
font-size: 20px;
font-family: sans-serif;
source-sans-pro;
}
info {
font-style: normal;
font-weight: bold;
font-family: sans-serif;
source-sans-pro;
}
.tr-top {
border-top: 1pt solid black;
}
.tr-left {
border-left: 1pt solid black;
}
.td-left {
border-left: 1pt solid black;
width: 35%;
}
.checkboxes label {
display: block;
float: left;
padding-right: 10px;
white-space: nowrap;
}
.checkboxes input {
vertical-align: middle;
}
.checkboxes label span {
vertical-align: middle;
}
#body1 {
width: 1000px;
background: #fff;
height: 100%;
}
#wrapper {
max-width: 1000px;
height: 100%;
background: #fff;
margin: 0px auto 0;
padding: 20px;
}
#colour {
background: #C6DEFF;
}
</style>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled D
<!--#include file="NewUser_get.php" -->
ocument</title>
<link href="Untitled-4.css" rel="stylesheet" type="text/css">
</head>
<body>
<!--<div id="body1">-->
<div id="wrapper">
<div id="head">
<form action="NewUser_get.php" method="POST">
<table style="width:1000px">
<tr>
<td width=90%>
<f>Request date:</f>
<br>
<input type="date" name="RequestDate">
</td>
<td width=10%>
<f>Requested by:</f>
<br>
<input type="text" style="width: 166px;" name="RequestBy">
</td>
</tr>
</table>
<br>
<div id="colour">
<info>
<center>New User Info</center>
</info>
</div>
<br>
<table style="width:100%">
<tr>
<td>
<f>Employee's last name: </f>
<input type="text" placeholder="Click to type" name="LastName">
</td>
<td>
<f>First name
<input type="text" placeholder="Click to type" name="FirstName">
</td>
<td>
<f>Middle name
<input type="text" placeholder="Click to type" name="MiddleName">
</td>
<td>
<f>Employment type
<select name="EmploymentType">
<option value="Permanent">Permanent</option>
<option value="Temporary">Temporary</option>
<option value="Contractor">Contractor</option>
<option value="Placement">Placement</option>
<option value="Other">Other</option>
</select>
</td>
<td width="80px">
<f> Gender</f>
<br>
<label for="GenderMale">
<input type="checkbox" name="GenderMale" value="Yes" /> <span>M</span>
</label>
<label for="GenderFemale">
<input type="checkbox" name="GenderFemale" value="Yes" /> <span>F</span>
</label>
</td>
</tr>
<tr>
<td>
<f>Department </f>
<br>
<input type="text" placeholder="Click to type" name="Department1">
</td>
<td>
<f>Job title </f>
<input type="text" placeholder="Click to type" name="JobTitle">
</td>
<td>
<f>Manager's name </f>
<input type="text" placeholder="Click to type" name="ManagerName">
</td>
<td>
<f>Start date </f>
<br>
<input type="date" placeholder="Click to type" name="StartDate">
</td>
<td>
<f>Finish date </f>
<input type="date" style="width: 166px;" name="FinishDate">
</td>
</tr>
</table>
<br>
<table style="width:100%">
<tr>
<td>
<f>Full address:</f>
<br>
<input type="text" style="width: 992px;" placeholder="Click to type, Address/ P.O. Box, City, Street, Post code" name="FullAddress">
</td>
</tr>
</table>
<br>
<table style="width:100%">
<tr>
<td>
<f>User Group / Profile to Use:</f>
<input type="text" style="width: 325px;" placeholder="Click to type, e.g. same as John, Accounts" name="UserGroup">
</td>
<td>
<f>Distribution Groups to be included:</f>
<input type="text" style="width: 325px;" placeholder="Click to type, e.g. Staff, Internal, External" name="DistributionGroup">
</td>
<td>
<f>Shared Drive Access:</f>
<input type="text" style="width: 325px;" placeholder="Click to type" name="SharedDriveAccess">
</td>
</tr>
</table>
<br>
<table style="width:100%">
<tr>
<td>
<f>Permissions on shared drives (in detail):</f>
<br>
<input type="text" style="width: 993px;" placeholder="Click to type, e.g. Marketing drive 'read only, Technical drive 'Full Access'" name="Permissions">
</td>
</tr>
</table>
<br>
<div id="colour">
<info>
<center>Additional Info</center>
</info>
</div>
<br>
<div class="checkboxes">
<table style="width:100%">
<tr>
<td width="%50">
<bigbold>List of required items (Tick the box next to an item):</bigbold>
</td>
<td> </td>
<td class="td-left" width="%50">
<bigbold>List of required software/drive access:</bigbold>
</td>
</tr>
<tr>
<td></td>
<td></td>
<td class="td-left">
<info> Drives:</info>
</td>
<td>
<info> Software:</info>
</td>
</tr>
<tr>
<td>
<label for="iPad">
<input type="checkbox" name="iPad" value="Yes"> <span><f>iPad + case</f></span>
</label>
</td>
<td>
<label for="Mouse">
<input type="checkbox" name="Mouse" value="Yes"> <span><f>Mouse</f></span>
</label>
</td>
<td class="td-left">
<label for="Sales">
<input type="checkbox" name="Sales" value="Yes"><span><f>Sales</f></span>
</label>
</td>
<td>
<label for="Salesforce">
<input type="checkbox" name="Salesforce" value="Yes"> <span><f>Salesforce</f></span>
</label>
</td>
</tr>
<tr>
<td>
<label for="iPhone">
<input type="checkbox" name="iPhone" value="Yes"> <span><f>iPhone + case</f></span>
</label>
</td>
<td>
<label for="Laptopb">
<input type="checkbox" name="Laptopb" value="Yes"> <span><f>Laptop bag</f></span>
</label>
</td>
<td class="td-left">
<label for="Marketing">
<input type="checkbox" name="Marketing" value="Yes"> <span><f>Marketing</f></span>
</label>
</td>
<td>
<label for="VPN">
<input type="checkbox" name="VPN" value="Yes"> <span><f>VPN</f></span>
</label>
</td>
</tr>
<tr>
<td>
<label for="Laptop">
<input type="checkbox" name="Laptop" value="Yes"> <span><f>Laptop</f></span>
</label>
</td>
<td>
<label for="Dphone">
<input type="checkbox" name="Dphone" value="Yes"> <span><f>Desk phone</f></span>
</label>
</td>
<td class="td-left">
<label for="General">
<input type="checkbox" name="General" value="Yes"> <span><f>General</f></span>
</label>
</td>
<td>
<label for="Terminal">
<input type="checkbox" name="Terminal" value="Yes"> <span><f>Terminal server</f></span>
</label>
</td>
</tr>
<tr>
<td>
<label for="Desktop">
<input type="checkbox" name="Desktop" value="Yes" /> <span><f>Desktop</f></span>
</label>
</td>
<td>
<label for="Printerw">
<input type="checkbox" name="Printerw" value="Yes"> <span><f>Printer (work)</f></span>
</label>
</td>
<td class="td-left">
<label for="CAD">
<input type="checkbox" name="CAD" value="Yes"> <span><f>CAD</f></span>
</label>
</td>
</tr>
<tr>
<td>
<label for="Printerh">
<input type="checkbox" name="Printerh" value="Yes"> <span><f>Printer (home)</f></span>
</label>
</td>
<td>
<label for="Dongle">
<input type="checkbox" name="Dongle" value="Yes"> <span><f>Dongle</f></span>
</label>
</td>
<td class="td-left">
<label for="Finance">
<input type="checkbox" name="Finance" value="Yes"> <span><f>Finance</f></span>
</label>
</td>
</tr>
<tr>
<td>
<label for="Monitor">
<input type="checkbox" name="Monitor" value="Yes"> <span><f>Monitor</f></span>
</label>
</td>
<td>
<label for="MiFi">
<input type="checkbox" name="Mifi" value="Yes"> <span><f>MiFi (Mobile Wifi)</f></span>
</label>
</td>
<td class="td-left">
<label for="Accounts">
<input type="checkbox" name="Accounts" value="Yes"> <span><f>Accounts</f></span>
</label>
</td>
<td></td>
</tr>
<tr>
<td>
<label for="Keyboard">
<input type="checkbox" name="Keyboard" value="Yes"> <span><f>Keyboard</f></span>
</label>
</td>
<td></td>
<td class="td-left"></td>
<td></td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</table>
<div id="colour">
<center>
<info>Miscellaneous:</info>
</center>
</div>
<br>
<table style="width:100%">
<tr>
<td>
<f>Should the predecessor's email be assigned to this user?</f>
</td>
<td>
<label for="Pemail">
<input type="checkbox" name="Pemail" value="Yes"> <span><f>Yes</f></span>
</label>
</td>
</tr>
<tr class="tr-top">
<td>
<f>Is the user replacing someone else from the staff or is he/she a completely new employee?</f>
</td>
<td>
<label for="Replacement">
<input type="checkbox" name="Replacement" value="Yes"> <span><f>Replacement</f></span>
</label>
</td>
<td>
<label for="NewUser">
<input type="checkbox" name="NewUser" value="Yes"> <span><f>New user</f></span>
</label>
</td>
</tr>
</table>
<br>
<textarea name="AddRequirements" style="width:1000px;" placeholder="Please continue here for any other extra requirements e.g. need of a special signature, software, hardware etc. or needed access to another user’s files and documents, or assign another user’s email profile to this user so they inherit all files and folders form the old user."></textarea>
<!--<input type='hidden' name='articleid' id='articleid' value='<? echo $_GET["id"]; ?>' /> -->
<input type="submit">
</form>
</div>
</div>
</body>
</html>
PHP:
<?php
if( $_POST )
{
$conn = mysqli_connect("myhost","myuser","mypassword", "mydb");
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$RequestBy = $_POST['RequestBy'];
$FirstName = $_POST['FirstName'];
$MiddleName = $_POST['MiddleName'];
$LastName = $_POST['LastName'];
$Desktop = $_POST['Desktop'];
$EmploymentType = $_POST['EmploymentType'];
$GenderMale = $_POST['GenderMale'];
$GenderFemale = $_POST['GenderFemale'];
$Department1 = $_POST['Department1'];
$JobTitle = $_POST['JobTitle'];
$ManagerName = $_POST['ManagerName'];
$FullAddress = $_POST['FullAddress'];
$UserGroup = $_POST['UserGroup'];
$DistributionGroup = $_POST['DistributionGroup'];
$SharedDriveAccess = $_POST['SharedDriveAccess'];
$Permissions = $_POST['Permissions'];
$iPad = $_POST['iPad'];
$Mouse = $_POST['Mouse'];
$Sales = $_POST['Sales'];
$Salesforce = $_POST['Salesforce'];
$iPhone = $_POST['iPhone'];
$Laptopb = $_POST['Laptopb'];
$Marketing = $_POST['Marketing'];
$VPN = $_POST['VPN'];
$Laptop = $_POST['Laptop'];
$Dphone = $_POST['Dphone'];
$General = $_POST['General'];
$Terminal = $_POST['Terminal'];
$Printerw = $_POST['Printerw'];
$CAD = $_POST['CAD'];
$Printerh = $_POST['Printerh'];
$Dongle = $_POST['Dongle'];
$Finance = $_POST['Finance'];
$Monitor = $_POST['Monitor'];
$Mifi = $_POST['Mifi'];
$Accounts = $_POST['Accounts'];
$Keyboard = $_POST['Keyboard'];
$Pemail = $_POST['Pemail'];
$Replacement = $_POST['Replacement'];
$NewUser = $_POST['NewUser'];
$AddRequirements = $_POST['AddRequirements'];
}
$sql= "
INSERT INTO TestTable (RequestBy, FirstName, MiddleName, LastName, Desktop, EmploymentType, GenderMale, GenderFemale, Department1, JobTitle, ManagerName, FullAddress, UserGroup, DistributionGroup, SharedDriveAccess, Permissions, iPad, Mouse, Sales, Salesforce, iPhone, Laptopb, Marketing, VPN, Laptop, Dphone, General, Terminal, Printerw, CAD, Printerh, Dongle, Finance, Monitor, Mifi, Accounts, Keyboard, Pemail, Replacement, NewUser, AddRequirements) VALUES ('$RequestBy', '$FirstName', '$MiddleName', '$LastName', '$Desktop', '$EmploymentType', '$GenderMale', '$GenderFemale', '$Department1', '$JobTitle', '$ManagerName', '$FullAddress', '$UserGroup', '$DistributionGroup', '$SharedDriveAccess', '$Permissions', '$iPad', '$Mouse', '$Sales', '$Salesforce', '$iPhone', '$Laptopb', '$Marketing', '$VPN', '$Laptop', '$Dphone', '$General', '$Terminal', '$Printerw', '$CAD', '$Printerh', '$Dongle', '$Finance', '$Monitor', '$Mifi', '$Accounts', '$Keyboard', '$Pemail', '$Replacement', '$NewUser', '$AddRequirements');";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>
Basically I want to create another page where I could select the user's name, click some button, and then see all the information such as access to "sales" drive, gender, etc. displayed.
Ignore the lack of security measures in the code, it'll be used on a local server by very few and trustworthy people.
If somebody could just guide me on the right path, it'd be much appreciated. Thank you in advance.
It seems to need a bit of AJAX to accomplish this.
At first, you need to make the php file containing the select box. Note, that you have to include jquery at html .
In select_user.php
<?php
//Connection to database
$connection = mysqli_connect('localhost', 'root', 'your_password', 'your_database');
mysqli_set_charset($connection, 'utf8');
if (!$connection) {
die("Database connection failed: " . mysqli_error());
}
//Simple query to populate the select box
$query = "SELECT id, FirstName, LastName FROM TestTable ORDER BY FirstName ASC, LastName ASC, id ASC;";
$result = mysqli_query($connection, $query);
if (mysqli_num_rows($result) > 0) { //If there are records in database table
echo '<select id="user" name="user">';
while ($row = mysqli_fetch_array($result)) {
echo '<option value="'.$row['id'].'">'.$row['FirstName'].' '.$row['LastName'].'</option>';
}
echo '</select>';
} else {
echo '<p class="alert">There are no data to select from.</p>';
}
?>
<div id="results">
</div>
Then you have to write some AJAX asking the server to fetch the user with the selected id (note that normally you have to be very careful with user inputs).
At the bottom of select_user.php
<script>
$(document).ready(function(){
//Each time that the value of select box changes then make an ajax call and bring the user details
$('#user').on('change', function() {
var id = $(this).val();
$.ajax({
async: false,
url: "ajax.php",
type: "POST",
data: {id : id},
dataType: "json",
success: function(data) {
//Check if data is empty or make some other validations
var firstName = data.FirstName;
var lastName = data.LastName;
var fullAddress = data.FullAddress;
var permissions = data.Permissions;
var str = '<p>Name: '+firstName+' '+lastName+' '+fullAddress+' '+permissions+'</p>';
//Replace content at #results div
$('#results').innerHtml(str);
}
});
}
}
</script>
Finally, you have to create the file ajax.php which contains the query that brings back the details of the selected user.
In file ajax.php
<?php
//This is ajax.php
//Connection to database
$connection = mysqli_connect('localhost', 'root', 'your_password', 'your_database');
mysqli_set_charset($connection, 'utf8');
if (!$connection) {
die("Database connection failed: " . mysqli_error());
}
$id = $_POST['id'];
//Never trust input from users
//Sanitize and validate variables
//Use prepared statemends or PDO
$query = "SELECT id, FirstName, LastName, FullAddress, Permissions FROM TestTable WHERE id = '$id';";
$result = mysqli_query($connection, $query);
$row = mysqli_fetch_array($result);
$json['id'] = $row['id'];
$json['firstName'] = $row['FirstName'];
$json['lastName'] = $row['LastName'];
$json['fullAddress'] = $row['FullAddress'];
$json['permisions'] = $row['Permissions'];
echo json_encode($json);
mysqli_close($connection);
?>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</head>
<?php
//Connection to database
$connection = mysqli_connect("*****************","***********","****", "******");
mysqli_set_charset($connection, 'utf8');
if (!$connection) {
die("Database connection failed: " . mysqli_error());
}
//Simple query to populate the select box
$query = "SELECT id, FirstName, LastName FROM TestTable ORDER BY FirstName ASC, LastName ASC, id ASC;";
$result = mysqli_query($connection, $query);
if (mysqli_num_rows($result) > 0) { //If there are records in database table
echo '<select id="user" name="user">';
while ($row = mysqli_fetch_array($result)) {
echo '<option value="'.$row['id'].'">'.$row['FirstName'].' '.$row['LastName'].'</option>';
}
echo '</select>';
} else {
echo '<p class="alert">There are no data to select from.</p>';
}
?>
<div id="results">
</div>
<script>
$(document).ready(function(){
//Each time that the value of select box changes then make an ajax call and bring the user details
$('#user').on('change', function() {
var id = $(this).val();
$.ajax({
async: false,
url: "ajax.php",
type: "POST",
data: {id : id},
dataType: "json",
success: function(data) {
//Check if data is empty or make some other validations
var firstName = data.FirstName;
var lastName = data.LastName;
var fullAddress = data.FullAddress;
var permissions = data.Permissions;
var str = '<p>Name: '+firstName+' '+lastName+' '+fullAddress+' '+permissions+'</p>';
//Replace content at #results div
$('#results').innerHtml(str);
}
});
}
}
</script>
<div id="results">
</div>
This is the select_user.php file:
<?php
//Connection to database
$connection = mysqli_connect("****","****","****", "***");
mysqli_set_charset($connection, 'utf8');
if (!$connection) {
die("Database connection failed: " . mysqli_error());
}
//Simple query to populate the select box
$query = "SELECT id, FirstName, LastName FROM TestTable ORDER BY FirstName ASC, LastName ASC, id ASC;";
$result = mysqli_query($connection, $query);
if (mysqli_num_rows($result) > 0) { //If there are records in database table
echo '<select id="user" name="user">';
while ($row = mysqli_fetch_array($result)) {
echo '<option value="'.$row['id'].'">'.$row['FirstName'].' '.$row['LastName'].'</option>';
}
echo '</select>';
} else {
echo '<p class="alert">There are no data to select from.</p>';
}
?>
<div id="results">
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">
$(document).ready(function(){
//Each time that the value of select box changes then make an ajax call and bring the user details
$('#user').on('change', function() {
var id = $(this).val();
$.ajax({
async: false,
url: "ajax.php", //Tried changing this to domainname.com/ajax.php but that didn't change anything.
type: "POST",
data: {id : id},
dataType: "json",
success: function(data) {
//Check if data is empty or make some other validations
var firstName = data.FirstName;
var lastName = data.LastName;
var fullAddress = data.FullAddress;
var permissions = data.Permissions;
var str = '<p>Name: '+firstName+' '+lastName+' '+fullAddress+' '+permissions+'</p>';
//Replace content at #results div
$('#results').innerHtml(str);
}
});
}
}
</script>
<div id="results">
</div>
This is ajax.php:
<?php
//This is ajax.php
//Connection to database
$connection = mysqli_connect("******","******","*******", "*******");
mysqli_set_charset($connection, 'utf8');
if (!$connection) {
die("Database connection failed: " . mysqli_error());
}
$id = $_POST['id'];
//Never trust input from users
//Sanitize and validate variables
//Use prepared statemends or PDO
$query = "SELECT id, FirstName, LastName, FullAddress, Permissions FROM TestTable WHERE id = '$id';";
$result = mysqli_query($connection, $query);
$row = mysqli_fetch_array($result);
$json['id'] = $row['id'];
$json['firstName'] = $row['FirstName'];
$json['lastName'] = $row['LastName'];
$json['fullAddress'] = $row['FullAddress'];
$json['permisions'] = $row['Permissions'];
echo json_encode($json);
mysqli_close($connection);
?>
This is the HTML.
<!doctype html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<meta charset="utf-8">
<title>Untitled D
<!--#include file="NewUser_get.php" -->
ocument</title>
<link href="Untitled-4.css" rel="stylesheet" type="text/css">
</head>
<body>
<!--<div id="body1">-->
<div id="wrapper">
<div id="head">
<center>
<img src="http://www.rwc.com/wp-content/themes/RWC_Global/assets/images/logo.png">
</center>
<form action="NewUser_get.php" method="POST">
<table style="width:1000px">
<tr>
<td width=90%>
<f>Request date:</f>
<br>
<input type="date" name="RequestDate">
</td>
<td width=10%>
<f>Requested by:</f>
<br>
<input type="text" style="width: 166px;" name="RequestBy">
</td>
</tr>
</table>
<br>
<div id="colour">
<info>
<center>New User Info</center>
</info>
</div>
<br>
<table style="width:100%">
<tr>
<td>
<f>Employee's last name: </f>
<input type="text" placeholder="Click to type" name="LastName">
</td>
<td>
<f>First name
<input type="text" placeholder="Click to type" name="FirstName">
</td>
<td>
<f>Middle name
<input type="text" placeholder="Click to type" name="MiddleName">
</td>
<td>
<f>Employment type
<select name="EmploymentType">
<option value="Permanent">Permanent</option>
<option value="Temporary">Temporary</option>
<option value="Contractor">Contractor</option>
<option value="Placement">Placement</option>
<option value="Other">Other</option>
</select>
</td>
<td width="80px">
<f> Gender</f>
<br>
<label for="GenderMale">
<input type="checkbox" name="GenderMale" value="Yes" /> <span>M</span>
</label>
<label for="GenderFemale">
<input type="checkbox" name="GenderFemale" value="Yes" /> <span>F</span>
</label>
</td>
</tr>
<tr>
<td>
<f>Department </f>
<br>
<input type="text" placeholder="Click to type" name="Department1">
</td>
<td>
<f>Job title </f>
<input type="text" placeholder="Click to type" name="JobTitle">
</td>
<td>
<f>Manager's name </f>
<input type="text" placeholder="Click to type" name="ManagerName">
</td>
<td>
<f>Start date </f>
<br>
<input type="date" placeholder="Click to type" name="StartDate">
</td>
<td>
<f>Finish date </f>
<input type="date" style="width: 166px;" name="FinishDate">
</td>
</tr>
</table>
<br>
<table style="width:100%">
<tr>
<td>
<f>Full address:</f>
<br>
<input type="text" style="width: 992px;" placeholder="Click to type, Address/ P.O. Box, City, Street, Post code" name="FullAddress">
</td>
</tr>
</table>
<br>
<table style="width:100%">
<tr>
<td>
<f>User Group / Profile to Use:</f>
<input type="text" style="width: 325px;" placeholder="Click to type, e.g. same as John, Accounts" name="UserGroup">
</td>
<td>
<f>Distribution Groups to be included:</f>
<input type="text" style="width: 325px;" placeholder="Click to type, e.g. Staff, Internal, External" name="DistributionGroup">
</td>
<td>
<f>Shared Drive Access:</f>
<input type="text" style="width: 325px;" placeholder="Click to type" name="SharedDriveAccess">
</td>
</tr>
</table>
<br>
<table style="width:100%">
<tr>
<td>
<f>Permissions on shared drives (in detail):</f>
<br>
<input type="text" style="width: 993px;" placeholder="Click to type, e.g. Marketing drive 'read only, Technical drive 'Full Access'" name="Permissions">
</td>
</tr>
</table>
<br>
<div id="colour">
<info>
<center>Additional Info</center>
</info>
</div>
<br>
<div class="checkboxes">
<table style="width:100%">
<tr>
<td width="%50">
<bigbold>List of required items (Tick the box next to an item):</bigbold>
</td>
<td> </td>
<td class="td-left" width="%50">
<bigbold>List of required software/drive access:</bigbold>
</td>
</tr>
<tr>
<td></td>
<td></td>
<td class="td-left">
<info> Drives:</info>
</td>
<td>
<info> Software:</info>
</td>
</tr>
<tr>
<td>
<label for="iPad">
<input type="checkbox" name="iPad" value="Yes"> <span><f>iPad + case</f></span>
</label>
</td>
<td>
<label for="Mouse">
<input type="checkbox" name="Mouse" value="Yes"> <span><f>Mouse</f></span>
</label>
</td>
<td class="td-left">
<label for="Sales">
<input type="checkbox" name="Sales" value="Yes"><span><f>Sales</f></span>
</label>
</td>
<td>
<label for="Salesforce">
<input type="checkbox" name="Salesforce" value="Yes"> <span><f>Salesforce</f></span>
</label>
</td>
</tr>
<tr>
<td>
<label for="iPhone">
<input type="checkbox" name="iPhone" value="Yes"> <span><f>iPhone + case</f></span>
</label>
</td>
<td>
<label for="Laptopb">
<input type="checkbox" name="Laptopb" value="Yes"> <span><f>Laptop bag</f></span>
</label>
</td>
<td class="td-left">
<label for="Marketing">
<input type="checkbox" name="Marketing" value="Yes"> <span><f>Marketing</f></span>
</label>
</td>
<td>
<label for="VPN">
<input type="checkbox" name="VPN" value="Yes"> <span><f>VPN</f></span>
</label>
</td>
</tr>
<tr>
<td>
<label for="Laptop">
<input type="checkbox" name="Laptop" value="Yes"> <span><f>Laptop</f></span>
</label>
</td>
<td>
<label for="Dphone">
<input type="checkbox" name="Dphone" value="Yes"> <span><f>Desk phone</f></span>
</label>
</td>
<td class="td-left">
<label for="General">
<input type="checkbox" name="General" value="Yes"> <span><f>General</f></span>
</label>
</td>
<td>
<label for="Terminal">
<input type="checkbox" name="Terminal" value="Yes"> <span><f>Terminal server</f></span>
</label>
</td>
</tr>
<tr>
<td>
<label for="Desktop">
<input type="checkbox" name="Desktop" value="Yes" /> <span><f>Desktop</f></span>
</label>
</td>
<td>
<label for="Printerw">
<input type="checkbox" name="Printerw" value="Yes"> <span><f>Printer (work)</f></span>
</label>
</td>
<td class="td-left">
<label for="CAD">
<input type="checkbox" name="CAD" value="Yes"> <span><f>CAD</f></span>
</label>
</td>
</tr>
<tr>
<td>
<label for="Printerh">
<input type="checkbox" name="Printerh" value="Yes"> <span><f>Printer (home)</f></span>
</label>
</td>
<td>
<label for="Dongle">
<input type="checkbox" name="Dongle" value="Yes"> <span><f>Dongle</f></span>
</label>
</td>
<td class="td-left">
<label for="Finance">
<input type="checkbox" name="Finance" value="Yes"> <span><f>Finance</f></span>
</label>
</td>
</tr>
<tr>
<td>
<label for="Monitor">
<input type="checkbox" name="Monitor" value="Yes"> <span><f>Monitor</f></span>
</label>
</td>
<td>
<label for="MiFi">
<input type="checkbox" name="Mifi" value="Yes"> <span><f>MiFi (Mobile Wifi)</f></span>
</label>
</td>
<td class="td-left">
<label for="Accounts">
<input type="checkbox" name="Accounts" value="Yes"> <span><f>Accounts</f></span>
</label>
</td>
<td></td>
</tr>
<tr>
<td>
<label for="Keyboard">
<input type="checkbox" name="Keyboard" value="Yes"> <span><f>Keyboard</f></span>
</label>
</td>
<td></td>
<td class="td-left"></td>
<td></td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</table>
<div id="colour">
<center>
<info>Miscellaneous:</info>
</center>
</div>
<br>
<table style="width:100%">
<tr>
<td>
<f>Should the predecessor's email be assigned to this user?</f>
</td>
<td>
<label for="Pemail">
<input type="checkbox" name="Pemail" value="Yes"> <span><f>Yes</f></span>
</label>
</td>
</tr>
<tr class="tr-top">
<td>
<f>Is the user replacing someone else from the staff or is he/she a completely new employee?</f>
</td>
<td>
<label for="Replacement">
<input type="checkbox" name="Replacement" value="Yes"> <span><f>Replacement</f></span>
</label>
</td>
<td>
<label for="NewUser">
<input type="checkbox" name="NewUser" value="Yes"> <span><f>New user</f></span>
</label>
</td>
</tr>
</table>
<br>
<textarea name="AddRequirements" style="width:1000px;" placeholder="Please continue here for any other extra requirements e.g. need of a special signature, software, hardware etc. or needed access to another user’s files and documents, or assign another user’s email profile to this user so they inherit all files and folders form the old user."></textarea>
<!--<input type='hidden' name='articleid' id='articleid' value='<? echo $_GET["id"]; ?>' /> -->
<input type="submit">
</form>
</div>
</div>
</body>
</html>
Sorry for the late reply, was a bit caught up in things. Thank you for all the help, it just feels like I can't do much at this point because I quite literally can't understand where the issue lies.