Submit Data Array With JqueryAutoCalc - php

Submit to Database Success But Value Of Debit And Kredit are 0 and 1
<table>
<tr>
<td>
<input class="form-control" name="debit[]" type="text" placeholder="Debit" autocomplete="off" required />
</td>
<td>
<input class="form-control" name="Kredit[]" type="text" placeholder="Kredit" autocomplete="off" required />
</td>
</tr>
<tr>
<th>Total</th>
<th colspan="2">
<input class="form-control" name="total" type="text" jAutoCalc="{debit[]} + {kredit[]}" />
</th>
</table>
This is the error i receive
Parsing error:unrecognied value
(Error:valueNotParsed):<*>{debit[]}+{kredit[]}

Related

<input type="time" /> value doesn't insert in mysql db

I want to insert value in a database and it inserted empty. I want help for this necessary.
This is the variable of time :
$rm_time = $_POST['rm-time'];
PHP
if(empty($_POST['rm-name']) or empty($_POST['rm-details'])){
?>
<h3 style="margin-top: 30px;text-align: center;font-size: 25px;color: red;" dir="rtl">Error</h3>
<?php
}else{
$rm_name = $_POST['rm-name'];
$rm_details = $_POST['rm-details'];
$rm_date = $_POST['rm-date'];
$rm_time = $_POST['rm-time'];
$rm_insert_query = $db->query("INSERT INTO reminders (r_name, r_details, r_date, r_time) VALUES ('$rm_name', '$rm_details', '$rm_date', '$rm_time')");
}
}
?>
<form action="reminder.php?rm=make" method="post">
<table class="rm" width="auto" border="0px">
<tr>
<td class="rm-form-text">Reminder date/time :</td>
<td><input autofocus="" name="rm-date" type="date" id="rm" /> / <input name"rm-time" type="time" id="rm" /></td>
</tr>
<tr>
<td class="rm-form-text">Remimnder name :</td>
<td><input name="rm-name" type="text" id="rm" /></td>
</tr>
<tr>
<td class="rm-form-text">Reminder details :</td>
<td><textarea dir="rtl" name="rm-details" id="rm-ta"></textarea></td>
</tr>
<tr>
<td colspan="2"><input name="save-reminder" type="submit" class="sp-submit" value="Save!" /></td>
</tr>
</table>
</form>
<?
exit;
here your syntax is wrong.
Use
<input name= "rm-time" type="time" id="rm" />
instead of
<input name"rm-time" type="time" id="rm" />
change this
FROM : <input name"rm-time" type="time" id="rm" /></td>
TO : <input name="rm-time" type="time" id="rm" /></td>

How to update html repeated field values to mysql database

