How to put values of textbox into variable in PHP? [closed] - javascript

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
I want to add values to my MySql database using PHP. The values I want to add, will come from the text-boxes of a form. I tried $variable = $_POST['formElementName'] and used $variable to insert values. But it doesn't work.
Question:
How can I put the values of the text-boxes into variables?
Thanks.

Use below code for the form
<form name="form-name" action="" method="POST">
<input type="text" name="fieldname1" value="" />
<input type="text" name="fieldname2" value="" />
</form>
and for php manipulation at server end, you will get values in $_POST i.e.
$_POST['fieldname1'] and $_POST['fieldname2]

I just want to elaborate what #Kyle wrote
Note: The form method is POST
HTML part
<form action="your_php_file_name.php" method="POST">
<input type="text" name="first_name" />
<input type="submit" value="Submit" />
</form>
PHP part: The file name is: your_php_file_name.php
<?php
//A good practice to check the type of HTTP request
$fname = $_POST['first_name'];
?>
Some good practices
Check the HTTP request type sent from the client side. (I find it a good way)
Sanitize the variables before inserting.

Here's an idea:
Client-side:
<input type="text" name="first_name">
Server-side:
$var = $_POST["first_name"];

Just to add to Kyle's answer above, Make sure you have value="Something" set, otherwise it will return nothing.
<input type="text" name="first_name" value="Testing">
Server Side
$var = $_POST["first_name"];
For debugging I use:
print_r($_POST)
This will return all the POST values set and is really handy.

Related

How to call a Python script in a Django server from JavaScript? [closed]

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 3 years ago.
Improve this question
Salut!
I have a HTML running properly in a Django server, also I have a function in a Python file which send an e-mail. I would like to execute this function when an submit input is clicked. So, how can I call this function using JavaScript?
I've read about using AJAX, but I think that this could be code easily. Am I wrong?
Yes you're right !
With Django you can grab all the post that the user send and do something with these datas.
So for example in mail.html page :
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
Name:<br>
<input type="text" name="name"><br>
E-mail:<br>
<input type="text" name="mail"><br>
Comment:<br>
<input type="text" name="comment" size="50"><br><br>
<input type="submit" value="Send">
<input type="reset" value="Reset">
</form>
And in views.py :
def send_mail(request):
if request.method == 'POST':
name = request.POST.get('name')
mail = request.POST.get('mail')
comment = request.POST.get('comment')
# YOUR SCRIPT TO SEND MAIL HERE WITH THE VARIABLES
else:
return render(request, 'mail.html')

Php : cant sumbit the good form [closed]

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 6 years ago.
Improve this question
Sorry for my spelling
Hi, im trying to make a website showing internet forfeit, so in mySQL database i put all my information then I print it on my web page, the the user click on the forfeit he wants, it brings him to an other page that shows all the forfeit informations... In the while(), I'm making unique form for each forfeit, then on the
The problem here is that the only form sumbitted is the last one created
include_once "DataBase/db.php";
if($internet->num_rows != 0){
while($rows = $internet->fetch_assoc()){
$nom = $rows["nom"];
$id = $rows["id"];
$tech = $rows["technologie"];
$telechargement = $rows["telechargement"];
$televersement = $rows["televersement"];
$utilisation = $rows["utilisation"];
$prix= $rows["prix"];
echo '
<form method="POST" action="Fournisseurs/Videotron.php" id="'.$id.'">
<div class="boxes">
<div class="[ price-option price-option--high ]">
<div class="price-option__detail">
<span class="price-option__cost">'.$nom.'<br>$'.$prix.'</span>
</div>
<input type="hidden" name="id" value="'.$id.'"></input>
<input type="hidden" name="nom" value="'.$nom.'"></input>
<input type="hidden" name="tech" value="'.$tech.'"></input>
<input type="hidden" name="telechargement" value="'.$telechargement.'"></input>
<input type="hidden" name="televersement" value="'.$televersement.'"></input>
<input type="hidden" name="utilisation" value="'.$utilisation.'"></input>
<input type="hidden" name="prix" value="'.$prix.'"></input>
<div class="price-option__purchase">
Submit
</div>
</div>
</div>
';
}
}
You can see what i'm talking about here : http://fournisseursquebec.com/Forfaits.php
just select internet
Thank you!
You are missing the closing </form> tag for every box. Now you have one big form with a lot of repeated fields:
<form method="POST" action="Fournisseurs/Videotron.php" id="'.$id.'">
box 1:
<input type="hidden" name="id" value="'.$id.'"></input>
.... box 2:
<input type="hidden" name="id" value="'.$id.'"></input>
...
The name attribute of the various input is the one that is sent and should be unique inside every form.
Just add the </form> tag in your while loop and it should work.

How get type or id data sent post? [closed]

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 7 years ago.
Improve this question
I have this code for send date:
<form enctype="multipart/form-data" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
<input name="file[]" type="file" id="img">
<textarea name="file[]" rows="5" cols="50" id="textarea"></textarea>
<input name="file[]" type="text" id="text" value="">
<input type="submit" value="upload" name="submit" id="upload" class="upload"/>
</form>
and this code:
<?php
if (isset($_POST['submit'])){
$textarea=$_POST['file'];
$implodetextarea=implode(",",$textarea);
for ($i = 0; $i < count($textarea); i++){
echo $textarea['id'][$i];//This is wrong
}
}
?>
Now how to get the type of data and how you can distinguish between the image or text, or others?
Data validation in Windows is based on the honor system - a file's suffix (.txt, .jpg, .zip, etc.) tells the system what kind of data is in the file. Of course a suffix can be changed, so it's not a perfect system. In other operating systems file suffixes are less prevalent and data validation, when required, must be done by examining the contents of the file. For example, if you're expecting the user to upload a jpg, you can use PHP's fopen and fread to search the uploaded file for jpg headers. In short, you can't be sure what kind of file is being uploaded without cracking it open and reading the contents.
You can look for the files mime type.

Beginners help to HTML [closed]

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 need to create a html page that will accept inputs from one webpage then print out the user results on a seperate HTML page. So far I have this. When I go and check my action_page.php file nothing is being written into it. Is there anyway I can have my inputs print directly on a second HTML page and constantly updating? Also is there any way for an outside application to control or change the values that are shown on the second webpage?
So I guess a more clear description of what I am trying to do is on one page its accepts input A,B,C then on another html page that have the previous A,B,C values I would like to update the values with the new user submitted values. The second webpage needs to also be static in the sense that the first html page would be website.com/UserInput and the second html page would be website.com/PrintedUserInput. I hope that helps. Thanks
<html>
<body>
<form action="action_page.php">
Time:
<br>
<input type="number" name="Time" value="">
<br>
Temperature:
<br>
<input type="number" name="Temperature" value="">
<br>
Instant Brew:
<br>
<input type="number" name="InstantBrew" value="">
<br>
<br>
<input type="submit" value="Submit">
</form>
<p>If you click "Submit", the form-data will be sent to a page called "action_page.php".</p>
</body>
</html>
All you have to do, is put the "method" attribute to your form like this:
<form action="action_page.php" method="post">
You absolutely need a server side language then to print them out. Since you use your page with the PHP extension, I'm guessing you're using PHP. So then you can call them that way in your other page:
<html>
<body>
Time: <?= $_POST['Time'] ?>
<br>
Temperature: <?= $_POST['Temperature'] ?>
etc, where the name you put between your POST braces is the "name" attribute of your input. Note that name attribute is case sensitive
Hope it helped !

Server Login programme [closed]

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
so, I made my own little server. I tried to make it so, that you have to Login in order to access its files. I tried Javascript, but of course that is the worst thing to do (because you can see the passwords and usernames in the source code):
<form name="login">
Användar: <input type="text" name="user" value="gast">
<br>
Lösenord: <input type="password" name="pw" value="">
<br>
<input type="button" OnClick="log()" value="Login">
</form>
and the log() method:
function log() {
if (document.login.user.value == "gast")
if (document.login.pw.value == "0000")
location.href="gast.html"
}
So, this is cleary not a good way to do it, if you actually want it to be somewhat secure... So does anybody have an idea how I could do this? With a databank perhaps? I'm pretty much a beginner with HTML and JS, so some help would be great :)
You should do authentication and authorization on the server-side.
I assume, you have a webserver running. Behind this webserver you have an application-interface, where the requests to your webserver are put forth to your application. This is the "place" where you should do your auth-processing.
And whatever language you use to write your server-side application, I am sure there are already libraries that help you in that task. Proper authentication and authorization can be tricky, and there is no need to reinvent the wheel (unless of course there is a good reason to do so...).
Just google for "{your-language} authentication" or "{your-language} Framework authentication", where {your-language} is the programming language, you want to use on the server-side.
Anyhow, if you have no need for a full application, and just want to serve plain websites, you webserver should have a method for "Basic-Authentication". Again, just google for: "{your-webserver} Basic Authentication".
Any login system needs to be serverside. Javascript is clientside. But there are many options depending on your server.
If you only have HTML and JS in your toolbox I'd look at using .htaccess if you are on a linux based server.
You can use jQuery. Its very easy, but verification through javascript is very dangerous and easy to challenge. I recommend to use PHP
$(document).ready(function() {
$("input[type='button']").click(function() {
var user = $("input[type='text']").val();
var pass = $("input[type='password']").val();
if (user === "gast" && pass === "0000") {
location.href = "gast.html";
} else {
alert("bad password!");
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<form name="login">
Användar:
<input type="text" name="user" value="gast">
<br>Lösenord:
<input type="password" name="pw" value="">
<br>
<input type="button" value="Login">
</form>
EXAMPLE1
when you must use javaScript, I recommend use Javascript Obfuscator: Javascript Obfuscator It's safer:
eval(function(p,a,c,k,e,d){e=function(c){return c};if(!''.replace(/^/,String)){while(c--){d[c]=k[c]||c}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('$(12).13(4(){$("1[0=\'11\']").9(4(){6 7=$("1[0=\'14\']").3();6 5=$("1[0=\'2\']").3();18(7==="8"&&5==="20"){17.16="8.19"}15{21("10 2!")}})});',10,22,'type|input|password|val|function|pass|var|user|gast|click|bad|button|document|ready|text|else|href|location|if|html|0000|alert'.split('|'),0,{}))
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<form name="login">
Användar:
<input type="text" name="user" value="gast">
<br>Lösenord:
<input type="password" name="pw" value="">
<br>
<input type="button" value="Login">
</form>
EXAMPLE2

Categories

Resources