My form doesn't appear in website [duplicate] - php

This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 5 years ago.
I have a question here. Somehow my created registration form doesn't appear on the website. When I am deleting all the include files, it shows, but with the files - it does not. Could someone help me to solve this problem? What I'm doing wrong?
Here is my register.php file:
<!DOCTYPE html>
<?php
include 'classes/connection.php';
include 'classes/register.php';
$connection = new Connection();
$users = new Users($connection);
$users->insertUserValues();
?>
<html>
<head>
<meta charset="UTF-8">
<title>
</title>
</head>
<body>
<div class="form">
<form method ="post" action="register.php">
Vardas:<br>
<input type="text" name="name" id="name" placeholder="Vardas" required>
<br>
Pavardė:<br>
<input type="text" name="surname" id="surname" placeholder="Pavardė" required>
<br>
Prisijungimo vardas:<br>
<input type="text" name="username" id="username" placeholder="Prisijungimo vardas" required>
<br>
Slaptažodis:<br>
<input type="password" name="password" id="password" placeholder="Slaptažodis" required>
<br>
Patvirtinti slaptažodį:<br>
<input type="password" name="confirm_password" id="confirm" placeholder="Slaptažodis" required>
<br>
El. pašto adresas: <br>
<input type="email" name="email" id="email" placeholder="El. pašto adresas" required>
<br><br>
<input type="submit" name="submit" id="submit" value="Registruotis">
</form>
</div>
</body>
The link I'm entering to the registration form is correct, I've also tried to go from index.php, but it's the same..

Without checking if $_POST['submit'] was set (or any other post var), you immediately call $users->insertUserValues();
What happens inside that? Can we see? I would suggest an if statement to check the form was posted before trying to process non-existent data.

Related

HTML and PHP - How to seperate 2 forms on a single page?

I'm pretty new to HTML and currently I'm making an assignment where I have to make a HTML Form for data input and write the input to a file using PHP.
The writing to file works, but I getting the following comment on my code:
You have tested whether something has been posted, but what happens to your code if there are 2 forms on your page?
I kinda know what is being meant with this, but I am not that fluent to know how to solve this issue or where this comes from in my code.. Does this has to do with the action of the form set to $_SERVER["PHP_SELF"], the name of the submit button set wrong or anything else?
I've tried looking online for HTML forms and how to have 2 on the same page.. but I could not find anything really helpfull. If anyone can help or maybe point me to some info that explains this in detail (and with examples preferably) that would be great!
Here is just my HTML form as I have it with the PHP part checking for the submit. Rest of the code I left out as it is not relevant..
<html>
<head>
<title>Save and show data</title>
</head>
<body>
<h2>Fill in the form below</h2>
<form method="post" action="<?php $_SERVER["PHP_SELF"]; ?>">
<label for='name'>Naam:</label><br>
<input type="text" id="name" name="name" placeholder = "John Doe" required><br>
<label for='address'>Adres:</label><br>
<input type="text" id="address" name="address" placeholder = "Sunset lane 10" required><br>
<label for='zip'>Postcode:</label><br>
<input type="text" id="zip" name="zip" placeholder = "15922" required><br>
<label for='residence'>Woonplaats:</label><br>
<input type="text" id="woonplaats" name="woonplaats" placeholder = "Somewhere" required><br>
<label for='phone'>Telefoonnummer:</label><br>
<input type="tel" id="phone" name="phone" placeholder = "0678945124" required><br>
<label for='email'>E-mail:</label><br>
<input type="email" id="email" name="email" placeholder = "johndoe#email.com" required><br><br>
<input type="submit" name="submit_data" value="Save"><br>
</form>
<?php
if(isset($_POST["submit_data"]))
{
// magic stuff happens here
}
Do you mean something like this? Each submit button has its own validation.
<?php
if (isset($_POST['submit_data'])) {
//first form
}
if (isset($_POST['edit_data'])) {
//second form
}
?>
<form method="post" action="<?php $_SERVER["PHP_SELF"]; ?>">
<label for='name'>Naam:</label><br>
<input type="text" id="name" name="name" placeholder = "John Doe" required><br>
<input type="submit" name="submit_data" value="Save"><br>
</form>
<form method="post" action="<?php $_SERVER["PHP_SELF"]; ?>">
<label for='name'>Naam:</label><br>
<input type="text" id="name" name="name" placeholder = "John Doe" required><br>
<input type="submit" name="edit_data" value="Edit"><br>
</form>

How can I replace a from value using a cookie?

