When I submit this form it downloads the php script it refers to:
<form action="insertcustomer.php" method="post" class="myform">
<p>
Name: <input type="text" name="name" size="20"/>
</p>
<p>
Address: <input type="text" name="addr" size="40"/></p>
<p>
City: <input type="text" name="city" size="20"/>
State: <input type="text" name="state" size="3"/>
Phone: <input type="text" name="phone" size="15"/>
</p>
<p>
Account Balance: <input type="text" name="acct_balance" size="13"/>
</p>
<p class="bttn">
<input class="b" type="submit" name="query" value="Insert Customer"/>
<input class="b" type="reset" name="reset" value="Clear Form"/>
</p>
</form>
Insertcustomer.php:
$name = $_POST['name'];
$addr = $_POST['address'];
$city = $_POST['ccity'];
$state = $_POST['cstate'];
$phone = $_POST['phone'];
$acct_balance = $_POST['acct_balance'];
Is there something wrong with the code? I have followed all steps mentioned in this article, but every time I click on the submit button, it downloads the php file. I apologize in advance as I am fairly new to php.
Make sure your code is wrapped in <?php and ?>
Does your server support PHP?
Is your server configured properly?
Related
When creating and posting just the user note data, I had no issues. Yet when I attempt to allow the user to specify the file name, the code refuses to run.
Is there another method of approaching this problem or is my syntax off?
HTML:
<form method="post">
<div>
<div style="margin-right 5px">
<input type="text" name="noteData" id="notes" size="250">
<input type="Submit" name="Submit" class="txtNote_But" value="Save Text
Note">
</div>
<input type="text" class="fileName" name="fileName" id="fileName"
size="35">
<input type="Submit" name="Submit2" class="filName_But" value="Save
File Name">
</div>
</form>
PHP WRITE:
$noteName = $_POST['fileName'];
$noteData = $_POST['notes'];
$notes = fopen('' + $noteName,"wb");
fwrite($notes,$noteData);
fclose($notes);
It seems like you have two submit buttons on one page which causes only one input field to get posted.
Restructure your form to something like this:
<form method="post">
<div>
<div style="margin-right:5px;">
<input type="text" class="fileName" name="fileName" id="fileName" size="35" value="untitled">
<input type="text" name="noteData" id="notes" size="250">
<input type="Submit" name="Submit" value="Save">
</div>
</div>
</form>
Get the POST data in your php script:
$noteName = $_POST['fileName'];
$noteData = $_POST['notes'];
$notes = fopen('' + $noteName,"wb");
fwrite($notes,$noteData);
fclose($notes);
By the way using the textarea tag would be more suitable for the note input:
<form method="post">
<div>
<div style="margin-right:5px;">
<input type="text" class="fileName" name="fileName" id="fileName" size="35" value="untitled"><br>
<textarea type="text" name="noteData" id="notes"></textarea><br>
<input type="Submit" name="Submit" value="Save">
</div>
</div>
</form>
Try using file_put_contents() instead of fwrite()
Example
// Create a unique prefix to prevent duplicate file names
$noteNamePrefix = $prefix = substr(str_shuffle("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 1).substr(md5(time()),1);
$noteName = $_POST['fileName'];
$noteData = $_POST['notes'];
// Write File To Disk (Replace _PATH_TO_DIR With the destination path Eg /public_html/uploads/)
file_put_contents(_PATH_TO_DIR_.$noteNamePrefix.$noteName, $noteData);
Can anyone help me to get the addition of Basic Salary and Allowance I and insert it in Total Day Rate without clicking a button. here's my php code.
Here's a Screen Shot of my UI.
Code :
<?php
$connection = mysql_connect("localhost", "root", "");
$db = mysql_select_db("laboursalary", $connection);
if(isset($_POST['submit'])){
$ID = $_POST['ID'];
$Name = $_POST['Name'];
$Location = $_POST['Location'];
$Category = $_POST['Category'];
$LabourSupplier = $_POST['LabourSupplier'];
$Home = $_POST['Home'];
$Mobile = $_POST['Mobile'];
$BasicSalary = $_POST['BasicSalary'];
$Allowance1 = $_POST['Allowance1'];
$Allowance2 = $_POST['Allowance2'];
$DayRate = $_POST['$DayRate'];
$OTrate = $_POST['OTrate'];
if($ID !=''||$Name !=''){
$query = mysql_query("insert into attendance(ID, Name, Location, Category,LabourSupplier,Home,Mobile,BasicSalary,Allowance1,Allowance2,DayRate,OTrate) values ('$ID','$Name','$Location','$Category','$LabourSupplier','$Home','$Mobile','$BasicSalary','$Allowance1','$Allowance2','$DayRate','$OTrate')");
echo "<br/><br/><span>Data Inserted successfully...!!</span>";
}
else{
echo "<p>Insertion Failed <br/> Some Fields are Blank....!!</p>";
}
}
mysql_close($connection);
?>
After I enter the values for Basic Salary and Allowance 1, I want to get the addition of those two in Day Rate automatically.
this is my HTML code.
<form id="details" action="" method="POST">
<fieldset> ID:
<input class="input" type="text" name="ID" value="" />
</fieldset>
<fieldset> Name:
<input class="input" type="text" name="Name" value="" />
</fieldset>
<fieldset> Location:
<input class="input" type="text" name="Location" value="" />
</fieldset>
<fieldset> Category:
<input class="input" type="text" name="Category" value="" />
</fieldset>
<fieldset> Labour Supplier:
<input class="input" type="text" name="LabourSupplier" value="" />
</fieldset>
<fieldset> Telephone:
<input class="input" type="text" name="Home" value="" />
</fieldset>
<fieldset>Mobile:
<input class="input" type="text" name="Mobile" value="" />
</fieldset>
<fieldset> Basic Salary:
<input class="input" type="number" name="BasicSalary" value="" />
</fieldset>
<fieldset> Allowance I:
<input class="input" type="number" name="Allowance1" value="" />
</fieldset>
<fieldset>Allowance II:
<input class="input" type="number" name="Allowance2" value="" />
</fieldset>
<fieldset>Total Day Rate:
<input class="input" type="number" name="DayRate" value="" />
</fieldset>
<fieldset>OT Rate:
<input class="input" type="number" name="OTrate" value="" />
</fieldset>
<fieldset>
<button name="submit" type="submit" id="submit">Insert</button>
<button onclick="goBack()" name="Back" type="back" id="details-back">Back</button>
</fieldset>
</form>
As I understood your question, your HTML code should be like,
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<form id="details" action="" method="POST">
<fieldset> ID:
<input class="input" type="text" name="ID" value="" />
</fieldset>
<fieldset> Name:
<input class="input" type="text" name="Name" value="" />
</fieldset>
<fieldset> Location:
<input class="input" type="text" name="Location" value="" />
</fieldset>
<fieldset> Category:
<input class="input" type="text" name="Category" value="" />
</fieldset>
<fieldset> Labour Supplier:
<input class="input" type="text" name="LabourSupplier" value="" />
</fieldset>
<fieldset> Telephone:
<input class="input" type="text" name="Home" value="" />
</fieldset>
<fieldset>Mobile:
<input class="input" type="text" name="Mobile" value="" />
</fieldset>
<fieldset> Basic Salary:
<input class="input" type="number" name="BasicSalary" value="0" id="bassal" />
</fieldset>
<fieldset> Allowance I:
<input class="input" type="number" name="Allowance1" value="0" id="all1" />
</fieldset>
<fieldset>Allowance II:
<input class="input" type="number" name="Allowance2" value="0" id="all2" />
</fieldset>
<fieldset>Total Day Rate:
<input class="input" type="number" name="DayRate" value="" id="DayRate" />
</fieldset>
<fieldset>OT Rate:
<input class="input" type="number" name="OTrate" value="" />
</fieldset>
<fieldset>
<button name="submit" type="submit" id="submit">Insert</button>
<button onclick="goBack()" name="Back" type="back" id="details-back">Back</button>
</fieldset>
</form>
<script >
$(document).ready(function (){
$('#bassal').on('input', function() {
$('#DayRate').val(parseInt($('#bassal').val()) + parseInt($("#all1").val()) + parseInt($("#all2").val()));
});
$('#all1').on('input', function() {
$('#DayRate').val(parseInt($('#bassal').val()) + parseInt($("#all1").val()) + parseInt($("#all2").val()));
});
$('#all2').on('input', function() {
$('#DayRate').val(parseInt($('#bassal').val()) + parseInt($("#all1").val()) + parseInt($("#all2").val()));
});
});
</script>
I've added jQuery, that does your work, and you don't need to do addition on PHP side.
This is how it would be done using a submit for post as these are all _POST values... Though to accomplish this without pressing a button would be JS/Angular/J Query/AJAX...
....
$BasicSalary = $_POST['BasicSalary'];
$Allowance1 = $_POST['Allowance1'];
$Allowance2 = $_POST['Allowance2'];
$DayRate = $_POST['$DayRate'];
$OTrate = $_POST['OTrate'];
//Set a new variable with the addition of the two `Basic Salary` and `Allowance 1`
//for the insertion into your column `dayRate`
$adustedDayRate = $BasicSalary + $Allowance1;
if($ID !=''||$Name !=''){
if($query != false){
$query = mysql_query("INSERT INTO `attendance` (ID, Name, Location, Category,LabourSupplier,Home,Mobile,BasicSalary,Allowance1,Allowance2,DayRate,OTrate) values ('$ID','$Name','$Location','$Category','$LabourSupplier','$Home','$Mobile','$BasicSalary','$Allowance1','$Allowance2','$adustedDayRate','$OTrate')");
echo "<br/><br/><span>Data Inserted successfully...!!</span>";
}esle{ $_SESSION['err'] = "ERROR: ".--- MySQL error handle here --- }
}
else{
echo "Some Fields are Blank....!!</p>";
}
}
mysql_close($connection);
Using Angular, you could place a placeholder element in your form input for `DayRate, then add the call back for the ng-model element for the two inputs you wish to add. Something like this here:
<div ng-app="">
<p>BasicSalary : <input type="number" ng-model="BasicSalary" placeholder="Basic Salary"></p>
<p>AllowanceI : <input type="number" ng-model="AllowanceI" placeholder="Allowance I"></p>
<p>DayRate : <input type="number" ng-model="DayRate" placeholder="{{BasicSalary -- AllowanceI}}"></p>
Your code would look like:
<fieldset> Basic Salary:
<input class="input" type="number" ng-model="BasicSalary" name="BasicSalary" value="" />
</fieldset>
<fieldset> Allowance I:
<input class="input" type="number" ng-model="Allowance1" name="Allowance1" value="" />
</fieldset>
<fieldset>Allowance II:
<input class="input" type="number" name="Allowance2" value="" />
</fieldset>
<fieldset>Total Day Rate:
<input class="input" type="number" name="DayRate" placeholder="{{ BasicSalary -- Allowance1 }}" value="" />
</fieldset>
Here is a working fiddle of the angular method, simply add the angular library to your server using composer or hosted links, no additional JS is required with the Angular library elements. You can change the value of DayRate as the two other combining inputs are being input.
https://jsfiddle.net/qkpfb90o/1/
Hope this helps!
You can also try with this.
<form id="details" action="" method="POST">
<fieldset> ID:
<input class="input" type="text" name="ID" value="" />
</fieldset>
<fieldset> Name:
<input class="input" type="text" name="Name" value="" />
</fieldset>
<fieldset> Location:
<input class="input" type="text" name="Location" value="" />
</fieldset>
<fieldset> Category:
<input class="input" type="text" name="Category" value="" />
</fieldset>
<fieldset> Labour Supplier:
<input class="input" type="text" name="LabourSupplier" value="" />
</fieldset>
<fieldset> Telephone:
<input class="input" type="text" name="Home" value="" />
</fieldset>
<fieldset>Mobile:
<input class="input" type="text" name="Mobile" value="" />
</fieldset>
<fieldset> Basic Salary:
<input class="input" type="number" name="BasicSalary" value="" id="BasicSalary" onkeyup="doSum()"/>
</fieldset>
<fieldset> Allowance I:
<input class="input" type="number" name="Allowance1" value="" id="Allowance1" onkeyup="doSum()"/>
</fieldset>
<fieldset>Allowance II:
<input class="input" type="number" name="Allowance2" />
</fieldset>
<fieldset>Total Day Rate:
<input class="input" type="number" name="DayRate" value="" id="DayRate" />
</fieldset>
<fieldset>OT Rate:
<input class="input" type="number" name="OTrate" value="" />
</fieldset>
<fieldset>
<button name="submit" type="submit" id="submit">Insert</button>
<button onclick="goBack()" name="Back" type="back" id="details-back">Back</button>
</fieldset>
<script>
function doSum() {
var Allowance1 = isNaN(document.getElementById('Allowance1').value) ? document.getElementById('Allowance1').value : 0;
var BasicSalary = isNaN(document.getElementById('BasicSalary').value) ? document.getElementById('BasicSalary').value : 0;
var tot = parseInt(Allowance1) + parseInt(BasicSalary);
document.getElementById('DayRate').value = tot;
}
</script>
I want to send an email from the browser, but my PHP knowledge and experience are not enough.
So I have a html form
<form>
<textarea value="Message" required></textarea>
<input type="text" value="Name" required>
<input type="text" value="Email" required>
<input type="text" value="subject" required>
<input type="reset" value="Reset" >
<input type="submit" value="Submit">
</form>
My question here is how to fill this php code so I can get data from the html form and then send the email.
$to = "my_email#example.com";
$name =
$message =
$from =
$headers =
mail($to,$name,$subject,$message,$headers);
You have to add an action and a method (POST or GET) in your form
<form action="yourpage.php" method="POST">
After that add a name attribute at all your input :
<input type="text" value="Name" name="name" required>
<input type="text" value="Email" name="mail" required>
In yourpage.php
Here the method was POST so :
$_POST['name']; //Here get the posted value in input named 'name'
$_POST['mail'];
You need to set the action in the form, and get the $_POST in PHP code, here is an example:
<form action="test.php">
<textarea value="Message" required></textarea>
<input type="text" name="Name" value="Name" required>
<input type="text" name="Email" value="Email" required>
<input type="text" name="subject" value="subject" required>
<input type="reset" value="Reset" >
<input type="submit" value="Submit">
</form>
//test.php file
<?php
$to = "my_email#example.com";
$name = $_POST['Name'];
$message = $_POST['Message'];
$from = 'test#test.com';
$headers = 'your headers';
mail($to,$name,$subject,$message,$headers);
?>
So, I am creating a simple form:
<tr>
<td>
<label for="FirstName">First Name <span class="req">*</span>
</label>
<br />
<input type="text" name="FirstName" id="FirstName" class="cat_textbox" maxlength="255" />
</td>
</tr>
<tr>
<td>
<label for="LastName">Last Name <span class="req">*</span>
</label>
<br />
<input type="text" name="LastName" id="LastName" class="cat_textbox" maxlength="255" />
</td>
</tr>
<input class="cat_button" type="submit" value="Submit" id="catwebformbutton" />
What I would like it to do is when the user click submit, it will take them to another page where those details will be confirmed, or simply shown to them. any ideas? or sample codes?
where the form ? I cant see any form in your code !
try create 2 php files
index.php file
<form action="next_page.php" method="post">
<table>
<tr>
<td>
<label for="FirstName">First Name <span class="req">*</span></label>
<br />
<input type="text" name="FirstName" id="FirstName" class="cat_textbox" maxlength="255" />
</td>
</tr>
<tr>
<td>
<label for="LastName">Last Name <span class="req">*</span></label>
<br />
<input type="text" name="LastName" id="LastName" class="cat_textbox" maxlength="255" />
</td>
</tr>
</table>
<input class="cat_button" type="submit" value="Submit" id="catwebformbutton" />
</form>
next_page.php file
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
echo "first Name : ".$FirstName."<br>";
echo "last Name : ".$LastName."<br>";
you want to use form method post and action form to do action in other page ,
and post data in another page using $_POST[]
Good references may be helpful to learn these things :
about form method ->
http://www.w3schools.com/tags/att_form_method.asp
about form action ->
http://www.w3schools.com/tags/att_form_action.asp
about $_POST in php ->
http://php.net/manual/en/reserved.variables.post.php
Hope you can help, I am trying to knock up a contact form for my website which is HTML, styled with CSS and the email sent with PHP.
<form class="form" action="webform.php" method="post">
<h1>Contact Form:</h1>
<label>
<span>Your Name:</span><input id="name" type="text" name="name" />
</label>
<label>
<span>Email Address:</span><input id="email" type="text" name="email" />
</label>
<label>
<span>Subject:</span><input id="subject" type="text" name="subject" />
</label>
<label>
<span>Message</span><textarea id="feedback" name="feedback"></textarea>
<input id="button" type="button" value="Submit Form" />
</label>
</form>
Anyone help me out, can provide the link to my site if necessary.
Appreciate any help :)
You should use submit as the button type
<input id="button" type="submit" value="Submit Form" />
Fiddle DEMO
See updated FIDDLE
Have you tried changing:
<input id="button" type="button" value="Submit Form" />
to:
<input id="button" type="submit" value="Submit Form" />
Alternatively, you can use:
<button id="button" >Submit Form</button>
As you have it now, input type='button' is not a valid element for form submission. For valid form elements, MDN have a great article- see the sections input and buttons
Change type="button" to type="submit"
<form class="form" action="webform.php" method="post">
<h1>Contact Form:</h1>
<label>
<span>Your Name:</span><input id="name" type="text" name="name" />
</label>
<label>
<span>Email Address:</span><input id="email" type="text" name="email" />
</label>
<label>
<span>Subject:</span><input id="subject" type="text" name="subject" />
</label>
<label>
<span>Message</span><textarea id="feedback" name="feedback"></textarea>
<input id="button" type="submit" value="Submit Form" />
</label>
</form>
In this particular case, I agree with the suggested solutions re: type="submit.
But I arrived here due to having my buttons stop working all of a sudden, though a Select submit was still working. And it was due to a tiny bug in some Javascript that was killing the submission.
Just something else to check.
try this html form
<form class="form" action="webform.php" method="post">
<h1>Contact Form:</h1>
<label>
<span>Your Name:</span><input id="name" type="text" name="name" />
</label>
<label>
<span>Email Address:</span><input id="email" type="text" name="email" />
</label>
<label>
<span>Subject:</span><input id="subject" type="text" name="subject" />
</label>
<label>
<span>Message</span><textarea id="feedback" name="feedback"></textarea>
<input id="button" type="submit" value="Submit Form" />
</label> </form>