html form validation using php - php

I have created a html form which has signup as well as login. Firstly I want to register the user using signup form and then make him login then redirect to another page. For this I'm using php with apache(xampp) server. The signup panel is working fine, but when I try to login, black column is added to database
My html code is like this
<form method="POST" action="yoga_signup.php">
<div class="row" style=" margin-top:4rem; margin-left:24rem;">
<div class="col-md-6 mx-auto p-0">
<div class="card">
<div class="login-box">
<div class="login-snip"> <input id="tab-1" type="radio" name="tab" class="sign-in" checked><label for="tab-1" class="tab">Login</label> <input id="tab-2" type="radio" name="tab" class="sign-up"><label for="tab-2" class="tab">Sign Up</label>
<div class="login-space">
<div class="login">
<input type="hidden" name="for_page" value="login">
<div class="group"> <label for="user" class="label">Username</label> <input id="user" type="text" class="input" name="username" placeholder="Enter your username" > </div>
<div class="group"> <label for="pass" class="label">Password</label> <input id="pass" type="password" name="password_1" class="input" data-type="password" placeholder="Enter your password" > </div>
<div class="group"> <input id="check" type="checkbox" class="check" checked> <label for="check"><span class="icon"></span> Keep me Signed in</label> </div>
<div class="group"> <input type="submit" class="button" value="Sign In"> </div>
<div class="hr"></div>
</div>
<div class="sign-up-form">
<input type="hidden" name="for_page" value="signup">
<div class="group"> <label for="user" class="label">Username</label> <input id="user" type="text" name="username" class="input" placeholder="Create your Username"> </div>
<div class="group"> <label for="pass" class="label">Password</label> <input id="pass" type="password" name="password_1" class="input" data-type="password" placeholder="Create your password" > </div>
<div class="group"> <label for="pass" class="label">Repeat Password</label> <input id="pass" type="password" name="password_2" class="input" data-type="password" placeholder="Repeat your password"> </div>
<div class="group"> <label for="pass" class="label">Email Address</label> <input id="pass" type="text" class="input" name="email" placeholder="Enter your email address" > </div><br>
<div class="group"> <input type="submit" class="button" value="Sign Up"> </div>
<div class="hr"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
and my php code is this
<?php
session_start();
$conn= new mysqli("localhost","root","","yoga");
if($_SERVER["REQUEST_METHOD"]=="POST"){
$TypeOfRequest=$_POST['for_page'];
if($TypeOfRequest=="signup"){
$user=$_POST['username'];
$pass_1=$_POST['password_1'];
$pass_2=$_POST['password_2'];
$mail=$_POST['email'];
if($pass_1===$pass_2){
$val=" INSERT INTO yoga_login(username,password_1,password_2,email) VALUES('$user','$pass_1','$pass_2','$mail')";
if($conn->query($val)===TRUE){
header('Location: login.html');
}else{
echo "registration unsucessfull";
}
}
if($pass_1!==$pass_2){
echo "please enter the same password";
}
}
$TypeofRequest = $_POST['for_page'];
if($TypeofRequest=="login"){
$user=$_POST['username'];
$pass_1=$_POST['password_1'];
$sql="SELECT * FROM yoga_login WHERE username='$user' AND password='$pass_1'";
$RunQuery = mysqli_query($conn,$sql);
$CheckNumberOfUsers = mysqli_num_rows($RunQuery);
//echo $CheckNumberOfUsers;
if($CheckNumberOfUsers==1){
$_SESSION['username'] = $user;
header('location:blogs.html');
}else{
echo "invalid credential";
}
}
mysqli_close($conn);
}