I have a html repeated values in array that i need to update to database, i need a help on how to use php script to update to database where staffid mataches . See below my HTML code
<!DOCTYPE html>
<html>
<head lang="en">
<meta chartaxt="UTF-8">
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<script src="js/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<title>Sample salary computation</title>
</head>
<body>
<form method="POST" name="regis" id="regis">
<table align="center" border="1" width="200">
<tr>
<th>Staff ID</th>
<th>Salary</th>
<th>Total Tax</th>
<th>Total Net Pay</th>
</tr>
<!--Staff 1-->
<tr data-id="STAFF/2016/001">
<td>
<input type="text" name="staffid[]" class="staffid" value="STAFF/2016/001" readonly="readonly">
</td>
<td>
<input type="text" name="salary[]" class="salary" placeholder="salary" value="5000">
</td>
<td>
<input type="text" name="tax[]" class="tax" placeholder="tax" value="500">
</td>
<td>
<input type="text" name="total[]" class="total" placeholder="total" readonly="readonly" value="4500">
</td>
</tr>
<!--Staff 2-->
<tr data-id="STAFF/2016/002">
<td>
<input type="text" name="staffid[]" class="staffid" value="STAFF/2016/002" readonly="readonly">
</td>
<td>
<input name="salary[]" class="salary" type="text" placeholder="salary" value="10000">
</td>
<td>
<input type="text" placeholder="tax" name="tax[]" class="tax" value="1000">
</td>
<td>
<input type="text" placeholder="total" class="total" name="total[]" readonly="readonly" value="9000">
</td>
</tr>
<!--Staff 3-->
<tr data-id="STAFF/2016/003">
<td>
<input type="text" name="staffid[]" class="staffid" value="STAFF/2016/003" readonly="readonly">
</td>
<td>
<input name="salary[]" class="salary" type="text" placeholder="salary" value="8400">
</td>
<td>
<input type="text" placeholder="tax" name="tax[]" class="tax" value="400">
</td>
<td>
<input type="text" placeholder="total" class="total" name="total[]" readonly="readonly" value="800">
</td>
</tr>
<tr>
<td width="300">
<input type="button" name="update" value="Update Values" class="btn btn-danger">
</td>
</tr>
</table>
</form>
</body>
</html>
Kindly assist. I want the SQL update query to look like
"Update payroll SET salary ='".$_POST['salary']."', tax='".$_POST['tax']."', total ='".$_POST['total']."' WHERE staffid= '".$_POST['staffid']."'"
I would recommend to rename the input names to create a single array with all the information you need. Use the staff ID as array keys.
<!--Staff 1-->
<tr data-id="STAFF/2016/001">
<td>
<input type="text" name="staff[STAFF/2016/001][id]" class="staffid" value="STAFF/2016/001" readonly="readonly">
</td>
<td>
<input type="text" name="staff[STAFF/2016/001][salary]" class="salary" placeholder="salary" value="5000">
</td>
<td>
<input type="text" name="staff[STAFF/2016/001][tax]" class="tax" placeholder="tax" value="500">
</td>
<td>
<input type="text" name="staff[STAFF/2016/001][total]" class="total" placeholder="total" readonly="readonly" value="4500">
</td>
</tr>
<!--Staff 2-->
<tr data-id="STAFF/2016/002">
<td>
<input type="text" name="staff[STAFF/2016/002][id]" class="staffid" value="STAFF/2016/002" readonly="readonly">
</td>
<td>
<input type="text" name="staff[STAFF/2016/002][salary]" class="salary" placeholder="salary" value="10000">
</td>
<td>
<input type="text" name="staff[STAFF/2016/002][tax]" placeholder="tax" class="tax" value="1000">
</td>
<td>
<input type="text" name="staff[STAFF/2016/002][total]" placeholder="total" class="total" readonly="readonly" value="9000">
</td>
</tr>
In PHP you can then iterate over this single array:
<?php
$db = new PDO('mysql:host=localhost;dbname=database;', 'root', '');
if (!empty($_POST['staff'])) {
$stmt = $db->prepare('UPDATE payroll SET salary = :salary, tax = :tax, total = :total WHERE staffid = :staffid');
foreach ((array)$_POST['staff'] as $staffId => $staffInfo) {
$stmt->bindValue(':salary', $staffInfo['salary']);
$stmt->bindValue(':tax', $staffInfo['tax']);
$stmt->bindValue(':total', $staffInfo['total']);
$stmt->bindValue(':staffid', $staffId); // you can also use $staffInfo['id'] here instead of $staffId
$stmt->execute();
}
}
See also:
http://php.net/manual/en/pdo.prepared-statements.php
http://php.net/manual/de/pdo.prepare.php

ContentType: multipart/form-data when POSTing access_token to a resource

