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
form.html
<form name="input" action="process.php" method="post">
<input type="text" name="user" placeholder="Enter Your Name">
<input type="text" name="message" placeholder="Enter A Message">
<br>
<input class="shout-btn" type="submit" name="submit" value="Shout It Out">
</form>
process.php
<?php
include "database.php";
echo var_dump($_POST);
if(isset($_POST['submit'])){
$user = mysqli_real_escape_string($con,$_POST['user']);
$message = mysqli_real_escape_string($con,$_POST['message']);
//SET TIMEZONE
date_default_timezone_set('America/New_York');
$time = date('h:i:s a',time());
if (!isset($user) || $user == "" || !isset($message) || $message == "") {
echo "bad";
} else {
echo "good";
}
}
?>
For some reason $_POST gives me text variable:
array(3) { ["text"]=> string(5) "david" ["message"]=> string(27) "adasdasdasdasdasd asdasdasd" ["submit"]=> string(12) "Shout It Out" }
Notice: Undefined index: user in D:\xampp\htdocs\php\shoutit\process.php on line 6
bad
Either you've retyped form.html correctly on SO and there is an error in you actual code (mainly calling the name field text), or you had it like this, then fixed it and the your browser is caching the old version.
Easy way to check, in your browser view source on the form and check the form name.
Clear your cache and try again.
Related
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
Hello i want to check if the textarea isnt empty and i still can´t get the echo that i want even when the textarea isnt empty and input is set
here is my code:
<form method="post" action="">
<input type="text" name="jmeno"/>
<textarea name="textarea" id="textarea" rows="5" cols="40"></textarea>
<input type="submit" name="submit"/>
</form>
<?php
if(isset($_POST['jmeno']) AND !empty($_POST['textarea'])){
echo "dokončeno";
}
?>
How about this:
if (!is_null($_POST['jmeno']) && strlen(trim($_POST['jmeno'])) > 0) {
echo "dokončeno";
}
As far as I understand you want your code to check if the submit button is pressed and the textarea isn't empty. I would say the code is:
if(isset($_POST['jmeno'])){
if(strlen($_POST['textarea']) > 0){
echo "dokončeno";
}
}
OR simply:
if(isset($_POST['jmeno']) && strlen($_POST['textarea']) > 0){
echo "dokončeno";
}
if (isset($_POST['jmeno']) && strlen(trim($_POST['textarea']))>0)
{
echo "dokončeno";
}
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
How do I Get This HTML 5 Form To Give PHP The Input Data Then Display It On The Screen. I want to collect data in a form. Convert it into a php variable and then echo it out in a way that I can read it.
<form>
First name:<br>
<input type="text" name="name">
</form>
<body>
<pre>
<?php
$taco = htmlspecialchars($_POST["name"]) . '!';
$taco = $_POST;
echo $taco;
?>
</pre>
</body
</html>
How about the following:
<?php
if($_POST) { // check if the page is posted not with a $_GET
foreach($_POST as $field => $value) { // Foreach field
$value = strip_tags($value); // Strip html tags (you can add more)
echo 'Field: '.$field.' has value: '.$value.'<br>'; // output
}
}
?>
<form action="" method="post">
First name: <input type="text" name="first_name">
<input type="submit" value="Display">
</form>
Just put it all in one php file. You can add as many fields as you want.
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 years ago.
Improve this question
From the HTML page I am submitting some records to a PHP page, where the records will be saved to the DB and then show a
message saved successfully
message to the user on the same HTML page.
When i submit my form, the records are sent to the HTML page and it displays the success message on another page and not on the same HTML page (where the form code is written). How can i correct it?
HTML
<form action="save.php" class="tsc_form_contact_dark nolabel" method="POST">
<input type="text" name="name" class="form-input" placeholder="Name (required)" required />
<input type="email" name="email" class="form-input" placeholder="Email (required)" required />
<input class="form-btn" type="submit" value="Send Message" />
</form>
PHP
<?php
$name = $_POST["name"];
$email = $_POST["email"];
// Do other stuff
echo "Success";
?>
All you need to do is set a message variable. Something like this:
$msg=isset($_GET['msg']) ? $_GET['msg'] : "";
<div><?php echo $msg; ?></div>
<form action="save.php" class="tsc_form_contact_dark nolabel" method="POST">
//rest of the form
And in the php, you need to redirect to the form page something likt this:
<?php
$name = $_POST["name"];
$email = $_POST["email"];
// Do other stuff
$msg = "Success";
$redirecturl = "form_page.php?msg=".$msg;
header("Location: $redirecturl");
?>
There could be other methods to send result message using session, but I would recommend not doing that.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
$redirect=$_GET["r"];
if ( isset($_GET["r"]) ){
header("location: http://" .$redirect);
} else {
$redirect = "mickiewiki.nl/login/profile.php";
header("location: http://" .$redirect);
this code won't work? I want it to be like if I go to mickiewiki.nl/login/login.php?r=mickiewiki.nl/Doneer.php that when I login I go back to the page Doneer.php
When I login, I am always being sent to profile.php no matter if I add my r or not
<?php
//allow sessions to be passed so we can see if the user is logged in
session_start();
//connect to the database so we can check, edit, or insert data to our users table
$database = mysql_select_db('***', $con) or die(mysql_error());
//include out functions file giving us access to the protect() function made earlier
include "login/functions.php";
$selectedid = $_GET['id'];
if(empty($selectedid)) {
$selectedid = $_SESSION['uid'];
}
if(strcmp($_SESSION['uid'],"") == 0){
header("location: login/login.php?r=mickiewiki.nl/Doneer.php");
} else {
?>
In your form on your website, you are not setting r through GET. You have username, password & submit for your form - and nothing for GET. If you are submitting r with your form (which I cannot see that you are), then you should probably be checking for $_POST['r'] instead of $_GET['r'].
Basically, you need to add a hidden field for your r variable and submit that along with your form.
<form method="post" action="login.php">
<input type="hidden" name="r" value="<?php print $_GET['r']; ?>">
<p><label for="name">Username: </label>
<input type="text" name="username" /></p>
<p><label for="pwd">Password: </label>
<input type="password" name="password" /></p>
<p>
<input type="submit" id="submit" value="Login" name="submit" />
</form>
but, you must do a control for $_GET["r"] ... and why it doesn't work?
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
I'm trying already for two hours to understand what am I doing wrong and I can't figure it out:
My HTML code:
<form action="php/images.php" method="post" enctype="multipart/form-data">
<input type="file" name="image" value="on" id="file">
<input type="submit" name="submit" value="Submit">
</form>
My PHP:
if ( isset($_POST['image'])
&& $_POST['image']=="on")
{
imageUpload();
}
When I removed the if in the PHP file and immediately entered the inner function imageUpload() I've been able to upload the image, why is the variable name I pass using post isn't working?!
Your upload data will be in $_FILES array:
<?php print_r($_FILES['image']); ?>
So something like this:
<?php
if($_SERVER['REQUEST_METHOD'] === 'POST'){
if(isset($_FILES['image']) && $_FILES['image']['error'] == 0){
imageUpload();
}
}
?>
browse button lets you make an array and can be obtain via $_FILES['image'];.Similarly $_FILES also gives an array(size etc).Try var_dump($_FILES); to get the values.