You can dump out what you are sending in the yoga_signup.php at the start of the file:
die('<pre>' . print_r($_POST, true) . '</pre>');
Then you can see this:
Array
(
[tab] => on
[for_page] => signup
[username] =>
[password_1] =>
[password_2] =>
[email] =>
)
so the for_page field's value is signup - and I was pressing the Sign In button
Then you go back to the HTML file and you can see that you are using the same form for the request, so with the second <input type="hidden" name="for_page" value="signup">, you are overwriting the first for_page value.
So instead of this you should create 2 forms and set them like this:
<div class="row" style=" margin-top:4rem; margin-left:24rem;">
<div class="col-md-6 mx-auto p-0">
<div class="card">
<div class="login-box">
<div class="login-snip">
<input id="tab-1" type="radio" name="tab" class="sign-in" checked>
<label for="tab-1" class="tab">Login</label>
<input id="tab-2" type="radio" name="tab" class="sign-up">
<label for="tab-2" class="tab">Sign Up</label>
<div class="login-space">
<form method="POST" action="yoga_signup.php">
<div class="login">
<input type="hidden" name="for_page" value="login">
<div class="group">
<label for="user" class="label">Username</label>
<input id="user" type="text" class="input" name="username" placeholder="Enter your username" >
</div>
<div class="group">
<label for="pass" class="label">Password</label>
<input id="pass" type="password" name="password_1" class="input" data-type="password" placeholder="Enter your password" >
</div>
<div class="group">
<input id="check" type="checkbox" class="check" checked>
<label for="check">
<span class="icon">
</span> Keep me Signed in
</label>
</div>
<div class="group"> <input type="submit" class="button" value="Sign In"> </div>
<div class="hr"></div>
</div>
</form>
<form method="POST" action="yoga_signup.php">
<div class="sign-up-form">
<input type="hidden" name="for_page" value="signup">
<div class="group"> <label for="user" class="label">Username</label> <input id="user" type="text" name="username" class="input" placeholder="Create your Username"> </div>
<div class="group"> <label for="pass" class="label">Password</label> <input id="pass" type="password" name="password_1" class="input" data-type="password" placeholder="Create your password" > </div>
<div class="group"> <label for="pass" class="label">Repeat Password</label> <input id="pass" type="password" name="password_2" class="input" data-type="password" placeholder="Repeat your password"> </div>
<div class="group"> <label for="pass" class="label">Email Address</label> <input id="pass" type="text" class="input" name="email" placeholder="Enter your email address" > </div><br>
<div class="group"> <input type="submit" class="button" value="Sign Up"> </div>
<div class="hr"></div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
Parameters in the PHP file after modification:
Array
(
[for_page] => login
[username] => asdf
[password_1] => asdf
)
Helpful sidenotes to improve your code:
passwords should be encrypted in the database
the mysql query is vulnerable against SQL injection
the second password field used to be required, because if the input type is password, then you can't see the characters, so it's like a proofread for the user to make sure that you won't miss the password. Because of this you don't need to store it in the database, but use it to check if it was written correctly in the first field.
use the redirection headers with die
close the mysql connection before the redirection
I found some issues at the login part of the code.
Instead of the password filed in the SQL query string you should use an existing password field from your database; for example the password_1 field.
Replacing that and fixing some minor issues, plus a bit of beautifying you will get this code for the login part:
if($TypeofRequest=="login"){
$username = $_POST['username'];
$password = $_POST['password_1'];
$sql="SELECT * FROM yoga_login WHERE username='{$username}' AND password_1='{$password}'";
$result = $conn->query($sql);
$conn->close();
if (empty($result)) {
die('invalid credentials');
}
$_SESSION['username'] = $user;
header('location:blogs.html');
die();
}

Related

redirecting to another page in html