I need Your help, i am implementing OAuth2 Services getting library from https://github.com/bshaffer/oauth2-server-php
Every thing is woking fine but when i used enctype="multipart/form-data" in form getting error The access token provided is invalid
My Form
<form action="contact.php" method="post" enctype="multipart/form-data" name="contact" id="conact">
<table>
<tbody>
<tr>
<td>Image</td>
<td><input type="file" name="image" id="image" value="" /></td>
</tr>
<tr>
<td>Name</td>
<td><input type="text" name="name" id="name" maxlength="25" value="" /></td>
</tr>
<tr>
<td>Status</td>
<td><input type="text" name="status" id="status" maxlength="25" value="" /></td>
</tr>
<tr>
<td>Access Token</td>
<td><input type="text" name="access_token" id="access_token" value="" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" id="submit" value="Submit" /></td>
</tr>
</tbody>
</table>
</form>
But When i remove it enctype="multipart/form-data" everthing is working file but image is not upload.
My contact.php have
if (!$server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) {
$response[]=$server->getResponse()->send();
die;
}
This Code is Checking Valid and Invalid Access Token
Please Help.
Thanks
I am not get these answer yet so i use the alternative method for this I passed the access token in action Like this
<form action="contact.php?access_token=" method="post" enctype="multipart/form-data" name="contact" id="conact">
<table>
<tbody>
<tr>
<td>Image</td>
<td><input type="file" name="image" id="image" value="" /></td>
</tr>
<tr>
<td>Name</td>
<td><input type="text" name="name" id="name" maxlength="25" value="" /></td>
</tr>
<tr>
<td>Status</td>
<td><input type="text" name="status" id="status" maxlength="25" value="" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" id="submit" value="Submit" /></td>
</tr>
</tbody>
</table>
</form>
It working fine.
I too had the similar problem solved by doing this
<form action="contact.php?access_token=MY_TOKEN_HERE" method="post" enctype="multipart/form-data" name="contact" id="conact">
<table>
<tbody>
<tr>
<td>Image</td>
<td><input type="file" name="image" id="image" value="" /></td>
</tr>
<tr>
<td>Name</td>
<td><input type="text" name="name" id="name" maxlength="25" value="" /></td>
</tr>
<tr>
<td>Status</td>
<td><input type="text" name="status" id="status" maxlength="25" value="" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" id="submit" value="Submit" /></td>
</tr>
</tbody>
</table>
</form>
You can also check this issue on bsaffers library issue
This is also mentioned on oauth library

php inserting last inserted values to the database

I have my login table in mysql is like this
id
fname
lname
email
contactno
userid
password
acctype
status
Now my form is like this
<form name="frm" method="post" action="registerform.php">
<table id="new-account" class="create-an-account" width="100%" border="1" cellspacing="10px" cellpadding="10px">
<tr>
<td width="45%">
<label for="firstname">First Name</label>
<input type="text" style="width:230px;" name="Firstname" id="Firstname" /></td>
<td width="10%"></td>
<td width="45%">
<label for="lastname">Last Name:</label>
<input type="text" style="width:230px;" name="LastName" id="LastName" />
</td>
</tr>
<tr>
<td>
<label for="">Account Type</label>
<select class="select" name="at" id="ValidSelection" style="width:245px;" >
<option value="0">Select Account Type</option>
<option value="agent">agent</option>
<option value="admin">admin</option>
</select>
</td>
</tr>
<tr>
<td><label for="">Email Id:</label></td>
</tr>
<tr>
<td><input type="text" name="email" id="ValidEmail" style="width:230px;"/></td>
</tr>
<tr>
<td><label for="">Contact Number</label></td>
</tr>
<tr>
<td><input type="text" name="contact" id="ValidNumber" style="width:230px" /></td>
</tr>
<tr>
<td><label for=""><strong>Choose Your Login Id:</strong></label>
<input type="text" style="width:230px;" name="LoginId" id="LoginId"/>
</td>
</tr>
<tr>
<td><label for=""><strong>Password: <br /></strong></label></td>
</tr>
<tr>
<td><input type="password" style="width:230px;" name="Password" id="ValidPassword" /></td>
</tr>
<tr>
<td><label for="">Confirm Password:</label></td>
</tr>
<tr>
<td>
<input type="password" style="width:230px;" name="ConfirmPassword" id="ValidConfirmPassword"
/>
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="signup" value="Create Account" style="margin-top:20px" /></td>
</tr>
</table>
and for insert data my php code is like this
<?php
if(isset($_REQUEST['signup'])) {
mysql_query("insert into login (`fname`,`lname`,`email`,`contactno`,`userid`,`password`,`acctype`,`status`) values('".$_REQUEST['Firstname']."','".$_REQUEST['LastName']."','".$_REQUEST['email']."','".$_REQUEST['contact']."','".$_REQUEST['LoginId']."','".$pswd."','".$_REQUEST['at']."','active')");
}
?>
Now here when I am reloading the page it is automatically inserting the last entered values to the database. So here can someone kindly tell me what is the issue here? Any help and suggestions are welcome.
If you reload the page after submitting a form, it will keep the POST data. To solve this follow the below things :
You can redirect to some other page after inserting the data, use header("location:new_page.php")
You can unset REQUEST, use unset($_REQUEST) after insert
after inserting the $_POST data use redirect to avoid this situation .
even you can redirect to same page like this :-
header('Location: '.$_SERVER['PHP_SELF']);
exit;

