This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
I have a HTML form which should post the data into an SQL database, No errors occur on submitting but the database does not receive the data.
<?php
include 'init.php';
//check if submit button is clicked
if(isset($_POST['submit'])) {
$User_Username = $_POST['User_Username'];
$User_First_Name = $_POST['User_First_Name'];
$User_Surname = $_POST['User_Surname'];
$User_Email = $_POST['User_Email'];
$User_Password = $_POST['User_Password'];
// prepare sql and bind parameters
$stmt = $pdo->prepare("INSERT INTO users (User_Username, User_First_Name, User_Surname,User_Password,User_Email)
VALUES (:User_Username, :User_First_Name, :User_Surname, :User_Password, :User_Email");
$stmt->bindParam(':User_Username', $User_Username);
$stmt->bindParam(':User_First_Name', $User_First_Name);
$stmt->bindParam(':User_Surname', $User_Surname);
$stmt->bindParam(':User_Email', $User_Email);
$stmt->bindParam(':User_Password', $User_Password);
$stmt->execute();
}
?>
<br>
<form action="" method="post">
<label>Username :</label><br>
<input type="text" name="User_Username" id="User_Username" required="required" placeholder=""/><br /><br />
<label>First Name :</label><br>
<input type="text" name="User_First_Name" id="User_First_Name" required="required" placeholder=""/><br /><br />
<label>Surname :</label><br>
<input type="text" name="User_Surname" id="User_Surname" required="required" placeholder=""/><br /><br />
<label>Email :</label><br>
<input type="email" name="User_Email" id="User_Email" required="required" placeholder=""/><br/><br />
<label>Password :</label><br>
<input type="Password" name="User_Password" id="User_Password" required="required" placeholder=""/><br /><br />
<br>
<input type="submit" value=" submit " name="submit"/><br />
</form>
</body>
</html>
You didn't close VALUES (....
You should have:
$pdo->prepare("INSERT INTO users (User_Username, A_Lot_more)
VALUES (:User_Username, :A_Lot_More)");
// ^ This one was missing
And you should NEVER save passwords as plain-text. Use something like password_hash() -- http://php.net/password_hash
Related
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Closed 2 years ago.
I want to start by saying i tried atleast 10 different solutions on this site, but none worked in my case so i was wondering if you guys could help me figure out what's wrong.
Form:
<form align="center" action=includes/signup.php method="post">
<input type="text" id="fname" name="fname" placeholder="First Name"><br>
<input type="text" id="lname" name="lname" placeholder="Last Name"><br>
<input type="text" id="uname" name="uname" placeholder="Username"><br>
<input type="text" id="email" name="email" placeholder="Email"><br>
<input type="text" id="phone" name="phone" placeholder="Phone Number"><br>
<button type="submit" value="submit" name="submit" name="save"> Add To Database </button>
</form>
signup.php
<?php
include_once 'dbh.php';
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$uname = $_POST['uname'];
$email = $_POST['email'];
$phone = $_POST['phone_no'];
$sql = "INSERT INTO `users` (f_name, l_name, username, email, phone_no)
VALUES ('$fname', '$lname', '$uname', '$email', '$phone');";
if (!mysqli_query($conn, $sql)) {
echo 'Not Inserted';
} else {
echo 'inserted';
}
header("refresh:3; url=../index.php?add=success");
My problem is that everytime i press the button, i get "Not Inserted", but when i changed the values from "$fname" to "David", David got inserted into the database. Which means the data from the form is not being received by this page.
I am using VS Code incase that makes a difference.
This question already has answers here:
$_POST is empty after form submit
(6 answers)
Closed 5 months ago.
Form:
<form id="register" method="POST" action="pro/register.php">
<input type="text" maxlength="30" placeholder="Username" id="user" /><br />
<input type="email" maxlength="64" placeholder="Email" id="email" /><br />
<input type="password" placeholder="Password" id="pass1" /><br />
<input type="password" placeholder="Confirm Password" id="pass2" /><br />
<input type="submit" value="Register" id="submit_register" />
</form>
pro/register.php page:
$user = $_POST['user'];
$email = $_POST['email'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
//Debug only
echo "<strong>Details:</strong><br>";
echo $user.", ".$email.", ".$pass1.", ".$pass2."<br>";
if($pass1!==$pass2){
header('Location:../login.php?alert=pass');
exit;
}
$hash = hash('sha256', $pass);
include "../inc/functions.php";
$salt = createSalt();
$hash = hash('sha256', $salt . $hash);
include "../inc/connect.php";
$stmt = $dbh->prepare("INSERT INTO `users`
(`username`,`email`,`password`,`salt`,`pic`)
VALUES (:username,:email,:password,:salt,:pic)");
$stmt->bindParam(':username',$user);
$stmt->bindParam(':email',$email);
$stmt->bindParam(':password',$hash);
$stmt->bindParam(':salt',$salt);
$stmt->bindParam(':pic',$pic);
$stmt->execute();
$dbh=NULL;
header('Location:../login.php?alert=newreg');
Output when form is posted:
Details:
, , ,
<input type="text" maxlength="30" placeholder="Username" id="user" name="user"/><br />
try adding the name field.
You must include the 'name' attribute in your form inputs, this is what determines where the value goes in $_POST.
I'm having a basic form like this:
<form method="post" action="register.php" class="form">
<input id="a" type="text" placeholder="Cod acces" name="access-code" size="20" required /><br>
<input id="b" type="password" placeholder="Parola" name="password" autocomplete="new-password" size="20" required /><br>
<input id="c" type="password" placeholder="Confirma parola" name="re-password" autocomplete="new-password" size="20" required /> <br><br>
<input type="submit" value="Register" name="register" />
</form>
In register.php i have the following 3 lines of code:
$password = $_POST["password"];
$repassword = $_POST["re-password"];
$acces_code = $_POST["access-code"];
Even if this code is as simple as it looks, my $_POST variable is empty. Even weirder, if I press F12 to see the request data, all variables and it's values are there.
I'm using XAMPP on Windows.
Here is the code I'm also with Windows version 10 and Xampp Server.
In your index.php paste this code below
<html>
<body>
<form method="post" action="register.php" class="form">
<input id="a" type="text" placeholder="Cod acces" name="access-code" size="20" required /><br>
<input id="b" type="password" placeholder="Parola" name="password" autocomplete="new-password" size="20" required /><br>
<input id="c" type="password" placeholder="Confirma parola" name="re-password" autocomplete="new-password" size="20" required /> <br><br>
<input type="submit" value="Register" name="register" />
</form>
</body>
</html>
and then in your register.php paste this code below
<?php
if(isset($_POST['register'])){
echo $password = $_POST["password"]." ";
echo $repassword = $_POST["re-password"]." ";
echo $acces_code = $_POST["access-code"]." ";
}
Successfully getting and outputting your input on the form. Hope this will help you
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">
<input type="text" name="duration" placeholder="Enter duration">
<input type="text" name="budget" placeholder="Enter Budget">
<input type="text" name="keyskills" placeholder="Enter Skills">
<input type="text" name="jobdescription" placeholder="Enter Job Description">
<input type="text" name="edate" placeholder="Click to enter expiry date">
<input type="text" name="cdexmin" placeholder="Enter Minimum Experience">
<input type="text" name="cdexmax" placeholder="Enter Maximum Experience">
<input type="submit">
</form>
<?php
if(isset($_POST['submit'])) {
try {
// Establish server connection and select database
$username = $_SESSION['username'];
$stmt = $db->prepare("SELECT * FROM employer INNER JOIN company ON employer.cid = company.cid WHERE employer.username='$username' ");
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$cid=$row['cid'];
$eid = $row['eid'];
$duration = $_POST['duration'];
$budget = $_POST['budget'];
$keyskills = $_POST['keyskills'];
$jobdescription = $_POST['jobdescription'];
$edate = $_POST['edate'];
$cdexmin = $_POST['cdexmin'];
$cdexmax = $_POST['cdexmax'];
$stmt = $db->prepare("INSERT INTO job(cid,eid,duration,budget,keyskills,jdesc,edate,cdexmin,cdexmax) values('$cid','$eid','$duration','$budget','$keyskills','$jobdescription','$edate','$cdexmin','$cdexmax') ");
$stmt->execute();
echo "JOB POSTED SUCCESSFULLY";
} catch(PDOException $e) {
echo "Error occurs:". $e->getMessage();
}
}
?>
Here is my code that I just created for a sample form that is trying to insert the values into database. My problem is that the values are not entering the database.
Why is it not working? Is there an syntax error I can't find?
Page parsing is easily done and it's not showing any errors but values are not entering the database.
You are using $_POST['submit'] but there is no any input with this name.
Add name to your input type submit as follow
<input type="submit" name="submit">
Change
<input type="submit">
to
<input type="submit" name="submit">
You have change in code. Add NAME attribute for POST form.
<input type="submit" name="submit">
This question already has answers here:
$_POST is empty after form submit
(6 answers)
Closed 6 months ago.
Form:
<form id="register" method="POST" action="pro/register.php">
<input type="text" maxlength="30" placeholder="Username" id="user" /><br />
<input type="email" maxlength="64" placeholder="Email" id="email" /><br />
<input type="password" placeholder="Password" id="pass1" /><br />
<input type="password" placeholder="Confirm Password" id="pass2" /><br />
<input type="submit" value="Register" id="submit_register" />
</form>
pro/register.php page:
$user = $_POST['user'];
$email = $_POST['email'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
//Debug only
echo "<strong>Details:</strong><br>";
echo $user.", ".$email.", ".$pass1.", ".$pass2."<br>";
if($pass1!==$pass2){
header('Location:../login.php?alert=pass');
exit;
}
$hash = hash('sha256', $pass);
include "../inc/functions.php";
$salt = createSalt();
$hash = hash('sha256', $salt . $hash);
include "../inc/connect.php";
$stmt = $dbh->prepare("INSERT INTO `users`
(`username`,`email`,`password`,`salt`,`pic`)
VALUES (:username,:email,:password,:salt,:pic)");
$stmt->bindParam(':username',$user);
$stmt->bindParam(':email',$email);
$stmt->bindParam(':password',$hash);
$stmt->bindParam(':salt',$salt);
$stmt->bindParam(':pic',$pic);
$stmt->execute();
$dbh=NULL;
header('Location:../login.php?alert=newreg');
Output when form is posted:
Details:
, , ,
<input type="text" maxlength="30" placeholder="Username" id="user" name="user"/><br />
try adding the name field.
You must include the 'name' attribute in your form inputs, this is what determines where the value goes in $_POST.