I am trying to redirect html form page after submission of data to an another html page using meta req method. Is their any other method ro redirect page as the problem with this is that it shows an intermediate page of our php command which i dont want
my html code is
<form method="POST" action="yoga_signup.php">
<div class="row" style=" margin-top:4rem; margin-left:24rem;">
<div class="col-md-6 mx-auto p-0">
<div class="card">
<div class="login-box">
<div class="login-snip"> <input id="tab-1" type="radio" name="tab" class="sign-in" checked><label for="tab-1" class="tab">Login</label> <input id="tab-2" type="radio" name="tab" class="sign-up"><label for="tab-2" class="tab">Sign Up</label>
<div class="login-space">
<div class="login">
<input type="hidden" name="for_page" value="login">
<div class="group"> <label for="user" class="label">Username</label> <input id="user" type="text" class="input" name="username" placeholder="Enter your username" required> </div>
<div class="group"> <label for="pass" class="label">Password</label> <input id="pass" type="password" name="password_1" class="input" data-type="password" placeholder="Enter your password" required> </div>
<div class="group"> <input id="check" type="checkbox" class="check" checked> <label for="check"><span class="icon"></span> Keep me Signed in</label> </div>
<div class="group"> <input type="submit" class="button" value="Sign In"> </div>
<div class="hr"></div>
my php code for the same is
<?php
session_start();
$conn= new mysqli("localhost","root","","yoga");
if($_SERVER["REQUEST_METHOD"]=="POST"){
$TypeOfRequest=$_POST['for_page'];
if($TypeOfRequest=="signup"){
$user=$_POST['username'];
$pass_1=$_POST['password_1'];
$pass_2=$_POST['password_2'];
$mail=$_POST['email'];
if($pass_1===$pass_2){
$val=" INSERT INTO yoga_login(username,password_1,password_2,email) VALUES('$user','$pass_1','$pass_2','$mail')";
if($conn->query($val)===TRUE){
echo "redirecting to login page.<meta http-equiv='refresh' content='1;login.html'>";
}else{
echo "registration unsucessfull";
}
}
if($pass_1!==$pass_2){
echo "please enter the same password";
}
}
mysqli_close($conn);
}
so is their any other method which doesnt shows the intermediate page like this
Just replace:
echo "redirecting to login page.<meta http-equiv='refresh' content='1;login.html'>";
With the PHP redirect:
header('Location: login.html');
exit; // this is normally a good idea

Checked Radio Button Inside Echo In PHP