Adding more field to PHP form (user can add more than one address)

My users can enter more than one address but I want an actual button that generates the extra fields as only one address is compulsory and empty fields will look ugly! I also need the extra addresses to go into mysql database.
How would I do with Javascript if PHP is not possible
Some code that may help:
<td width="732" valign="top"><p>
<h3 class="main">Address Details</h3>
<p class="normal"> You are able to add up to 3 addresses but only 1 is compulsory.
However it would be helpful if you could insert 3 addresses:
<ul>
<li>Permanent home address</li>
<li>Postal address (where you will be from June to September)</li>
<li>Local address (where you currently live)</li>
</ul>
<?php
if(!empty($err)) {
echo "<div class=\"msg\">";
foreach ($err as $e) {
echo "* $e <br>";
}
echo "</div>";
}
?>
<br>
<form action="address.php" method="post" name="regForm" id="regForm" >
<table width="95%" border="0" cellpadding="3" cellspacing="3" class="forms">
<tr>
<td>Street<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="Street" type="text" id="Street" class="required" size="50">
</tr>
<tr>
<td>Line 2
</td>
<td><input name="Line2" type="text" id="Line2" class="required" size="50">
</tr>
<tr>
<td>Line 3
</td>
<td><input name="Line3" type="text" id="Line3" class="required" size="50">
</tr>
<tr>
<td>Town<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="Town" type="text" id="Town" class="required" size="30">
</tr>
<tr>
<td>Postcode<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="Postcode" type="text" id="Postcode" class="required" size="10">
</tr>
<tr>
<td>Country <font color="#CC0000">*</font></span></td>
<td><select name="Country" class="required" id="select8">
<option value="" selected></option>
<option value="Afghanistan">Afghanistan</option>
<option value="Albania">Albania</option>
(etc)
</select></td>
</tr>
<tr>
<td>Telephone Number<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="Tele" type="text" id="Tele" class="required" >
</tr>
<tr>
<td>Fax<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="Fax" type="text" id="Fax" class="required" >
</tr>
<tr>
<td>Mobile<span class="required"><font color="#CC0000">*</font></span>
</td>
<td><input name="Mobile" type="text" id="Mobile" class="required" >
</tr>
<tr>
<td>Type <font color="#CC0000">*</font></span></td>
<td><select name="Type" class="required" id="select8">
<option value="" selected></option>
<option value="H">Home</option>
<option value="P">Postal</option>
<option value="L">Local</option>
</table>
<p align="center">
<input name="doAddress" type="submit" id="doAddress" value="Submit">
to fix your parse error - put ; at the end of line $numrows = 0 + $_GET['numrows']
to generate more fields dynamically - use javascript, really, it's way better for this task than php

Categories