Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
im editing some code for a client but i am stuck on a piece of code
<?php
include("sample/model.php");
if(!empty($username) && !empty($pass)){
$data = aut($username,$pass,$database);
?>
<form id="login" action="index.php" method="post">
<label>User</label>
<input type="text" name="username" id="req" placeholder="User">
<label>Password:</label>
<input type="password" name="pass" id="pass" placeholder="Password">
<input type="submit" name="submit" value="Enter">
</form>
As you can see the form post to it self, how is the post data transform to a variable, there is no function in the included file that does this and no other relevant code in index.php.
Hope someone can help on this.
Thanks in advanced!
If register_globals is on then data passed to a PHP script via cookies or GET and POST requests to be made available as global variables in the script.
There are negative security ramifications for doing this which is why this feature has been deprecated and then removed in PHP 5.4.
If I understood your question correctly. Try this out:
include("sample/model.php");
// $database <-- not really sure where you're getting that
$username = ( isset($_POST["username"]) ? $_POST["username"] : 'Not Found');
$pass = ( isset($_POST["pass"]) ? $_POST["pass"] : 'Not Found');
$data = aut($username,$pass,$database);
I think I know what you're asking. You'd be defining a boolean, or you can turn $username into a variable and check if it's set in the actual if statement, but both will result in the same thing.
<?php
include("sample/model.php");
$username = isset($_POST['username'];
$pass = isset($_POST['pass'];
$pass_data = $_POST['pass'];
$user_data = $_POST['username'];
if(isset( && ){
$data = aut($user_data,$pass_data,$database);
?>
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 3 years ago.
Improve this question
How to print all even numbers between two input values typed by user. please write code hint only in php.
I can give you a hint. Lookup the modulo operator. With it you can do something like this:
<?php
if (($number % 2) === 1)
{
echo "$number is odd.";
}
if (($number % 2) === 0)
{
echo "$number is even." ;
}
?>
Also. Have a look at how you ask questions on stack overflow. Or they will prevent you from asking questions in the future if you don't adhere to those rules.
use this code, for user input i have created a form.
<html>
<body>
<form method="post">
<input type="number" name="num1">
<input type="number" name="num2">
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
<?php
if(isset($_POST['submit'])){
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
// while loop that will print number
while($num1 <= $num2){
// here is the condition to check the EVEN number
if($num1%2!==0){
echo $num1."<br>";
}
// increasing the loope counter by 1
$num1++;
}
}
?>
i hope now your problem has been solved..
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I have read all the questions concerning this but I'm still at a loss.
Using a test script like this
// PAGE 1
<?php session_start();
echo var_dump($_SESSION) . "<br>";
$_SESSION[‘session_var’] = "stuff";
$PHPSESSID = session_id();
echo session_id() . "<br>";
?>
<html>
<head><title>Testing Sessions page 1</title></head> <body>
<p>This is a test of the sessions feature.
<form action="sessionTest2.php" method="POST">
<input type= "text" name= "form_var" value= "testing">
<input type= "submit" value= "Go to Next Page"> </form>
</body>
</html>
//PAGE 2
<?PHP session_start();
echo var_dump($_SESSION);
$session_var = $_SESSION['session_var'];
$form_var = $_POST['form_var'];
echo "session_var =" . $session_var. "</br>";
echo "form_var =" . $form_var. "<br>";
$PHPSESSID = session_id();
echo session_id();
?>
the results I get in page 2 are
array(1) { ["‘session_var’"]=> string(5) "stuff" } session_var =
form_var =testing
al89u6vu02lstp99cs4damdn04
As you can see the variable session_var can be seen in the array but is not being output to the screen where expected, and yes session_start() is at the very top of both pages.
Any ideas what may be wrong
$_SESSION[‘session_var’] = "stuff";
Is using non ascii ‘’ quote marks.
Are you using a word processor to edit your code?
Those quotes are now part of the key name, see this ["‘session_var’"].
Stick to simple ascii single and double quotes ' or "
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Pardon if parts of this question don't make sense—I'm a newb to programming in general. Feel free to correct me!
Here's my problem: I'm making a PHP upload page that uses $_POST. There are two upload fields in the HTML section, both of which are optional. So here's my code for, let's say, example-upload.php:
<form action="" enctype="multipart/form-data" method="post">
<input type="file" id="upload1" name="upload1" accept=".jpg">
<input type="file" id="upload2" name="upload2" accept=".jpg">
<button type="submit" name="submit">Submit either, both, or none of these</button>
</form>
<?php
if (isset($_POST['submit'])) {
if (!empty($_POST['upload1'])) {
$filename_upload1 = $_FILES['upload1']['name'];
}
if (!empty($_POST['upload2'])) {
$filename_upload2 = $_FILES['upload2']['name'];
}
// Checks if there is no upload at all
if (!isset($filename_upload1) && !isset($filename_upload2)) {
echo 'You didn\'t upload anything and that\'s OK';
} else {
if (isset($filename_upload1)) {
move_uploaded_file($_FILES['upload1']['tmp_name'], 'path/to/file/' . $filename_upload1);
}
if (isset($filename_upload2)) {
move_uploaded_file($_FILES['upload2']['tmp_name'], 'path/to/file/' . $filename_upload2);
}
echo 'One or two files was successfully uploaded';
}
}
?>
Each time I run this, submitting either one or both files, I get the "You didn't upload anything and that's okay" message, leading me to believe that I'm doing something wrong with the $_FILES variable. The unusual thing is that I have a different form on a similar page, except with one upload field instead of two. That seems to work.
Any advice? Thank you!
There's no $_POST['upload1'] variable in your form.
Files are passed within $_FILES array.
So, in simplest case you can check $_FILES['upload1']['name']:
if (!empty($_FILES['upload1']['name'])) {
$filename_upload1 = $_FILES['upload1']['name'];
}
And the same check for upload2:
if (!empty($_FILES['upload2']['name'])) {
$filename_upload2 = $_FILES['upload2']['name'];
}
You have to check $_FILES and not $_POST
if (!empty($_FILES['upload1']))
{
$filename_upload1 = $_FILES['upload1']['name'];
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to make an incredibly basic php form that outputs some text a user puts in to a database. Looked at a couple other questions like this to make sure and from what I can tell no one else asked about this. Here's the create.php that takes input from the html.
<?php
include 'connection.php';
$firstname= $_POST('inputName');
$lastname= $_POST('inputName2');
if($_POST ['SUBMIT']) { echo "please fill out the form";
header('location: ../index.html');
} else {
mysql_query("INSERT INTO requestdata ('firstname', 'lastname')
VALUES ('$firstname', '$lastname')") or die(mysql_error());
echo "User has been added"; header ('Location: ../index.html');
}
?>
Here's the html code for the form:
<form action = "php/create.php" method = "POST">
First Name <input type ="text" name='inputName' value=""/>
Last Name <input type="text" name='inputName2' value=""/>
<br />
<input type="submit" name = "button">
</form>`
and the error I'm getting is:
"Fatal error: Function name must be a string in
mywebsite.com/php/create.php on line 8
I think your $_POST variables are wrong.
Please try $_POST['inputName'] instead of $_POST('inputName') and $_POST['inputName2'] instead of $_POST('inputName2')
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 9 years ago.
Improve this question
For example, I have a simple form with POST target to PHP file:
<form action="language_foo.php" method="post">
<input type="text" name="fname" />
<input type="text" name="age" />
<input type="Submit" name="Submit">
</form>
In language_foo file, I have:
$lang = "$_lang['item.desc']" = $_POST['fname'];
How can I save the user input with exact the same structure, e.g:
$lang = "$_lang['item.desc']" = "Jane";
To another PHP file? I can do file_put_contents, but it will only put "Jane" to file.
Any suggestions?
Simply file_put_contents the below variable $variable_to_put_in_file
$variable_to_put_in_file = '$lang = "$_lang[\'item.desc\']" = "' . $_POST['fname'] . '";';
Are you looking for serialize() ? After filling your $_lang array, you can serialize the whole array to a string and dump it into a file by doing file_put_contents(..., serialize($_lang)), and load it back later with $_lang = unserialize(file_get_contents(...)).