How i can checked radio button inside echo method ?
<?php
if(isset($_GET['sid'])){
echo'
<div class="right_col" role="main">';
$a=$_GET['sid'];
$update = $obj->selectdata($a);
foreach($update as $upd)
{
$upd['sname'];
echo'
<h1 class="text-center">update student</h1>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-8">
<form class="form-horizontal" action="dashboard.php?sid='.$upd['id'].'" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label>Name</label>
<input type="text" value="'.$upd['sname'].'" name="sname" required class="form-control"/>
</div>
<div class="form-group">
<label>Father Name</label>
<input type="text" value="'.$upd['sfname'].'" name="sfname" required class="form-control"/>
</div>
<div class="form-group">
<label>Email</label>
<input type="email" value="'.$upd['email'].'" name="semail" required class="form-control"/>
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="spass" placeholder="Change Password" required class="form-control"/>
</div>
<div class="form-group">
<label>Date Of Birth</label>
<input type="date" value="'.$upd['dob'].'" name="sdob" required class="form-control"/>
</div>
<div class="form-group">
<label>Gender</label>
<div class="radio-inline">
<label><input type="radio" name="sgender" if($s_gender == Male){echo checked=checked} value="Male" />Male</label>
</div>
<div class="radio-inline">
<label><input type="radio" name="sgender" if($s_gender == Female){echo checked=checked} value ="Female" />Female</label>
</div></div>
<div class="form-group">
<label>Contact</label>
<input type="text" name="scontact" value="'.$upd['contact'].'" required class="form-control"/>
</div>
<div class="form-group">
<label>Address</label>
<input type="text" name="saddress" value="'.$upd['address'].'" required class="form-control"/>
</div>
<div class="form-group">
<label>Photo</label>
<input type="file" name="spic" required class="form-control"/>
</div>
<button type="submit" name="upt_form" class="btn btn-default">Submit</button>
</form>
</div>
</div>';
}
}
else {
echo'
<div class="right_col" role="main">
<h1 class="text-center">add student</h1>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-8">
<form class="form-horizontal" action="dashboard.php" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label>Name</label>
<input type="text" name="sname" required class="form-control"/>
</div>
<div class="form-group">
<label>Father Name</label>
<input type="text" name="sfname" required class="form-control"/>
</div>
<div class="form-group">
<label>Email</label>
<input type="email" name="semail" required class="form-control"/>
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="spass" required class="form-control"/>
</div>
<div class="form-group">
<label>Date Of Birth</label>
<input type="date" name="sdob" required class="form-control"/>
</div>
<div class="form-group">
<label>Gender</label>
<div class="radio-inline">
<label><input type="radio" name="sgender" value="Male" required/>Male</label>
</div>
<div class="radio-inline">
<label><input type="radio" name="sgender" value ="Female"required />Female</label>
</div></div>
<div class="form-group">
<label>Contact</label>
<input type="text" name="scontact" required class="form-control"/>
</div>
<div class="form-group">
<label>Address</label>
<input type="text" name="saddress" required class="form-control"/>
</div>
<div class="form-group">
<label>Photo</label>
<input type="file" name="spic" required class="form-control"/>
</div>
<button type="submit" name="stu_form" class="btn btn-default">Submit</button>
</form>
</div>
</div>';
}
?>
Work like this:
<input type="radio" '.($s_gender == Female ? 'checked="checked"' : "").' name="sgender" value ="Female" />
<?php
if(isset($_GET['sid'])){
echo'
<div class="right_col" role="main">';
$a=$_GET['sid'];
$update = $obj->selectdata($a);
foreach($update as $upd)
{
$upd['sname'];
echo'
<h1 class="text-center">update student</h1>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-8">
<form class="form-horizontal" action="dashboard.php?sid='.$upd['id'].'" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label>Name</label>
<input type="text" value="'.$upd['sname'].'" name="sname" required class="form-control"/>
</div>
<div class="form-group">
<label>Father Name</label>
<input type="text" value="'.$upd['sfname'].'" name="sfname" required class="form-control"/>
</div>
<div class="form-group">
<label>Email</label>
<input type="email" value="'.$upd['email'].'" name="semail" required class="form-control"/>
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="spass" placeholder="Change Password" required class="form-control"/>
</div>
<div class="form-group">
<label>Date Of Birth</label>
<input type="date" value="'.$upd['dob'].'" name="sdob" required class="form-control"/>
</div>
<div class="form-group">
<label>Gender</label>
<div class="radio-inline">
if($upd['gender']== "Male") {
echo '
<label><input cheacked= "cheacked" type="radio" name="sgender" value="Male" />Male</label>
</div>';
}
else {
echo' <div class="radio-inline">
<label><input type="radio" cheacked= "cheacked" name="sgender" value ="Female" />Female</label>
</div></div>';
}
<div class="form-group">
<label>Contact</label>
<input type="text" name="scontact" value="'.$upd['contact'].'" required class="form-control"/>
</div>
<div class="form-group">
<label>Address</label>
<input type="text" name="saddress" value="'.$upd['address'].'" required class="form-control"/>
</div>
<div class="form-group">
<label>Photo</label>
<input type="file" name="spic" required class="form-control"/>
</div>
<button type="submit" name="upt_form" class="btn btn-default">Submit</button>
</form>
</div>
</div>';
}
}
else {
echo'
<div class="right_col" role="main">
<h1 class="text-center">add student</h1>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-8">
<form class="form-horizontal" action="dashboard.php" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label>Name</label>
<input type="text" name="sname" required class="form-control"/>
</div>
<div class="form-group">
<label>Father Name</label>
<input type="text" name="sfname" required class="form-control"/>
</div>
<div class="form-group">
<label>Email</label>
<input type="email" name="semail" required class="form-control"/>
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="spass" required class="form-control"/>
</div>
<div class="form-group">
<label>Date Of Birth</label>
<input type="date" name="sdob" required class="form-control"/>
</div>
<div class="form-group">
<label>Gender</label>
<div class="radio-inline">
<label><input type="radio" name="sgender" value="Male" required/>Male</label>
</div>
<div class="radio-inline">
<label><input type="radio" name="sgender" value ="Female"required />Female</label>
</div></div>
<div class="form-group">
<label>Contact</label>
<input type="text" name="scontact" required class="form-control"/>
</div>
<div class="form-group">
<label>Address</label>
<input type="text" name="saddress" required class="form-control"/>
</div>
<div class="form-group">
<label>Photo</label>
<input type="file" name="spic" required class="form-control"/>
</div>
<button type="submit" name="stu_form" class="btn btn-default">Submit</button>
</form>
</div>
</div>';
}
?>
use this code then let me know if it resolved your issue, you had to put if and else with your problem in proper way you used wrong variable for get gender value.

