Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have simple HTML form on which user will enter token number. How can I fetch details from database using onclick() event when user enter token number and click on fetch details.
After fetching the details user will click on Pay with PayPal button to complete payment.
HTML Form:
<form class="responsive" action="payments.php" method="post" id="paypal1">
<strong><big>Have Token? Checkout here...</big></strong><br><br>
<p>Token Number:
<input type="text" name="token" placeholder="Enter Token Number" autocomplete="off" maxlength="45" required />
<input type="button" id="token-btn" value="Fetch Details" onClick="fetch-details()">
</p>
<button class="btn btn-success">Pay With PayPal</button>
</form>
The usual way is either:
Old-style, page-refresh: Have the button submit a form, have your PHP code do the DB work, and show a new page.
Use ajax:
Have a JavaScript event handler that makes an ajax call to your PHP code (using fetch [on modern browsers] or XMLHttpRequest)
Have your PHP code do the DB work and return the details, perhaps using json_encode to send the details back as JSON
Have your JavaScript ajax success handler use the details to update the page via DOM manipulation
Download jquery from jquery site include the script in the page needed, then create a php file lemme call mine fetch.php that fetches the details you want, something like this
<?php
require_once 'your_connection';
if(isset($_POST['id'])){
$id = mysqli_real_escape_string($connect, $_POST['id'];
$query = "SELECT * FROM `table` WHERE `id`='$id'";
if($query_run= mysqli_query($query)){
if($row = mysqli_fetch_assoc($query_run)){
echo"<h1>$row['details']</h1>";
}
}
}
?>
then below the included script of downloaded do this
$(document).ready(function(){
$("#fetchDetails").click(function(){
$.post("fetch.php",{id:the_id_of_the_details_you_want_to_fetch},function(data)
{
$("#id_of_where_you_want_to_place_details_on_page").html(data);
})
});
})
hope it helps
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 months ago.
Improve this question
I am trying to make a registration page for my website but when I run it; it gives error. What am I doing wrong?
<?php
//Form values
$name_value=$_POST['Name_input'];
$Username_value=$_POST['Username_input'];
$DOB_value=$_POST['DOB_input'];
$Password_value=$_POST['Password_input'];
$Phone_number_value=$_POST['Phone_number_input'];
$Python_checkbox_value=$_POST['Python_checkbox'];
$Java_checkbox_value=$_POST['Java_checkbox'];
$C_sharp_checkbox_value=$_POST['C#_checkbox'];
$HTML_checkbox_value=$_POST['HTML_checkbox'];
$Cpp_checkbox_value=$_POST['C++_checkbox'];
$R_checkbox_value=$_POST['R_checkbox'];
$swift_checkbox_value=$_POST['swift_checkbox'];
$kotlin_checkbox_value=$_POST['kotlin_checkbox'];
$JS_checkbox_value=$_POST['JS_checkbox'];
Take a look at this code :
<form method="GET">
<input type="checkbox" value="value" name="name">checkbox label</input>
<input type="submit">
</form>
<?php
if (isset($_GET["name"]))
{
echo $_GET["name"];
}
?>
As you can see when I submit the form without checking, the parameter in URI is empty because the checkbox isn't defined (I used GET method)
But when I check it, you can see the parameter is name=value
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am wanting to literally take the HTML form input with the ID "bet" and after the value has been entered and submitted; get the exact input for example: '100' may be entered, as I am wanting to perform an if statement to check that the value submitted isn't less than 0 for obvious reasons so then I can stop the webpage proceeding to perform the bet, and make the user instead enter a valid amount.
The code that I am having an issue with is below, upon loading the page I am getting the error: Notice: Undefined index: bet
<form action="duel.php" name="duel" id="duel">
<input type="text" id="betamount" name="betamount">
<?php
$data = $_GET['betamount'];
echo $data;
?>
</form>
I am fairly new to programming in PHP, so any help would be greatly appreciated.
You need to assign a name to the input element. In your situation, you could use the same name as your id:
<input id='bet' name='bet' type='text' value='100' />
To get the specific data for the 'bet' input field use:
echo $_POST['bet'];
On your server to view all of the post data use the code:
// Wrapping the output in the pre block makes the POST data easier to read
echo '<pre>';
print_r($_POST);
echo '</pre>';
This is an example script you can use:
php file:
<?php
if(isset($_POST['submit'];)) {
session_start();
$text = $_POST['Text'];
echo "$text";}else {echo 'Could not load text!';}
?>
<form method="POST">
<input name="Text" type="text">
<input type="submit" name="submit">
</form
So, you would make your form method "POST' and the action the url of the PHP script.
Then, in the PHP script you would use $_POST variable which would contain all of the info that was submitted in that form. See here:
http://php.net/manual/en/reserved.variables.post.php
There is a similar variable for get requests. For hte difference in get and post methods see here:
http://www.w3schools.com/tags/ref_httpmethods.asp
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm having difficulty... I'm trying to create a form which automatically create extra input like .php after the form is submitted.
<form>
<input type="text" name="add" placeholder="Write Test">
<br/>
<input type="submit" name="submit" value="Send">
</form>
When user enters "Test" and press on submit, an automatically extension will be created like this:
Test.php
Thanks in advance.
This can be achieved like this:
<?php
if(!empty($_POST["add"])) {
$file = $_POST["add"] . ".php";
if(file_exists($file)) {
echo "File already exists";
} else {
fopen($file, "w");
}
}
?>
References:
Check if file is already there: http://php.net/manual/en/function.file-exists.php
Create a file / directory : http://php.net/manual/en/function.fopen.php
Concat a string:
$string = $_POST['add'];
$new_string = $string.'.php';
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a simple html page which should take the input from text box and send that as an email.
function getData()
{ var txt=document.getElementById("result").value; }
<body>
<form>
<input type="text" id="result" size="20">
<input type="button" onclick="getData()">
</form>
</body>
Now i need to send the value of txt as email. Whats the easiest way to achieve that? I am familiar with Java/ Java script. I have no hands on PHP.
You cannot send an email using client-side JavaScript.
You will need to submit the form to a server side script which can send the mail for you.
This is not too difficult using PHP, so I urge you to read up on it. Here's a good link: http://code.tutsplus.com/tutorials/sanitize-and-validate-data-with-php-filters--net-2595
<form action="myscript.php">
<input type="text" name="message" size="20">
<input type="submit" value="Send mail"">
</form>
Then in myscript.php:
<?
$message = filter_var($_POST['message'], FILTER_SANITIZE_STRING);
mail("someone#example.com","My subject",$message);
?>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
My php page consist of a number of textfileds and textareas in which the user can input their details there. these textareas and textfileds are inside a <form></form>.so when clicking on submit button all those values are posted (form method=POST ).
there are 2 <textarea> named as Permanent Address and Communication address. and also a check box "Communi. address is same as permanent". the check box code is follows
<input type="checkbox" id="checkadd" onclick="if (this.checked) copyAddress (this.form)"/>
this function calls copyaddress function that copy the Permanent address to Communication address <textarea>. " copyAddress (this.form) " will copy the value of 1st <textarea>(permanent address). so i don't get the value of Permanent address in the page in which i have to POST this value too to the Next Page.
Can you try this..
<?php
if($_POST['permaddress'])
{
echo $_POST['permaddress'];
echo $_POST['commaddress'];
}
?>
<script>
function copyAddress()
{
if(document.getElementById('checkadd').checked == true)
{
document.getElementById('commaddress').value = document.getElementById('permaddress').value;
}
}
</script>
<form method="post" action="test.php" >
<textarea rows="30"cols="30" name="permaddress" id="permaddress"></textarea>
<textarea rows="30"cols="30" name="commaddress" id="commaddress"></textarea>
<input type="checkbox" id="checkadd" onclick="copyAddress()"/>
<input type="submit" value="submit">
</form>