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')
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 7 years ago.
Improve this question
This is my code, I get variable from textbox but nothing appears.
This code checks if a input is number:
this is a number
or not:
this is not a number
<?php
echo'<form method="post" action="">';
echo '<input type=text name=t/>';
echo'<input type=submit name=su/>';
echo'</form>';
if(isset($_POST['su']))
{
if (ctype_digit($_POST['t'])) {
echo "This is number.\n";
} else {
echo "This is not a number.\n";
}
}
?>
All of code is in one page.
Your code is failing because you have unquoted elements/attributes.
The following require quotes for:
echo '<input type=text name=t/>';
^^^^ ^^^^^^
echo'<input type=submit name=su/>';
^^^^^^ ^^^^^^^
Modify your code to read as:
<?php
echo'<form method="post" action="">';
echo '<input type="text" name="t"/>';
echo'<input type="submit" name="su"/>';
echo'</form>';
if(isset($_POST['su']))
{
if (ctype_digit($_POST['t'])) {
echo "This is number.\n";
} else {
echo "This is not a number.\n";
}
}
?>
Certain web browsers will not accept unquoted elements/attributes and will simply be ignored, such as the current version of Firefox and will fail silently even with error reporting set to catch/display, strangely enough.
You can test for a number using the JS function isNAN. PHP processes on the server so once the page is loaded it is not available. Javascript is available though after the page loads. JS is client side and is executed on the browser. Here's a js solution:
var test = 1;
if(isNaN(test)) {
alert('String');
} else {
alert('number');
}
This would alert number.
Here's a longer write up on that JS function, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN.
If method is not defined in <form> then the default is GET. So
<form>
is the same as
<form method="GET">
If you want to use $_POST, you need to do
<form method="POST">
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);
?>