Failure receiving POST results in PHP/HTML

I've done tests and it's definitely not a problem with the database, it connects fine and variables input if specified, (the integers work). Note that the {} brackets around the variables in the sql statement, for some reason need to be there for it to work, if someone could tell me why that'd be great.
The main problem is the POST for receiving from the form, nothing echoes, nor inputs to the database. Can anyone help? Thanks in advance.
PHP:
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$username = $_POST['username'];
$pw = $_POST['pw'];
$email = $_POST['email'];
$wins = 0;
$losses = 0;
$played = 0;
$earnings = 0;
$sql = "
INSERT INTO users (first_name, last_name, username, password, email, last_login, date_joined, wins, losses, played, earnings) VALUES
('{$firstName}','{$lastName}','{$username}','{$pw}','{$email}','1111','2222','{$wins}','{$losses}','{$played}','{$earnings}')
";
if(!mysql_query($sql, $con)){
echo 'Worked';
} else {echo 'Failed';}
HTML:
<form id="registration_form" action="http://valhq.com/register/" method="POST">
<div class="signup_form_content_names">
<div class="signup_form_input_fn">
<input type="text" class="signup_input_style_fn" id="firstName" placeholder="First Name" maxlength="20">
</div>
<div class="signup_form_input_ln">
<input type="text" class="signup_input_style_ln" id="lastName" placeholder="Last Name" maxlength="20">
</div>
</div>
<div class="signup_form_content">
<div class="signup_form_input">
<input type="text" class="signup_input_style" placeholder="E-Mail" id="email" maxlength="40">
</div>
<div class="signup_form_input">
<input type="text" class="signup_input_style" placeholder="Confirm E-Mail" id="emailconf" maxlength="40">
</div>
<div class="signup_form_input">
<input type="text" class="signup_input_style" placeholder="Desired Username" id="username" maxlength="20">
</div>
<div class="signup_form_input">
<input type="password" class="signup_input_style" placeholder="Password" id="pw" maxlength="64">
</div>
<div class="signup_form_input">
<input type="password" class="signup_input_style" placeholder="Confirm Password" id="pwconf" maxlength="64">
</div>
<div class="signup_tc">
<p>
<input type="checkbox" id="terms" value="terms_true" style="vertical-align:middle;">
I agree to the Terms and Conditions
<span class="signup_tc_required">*</span>
</p>
</div>
<input type="submit" id="submit" class="signup_submit" value="Create Account">
<div class="signup_alreadyMember">
Already a member? Login.
</div>
<div class="signup_error">
<span class="signup_error" id="fn_error_message"></span>
<span class="signup_error" id="ln_error_message"></span>
<span class="signup_error" id="email_error_message"></span>
<span class="signup_error" id="emailconf_error_message"></span>
<span class="signup_error" id="username_error_message"></span>
<span class="signup_error" id="pw_error_message"></span>
<span class="signup_error" id="pwconf_error_message"></span>
<span class="signup_error" id="tos_error_message"></span>
</div>
</div>
</form>
if you want to get your values using $_POST your inputs name attributes must be set
example add name="firstName"
<input type="text" class="signup_input_style_fn" name="firstName" id="firstName" placeholder="First Name" maxlength="20">
So now you can access it using
$firstName = $_POST['firstName'];
Change your "Id" to "name",and you will succeed.
You are missing name attribute from input , if you are not using ajax then you require name attribute
Use This
<form id="registration_form" action="http://valhq.com/register/" method="POST">
<div class="signup_form_content_names">
<div class="signup_form_input_fn">
<input type="text" class="signup_input_style_fn" id="firstName" name="firstName" placeholder="First Name" maxlength="20">
</div>
<div class="signup_form_input_ln">
<input type="text" class="signup_input_style_ln" id="lastName" name="lastName" placeholder="Last Name" maxlength="20">
</div>
</div>
<div class="signup_form_content">
<div class="signup_form_input">
<input type="text" class="signup_input_style" placeholder="E-Mail" id="email" name="email" maxlength="40">
</div>
<div class="signup_form_input">
<input type="text" class="signup_input_style" placeholder="Confirm E-Mail" id="emailconf" name="emailconf" maxlength="40">
</div>
<div class="signup_form_input">
<input type="text" class="signup_input_style" placeholder="Desired Username" id="username" name="username" maxlength="20">
</div>
<div class="signup_form_input">
<input type="password" class="signup_input_style" placeholder="Password" id="pw" name="pw" maxlength="64">
</div>
<div class="signup_form_input">
<input type="password" class="signup_input_style" placeholder="Confirm Password" id="pwconf" name="pwconf" maxlength="64">
</div>
<div class="signup_tc">
<p>
<input type="checkbox" id="terms" name="terms" value="terms_true" style="vertical-align:middle;">
I agree to the Terms and Conditions
<span class="signup_tc_required">*</span>
</p>
</div>
<input type="submit" id="submit" name="submit" class="signup_submit" value="Create Account">
<div class="signup_alreadyMember">
Already a member? Login.
</div>
<div class="signup_error">
<span class="signup_error" id="fn_error_message"></span>
<span class="signup_error" id="ln_error_message"></span>
<span class="signup_error" id="email_error_message"></span>
<span class="signup_error" id="emailconf_error_message"></span>
<span class="signup_error" id="username_error_message"></span>
<span class="signup_error" id="pw_error_message"></span>
<span class="signup_error" id="pwconf_error_message"></span>
<span class="signup_error" id="tos_error_message"></span>
</div>
</div>
</form>
Can you try echoing the variables in your php file to check if the variables are being set to the correct values from the form.
for example
echo "first name: $firstName";
echo "email: $email";
And I would also advise if you can try directly putting the actual php file in the action of your form. Just like below:
<form id="registration_form" action="<your php file here>" method="POST">