I want to use cookies to remember the usernames I add and replace the default value with the last used username.
I have the following html code:
<link href = "login.css" rel = "stylesheet">
<html>
<head>
</head>
<body>
<form action="login.php" method="post">
<label for="uname"><b>Username</b></label>
<input type="text" placeholder="Enter Username" value ="?" name="uname" required>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<button type="submit">Login</button>
<label>
<input type="checkbox" checked="checked" name="remember"> Remember me
</label>
</form>
</body>
</html>
this is login.php:
<?php
echo("Success!");
if($_SERVER["REQUEST_METHOD"] == "POST"){
setcookie("username", $_POST["uname"], time()+30*24*60*60);
}
?>
I want to replace the '?' from
<input type="text" placeholder="Enter Username" value ="?" name="uname" required>
with the value held by the cookie.
This is what I do in value.php:
<?php
if(isset($_COOKIE["username"]))
echo $_COOKIE["username"];
?>
Can I do something like:
<input type="text" placeholder="Enter Username" value ="value.php" name="uname" required>
so I don't have to write the php code there? This doesn't work, the value I get in the form is "value.php"
I'm not too familiar with PHP, but can't you just do:
<input type="text" placeholder="Enter Username" value="<?php include 'value.php'?>" name="uname" required>
or something like that?

html form can not send data to [duplicate]

This question already has answers here:
How can I get useful error messages in PHP?
(41 answers)
Closed 2 years ago.
My html is not sending field data to php in same file until action and method attribute are placed.... kindly identify my error and guide me.....
<pre><code>
<?php
if(isset($_post['submit'])){
echo "Yes is is working";
}
?>
<!DOCTYPE html>
<html>
<head>
<title>testing form</title>
</head>
<body>
<br><br><br><br>
<form action="test.php" method="post">
<input type="text" name="name" placeholder="Enter Name"><br>
<input type="text" name="location" placeholder="ENter location"><br>
<input type="submit" name="submit">
</form>
</body>
</html>
</pre></code>
Probably you could try by setting id instead of name.
Eg.
<form action="test.php" method="post">
<input type="text" id="name" placeholder="Enter Name"><br>
<input type="text" id="location" placeholder="ENter location"><br>
<input type="submit" id="submit">
</form>

HTML form not sending POST data (or PHP not receiving it)

Yes, forms of this question are asked all the time. Due to the infinite possible ways that one can construct a form/php pair, my question still is different. (and much simpler)
I have:
<html>
<body>
<form id="request-inspecton" action="test_form_processor.php" method="POST">
<label class="text-label" for="FirstName">*first name:</label>
<input class="text-input" type="text" name="FirstName" id="FirstName" required="required" placeholder="First Name">
<label class="text-label" for="LastName">*last name:</label>
<input class="text-input" type="text" name="LastName" id="LastName" required="required" placeholder="Last Name">
<input class="button-input" type="submit" value="send" id="buttonSend" name="submitForm" placeholder="Submit form" value="POST">
</form>
</body>
</html>
and:
<?php
var_dump($_POST);
print $_POST["FirstName"];
?>
But all I get is:
array(0) { }
Golly, I just can't figure out what is wrong!\
Incidentally, example currently at:
http://checkitouthomeinspection.com/test_form.html
Strangely enough, it now works in both FF and Chrome. Beats me what the problem was. Thanks for the help. Case closed.

Why are my form variables not passing through POST?

I am sending form data through POST, but the corresponding POST variables are not set, and do not.
Also, when I store POST data into local PHP variables, I seem to be unable to use those variables. (Once I resolve the first issue, I have a feeling I will be able to user the variables too.)
My error messages output by the second page (see below) is:
Notice: Undefined variable: postUsername in (...somepath)\scripts\create-member.php on line 10
(Form page) :
<form action="scripts/create-member.php" method="POST">
<input type="text" name"username" value="" placeholder="User Name"> <br />
<input type="password" name"password" value="" placeholder="Password"> <br />
<input type="password" name"passwordConfirm" value="" placeholder="Confirm Password"> <br />
<!-- ?type email or type text -->
<input type="email" name"email" value="" placeholder="Email" autofocus> <br />
<input type="submit" name="submitRegistration" value="Register!">
</form>
(Second page) scripts\create-member.php:
<?php
//!proper way to declare variables obtained from POST.
// Data from form "register.php"
if ( isset($_POST['username']) ) {
$postUsername = $_POST['username'];
}
echo $postUsername; // <-- this is line 10
?>
I've tried using isset() for the submit button too, but that didn't solve the problem.
I've simplified the code by a lot here, and ran it testing it too.
In your html code, you have missed = for name
name="username"
Instead of name"username"
Here's your fixed code.
<input type="text" name="username" value="" placeholder="User Name"> <br />
<input type="password" name="password" value="" placeholder="Password"> <br />
<input type="password" name="passwordConfirm" value="" placeholder="Confirm Password"> <br />
<!-- ?type email or type text -->
<input type="email" name="email" value="" placeholder="Email" autofocus> <br />
the ploblem is not at register.php
you can try to write like this:
if ( isset($_POST['username']) ) {
$postUsername = $_POST['username'];
echo $postUsername;
}
I had a similar problem posting to an index.php file in a folder.
<form id="register" name="register" method="POST" action="/register">
// BROKEN
all $_POST vars were empty until I added a trailing forward slash to the form post action
<form id="register" name="register" method="POST" action="/register/">
// WORKS

Categories