Mysql Insert form into database table PDO

I have a problem.. I tried today a lot to make this working but it seems to be impossible for me.. so I decided to ask help here. So I have a form which needs to be added on database table when submit button is pressed.
This is php code I currently use.. I removed my tries btw:
<?php
$pdo = new PDO('mysql:host=;dbname=', '', '');
$sql = "SELECT * FROM games LIMIT 10";
foreach ($pdo->query($sql) as $row) {
?>
my HTML code (form):
<form class="form-group" method="POST" action="">
<div role="tabpanel" class="tab-pane active" id="home">
<div class="form-group" style="margin-top: 15px;">
<label for="exampleInputEmail1">Game Title</label>
<input type="text" class="form-control" id="exampleInputEmail1" placeholder="" name="gtitle" />
</div>
<div class="form-group">
<label for="exampleInputPassword1">YouTube Link</label>
<input type="text" class="form-control" id="exampleInputPassword1" placeholder="" name="ytlink" />
</div>
<div class="form-group">
<label for="exampleInputPassword1">Link Source</label>
<input type="text" class="form-control" id="exampleInputPassword1" placeholder="ex: GLEAM, DLH, FAILMID, HRKGAME, INDIEGALA, OTHER, STEAM" name="slink" />
</div>
<div class="form-group">
<label for="exampleInputPassword1">Link to Free Steam Keys</label>
<input type="text" class="form-control" id="exampleInputPassword1" placeholder="KEY MUST GIVE +1 TO THE STEAM LIBRARY GAME COUNT" name="keysl" />
</div>
<label for="exampleInputPassword1">Steam App ID</label>
<div class="input-group" style="padding-bottom: 10px;">
<span class="input-group-addon" id="basic-addon3">http://store.steampowered.com/app/</span>
<input type="text" class="form-control" id="basic-url" aria-describedby="basic-addon3" placeholder="App ID" name="appid" />
</div>
<div class="form-group">
<label for="exampleInputPassword1">Categories</label>
<div class="checkbox">
<label class="radio-inline">
<input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1" /> 1
<h4><span class="label label-success">Keys Available</span></h4>
</label>
<label class="radio-inline">
<input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="option2" /> 2
<h4><span class="label label-danger">No Keys left</span></h4>
</label>
</div>
<button type="submit" class="btn btn-default" name="insert">Submit</button>
</div>
</div>
</form>
Thank those who help me.
Try this and in the radio button put value as '1' and '2' instead of 'option1' and 'option2'
if(isset($_POST['insert']))
{
$game_title=$_POST['gtitle'];
$youtube_link=$_POST['ytlink'];
$link_source=$_POST['slink'];
$link_steam_keys=$_POST['keysl'];
$app_id=$_POST['appid'];
$categories=$_POST['inlineRadioOptions'];
$query_ins="INSERT INTO tbl_game(game_title,youtube_link,link_source,link_steam_keys,app_id,categories) VALUES(:game_title,:youtube_link,:link_source,:link_steam_keys,:app_id,:categories)";
$stmt_query=$dbh->prepare($query_ins);
$games_ins=$stmt_query->execute(array(":game_title"=>$game_title,":youtube_link"=>$youtube_link,":link_source"=>$link_source,":link_steam_keys"=>$link_steam_keys,":app_id"=>$app_id,":categories"=>$categories));
if(!$games_ins)
{
$error=$stmt_query->errorInfo();
echo $error['2'];
}
}
You need to check the POST variables after submitting in your PHP code. If the form is submitted, take the post values and just run an INSERT query.
See $_POST

Submit button will not send form data to MySQL database [closed]

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 7 years ago.
Improve this question
I have a problem that might be a syntax problem but I can't seem to figure out what I am doing wrong.
I have created a form and when I click on submit, the data in the form is not sent to my mysql database.
Here is my html code
<div class="content-wrapper">
<div class="container">
<div class="row">
<div class="col-md-10">
<h1 class="page-head-line">Forms </h1>
</div>
</div>
<div class="row">
<div class="col-md-10">
<div class="panel panel-default">
<div class="panel-heading">
BASIC FORM ELEMENTS
</div>
<div class="panel-body">
<form method="post" action="insert.php" >
<div class="form-group">
<label for="name">Name</label>
<input name="name' type="text" class="form-control" id="name" placeholder="Enter your name" required/>
</div>
<div class="form-group">
<label for="project_num">OIT-GIS Project Number</label>
<input name="project_num' type="text" class="form-control" id="project_num" placeholder="OIT-GIS Project Number" />
</div>
<div class="form-group">
<label for="project_name">Project Name</label>
<input name="name' type="text" class="form-control" id="project_name" placeholder="Project Name" required/>
</div>
<div class="form-group">
<label for="easyvista">EasyVista Ticket Number</label>
<input name="easyvista' type="text" class="form-control" id="easyvista" placeholder="EasyVista Ticket Number" />
</div>
<div class="form-group">
<label for="agency">Requestor/Agency</label>
<input name="agency' type="text" class="form-control" id="agency" placeholder="Requestor or Agency" />
</div>
<div class="form-group">
<label for="description">Description of Work:</label>
<input name="description' type="text" class="form-control" id="agency" placeholder="Description" />
</div>
<div class="form-group">
<label for="input-date">Enter Today Date</label>
<input name="input-date' type="date" value="">
<span class="result"></span>
</div>
<div class="form-group">
<div class="col-md-10">
<input id="submit" name="submit" type="submit" class="btn btn-primary">
</div>
</div>
</form>
</div>
</div>
and here is my php
<?php
echo $POST;
error_reporting(E_ALL);
ini_set('display_errors', 1);
include("../includes/config.php");
if (isset($_POST['submit'])) {
echo $_POST['submit'];
$name = $_POST['name'];
$projectnum = $_POST['project_num'];
$projectname = $_POST['project_name'];
$easyvista = $_POST['easyvista'];
$agency = $_POST['agency'];
$description = $_POST['description'];
$startDate = $_POST['input-date'];
$sql="INSERT INTO statusreport(name, project_num, project_name, easyvista, agency, description)
VALUES
('$name','$projectnum', '$projectname', '$easyvista', '$agency', '$description')";
if (!mysqli_query($conn, $sql))
{
die('Error: ' . mysqli_connect_error($conn));
}
echo "Entry is recored <br/>";
echo "Name:", $name, "<br/>";
echo "test..................<br/>", $name;
/*header("location: http://10.1.7.129//gisadmin/admin/forms.php");*/
//echo "<script>setTimeout(\"location.href = 'http://10.1.7.129//gisadmin/admin/forms.php';\",700);</script>";
mysqli_query($conn, $sql);
}
else {
echo "No data";
}
?>
Any help would be greatly appreciated.
Thanks
You have a mixing of single and double quotes here, the name attributes are opening the value with double quotes and closing with single quotes, should be as follows:
<form method="post" action="insert.php" >
<div class="form-group">
<label for="name">Name</label>
<input name="name" type="text" class="form-control" id="name" placeholder="Enter your name" required/>
</div>
<div class="form-group">
<label for="project_num">OIT-GIS Project Number</label>
<input name="project_num" type="text" class="form-control" id="project_num" placeholder="OIT-GIS Project Number" />
</div>
<div class="form-group">
<label for="project_name">Project Name</label>
<input name="project_name" type="text" class="form-control" id="project_name" placeholder="Project Name" required/>
</div>
<div class="form-group">
<label for="easyvista">EasyVista Ticket Number</label>
<input name="easyvista" type="text" class="form-control" id="easyvista" placeholder="EasyVista Ticket Number" />
</div>
<div class="form-group">
<label for="agency">Requestor/Agency</label>
<input name="agency" type="text" class="form-control" id="agency" placeholder="Requestor or Agency" />
</div>
<div class="form-group">
<label for="description">Description of Work:</label>
<input name="description" type="text" class="form-control" id="agency" placeholder="Description" />
</div>
<div class="form-group">
<label for="input-date">Enter Today Date</label>
<input name="input-date" type="date" value="">
<span class="result"></span>
</div>
<div class="form-group">
<div class="col-md-10">
<input id="submit" name="submit" type="submit" class="btn btn-primary">
</div>
</div>
</form>
And then, as #Fred -ii stated in his comment, the php script is wrong:
echo $POST;
That line is wrong, there is no variable with name $POST before that code.
Are you getting success message but database is not getting updated OR Getting Total Error...???
1) Check for double quotes and single quotes..
<div class="form-group">
<label for="name">Name</label>
<input name="name" type="text" class="form-control" id="name" placeholder="Enter your name" required/>
</div>
2) Also check for path... for
include("../includes/config.php");
Is it correct or not...?
3)
<label for="project_name">Project Name</label>
<input name="name' type="text"
SHOULD BE
<label for="project_name">Project Name</label>
<input name="project_name" type="text"

Categories