When trying to submit my form I get the following error message:
Notice: Undefined index: application_results in C:\xampp\htdocs\cas\insert.php
This is my form php code:
<!DOCTYPE html>
<html lang="en">
<head>
<title>CAS Application</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap /3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body style="background-color:#FF9933">
<div class="container" >
<form action="insert.php" method="post" class="form-horizontal" role="form" enctype="multipart/form-data">
<h2 style="text-align:center">Application Form</h2>
</div>
<div class="form-group">
<label for="surname" class="col-sm-3 control-label">Surname</label>
<div class="col-sm-9">
<input type="text" name="surname" id="surname" placeholder="Surname" class="form-control" autofocus>
</div>
</div>
<div class="form-group">
<label for="firstName" class="col-sm-3 control-label">First Name</label>
<div class="col-sm-9">
<input type="text" name="first_name" id="first_name" placeholder="First Name" class="form-control" autofocus>
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-3 control-label">Email</label>
<div class="col-sm-9">
<input type="text" id="email" placeholder="Email" class="form-control" name="email">
</div>
</div>
<div class="col-sm-offset-3">
<h2>Application Results</h2>
<label for="application_results">Please upload your application results here:</label>
<input type="file" name="application_results" ><br>
</div>
<div class="form-group">
<div class="col-sm-6 col-sm-offset-3">
<button type="submit" class="btn btn-primary btn-block" name="submit">Submit</button>
</div>
</div>
</form>
</div>
</body>
</html>
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("cas",$con);
if(isset($_POST['submit'])) {
$file = rand(1000,100000). "-".$_FILES['application_results']['name'];
$file_loc = $_FILES['application_results']['tmp_name'];
$folder="application_results";
if(move_uploaded_file($file)) {
$sql="INSERT INTO applications (application_results) VALUES ($application_results)";
mysql_query($sql);
}
}
?>
This is my code for insertion:
<?php
$link = mysqli_connect("localhost", "root", "", "cas");
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$surname = mysqli_real_escape_string($link, $_REQUEST['surname']);
$first_name = mysqli_real_escape_string($link, $_REQUEST['first_name']);
$email = mysqli_real_escape_string($link, $_REQUEST['email']);
$application_results = mysqli_real_escape_string($link, $_REQUEST['application_results']);
// attempt insert query execution
$sql = "INSERT INTO applications ( surname, first_name,
email, application_results )
VALUES ('$surname', '$first_name', '$email', $application_results )";
if(mysqli_query($link, $sql)){
echo "Your application has been submitted.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// close connection
mysqli_close($link);
?>
What I am actually trying to accomplish is after insertion when calling an applications.php page details of the applicant must be displayed together with the uploaded file for reading. I suspect most of the uploaded files will be in pdf.
Related
This question already has answers here:
How can I prevent SQL injection in PHP?
(27 answers)
Closed 1 year ago.
I write my code but I still have this error (Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in database). I have table users which have username and user_id. And I have table country which has country_id as primary key(Varchar) and has country_name, the table education has user_id as foreign key and also country_id as foreign key.
<?php
include_once "connection.php";
/** #var PDO $conn */
if(isset($_REQUEST['btn_register'])) {
$user_id = $_REQUEST['user_id'];
$edname = $_REQUEST['edname'];
$street = $_REQUEST['street_address'];
$postcode = $_REQUEST['postal_address'];
$city = $_REQUEST['city'];
$pofiletext = $_REQUEST['profiletext'];
$positionn = $_REQUEST['position_com'];
$video = $_REQUEST['video'];
$logo = $_REQUEST['logo'];
$contactperson = $_REQUEST['contactpersoon'];
$emailcon = $_REQUEST['email_contactpersoon'];
$website = $_REQUEST['website'];
$country="SELECT country_id FROM country WHERE country_id= 'AD'";
try {
$select_stmt = $conn->prepare("INSERT INTO education (user_id ,edname, street_address, postal_address, city, country_id , profiletext ,position_com, video, logo,contactpersoon, email_contactpersoon , website )
VALUES (':user_id',':edname',':street_address', ':postal_address',':city',':countryid', ':about',':position_com', ':video', ':logo', ':contactperson',':email_contactpersoon', ':website')");
$select_stmt->bindParam(':user_id', $user_id);
$select_stmt->bindParam(':edname', $_POST['edname']);
$select_stmt->bindParam(':street_address', $_POST['street_address']);
$select_stmt->bindParam(':postal_address', $_POST['postal_address']);
$select_stmt->bindParam(' :city', $_POST['city']);
$select_stmt->bindParam(':country_id',$country );
$select_stmt->bindParam(':profiletext', $_POST['profiletext']);
$select_stmt->bindParam(':position_com', $_POST['position_com']);
$select_stmt->bindParam(':video', $_POST['video']);
$select_stmt->bindParam(':logo', $_POST['logo']);
$select_stmt->bindParam(':contactpersoon', $_POST['contactpersoon']);
$select_stmt->bindParam(':email_contactpersoon', $_POST['email_contactpersoon']);
$select_stmt->bindParam(':website', $_POST['website']);
$select_stmt->execute();
$resiterMsg = "Register successfully";
header("location: index.php");
} catch (PDOExeption $e) {
echo $e->getMessage();
}
}
?>
And my html code:
<?php
include_once "html.html";
include "connection.php";
/** #var PDO $conn */
$sql = $conn->prepare('SELECT * From intern where user_id = :user_id');
$sql->bindParam(":user_id", $_GET['user_id']);
$sql->execute();
$row = $sql->fetch();
?>
<!DOCTYPE html>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<html>
<head>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link href="educationRegister.php">
<!------ Include the above in your HEAD tag ---------->
</head>
<body id="educationForm">
<div class="container">
<div class="login-form">
<div class="main-div">
<div class="panel">
<h2>Register</h2>
</div>
<form method="post" class="cd-form floating-labels" action="educationRegister.php">
<div class="form-group">
<input type="hidden" name="type" value="education">
<input type="hidden" name="user_id" value="<?php echo $_GET['user_id'] ?>" >
<input type="text" name="edname" class="form-control" placeholder="Name">
</div>
<div class="form-group">
<input type="text" name="street_address" class="form-control" placeholder="Street">
</div>
<div class="form-group">
<input type="text" name="postal_address" class="form-control" placeholder="Postal Code">
</div>
<div class="form-group">
<select name="city">
<option>--Select city--</option>
<?php
$country_stmt=$conn->prepare('SELECT * FROM country');
$country_stmt->execute();
while ($row = $country_stmt->fetch(PDO::FETCH_ASSOC)) { ?>
<option value="<?php echo $row['country_id']; ?>"><?php echo $row['countryname']; ?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<input type="text" name="profiletext" class="form-control" placeholder="About you">
</div>
<div class="form-group">
<input type="text" name="position_com" class="form-control" placeholder="position">
</div>
<div class="form-group">
<input type="text" name="video" class="form-control" placeholder="video">
</div>
<div class="form-group">
<input type="text" name="logo" class="form-control" placeholder="logo">
</div>
<div class="form-group">
<input type="text" name="contactpersoon" class="form-control" placeholder="contactperson">
</div>
<div class="form-group">
<input type="email" name="email_contactpersoon" class="form-control" placeholder="emailContactperson">
</div>
<div class="form-group">
<input type="text" name="website" class="form-control" placeholder="website">
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9 m-t-15">
<button type="submit" name="btn_register" class="btn btn-primary" value="Regsiter" >
<button type="button" class="btn btn-primary"> Cancel </button>
</div>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
$select_stmt->bindParam(' :city', $_POST['city']);
You have an empty space between ' and :. Try with it like this:
$select_stmt->bindParam(':city', $_POST['city']);
I want to insert the values in two different tables based on the if and else condition. But i am getting error of else statement when used second time. All the page goes blank if i use else{?> before html elements. Please help me out.
I have used if and else in different ways and i also used condition with these statements
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<title>GlobalWorkOnline Registration</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<?php
require('db.php');
// If form submitted, insert values into the database.
if($_GET['viewregistrationid']!="") {
if (isset($_REQUEST['submit'])){
$username = stripslashes($_REQUEST['username']); // removes backslashes
$username = mysqli_real_escape_string($con,$username); //escapes special characters in a string
$name = stripslashes($_REQUEST['name']);
$name = mysqli_real_escape_string($con,$name);
$password = stripslashes($_REQUEST['password']);
$password = mysqli_real_escape_string($con,$password);
$trn_date = date("Y-m-d H:i:s");
$query = "INSERT into `freelancer_details` (username, password, fullname, trn_date) VALUES ('$username', '".md5($password)."', '$name', '$trn_date')";
$result = mysqli_query($con,$query);
if($result){
echo "<div class='form text-center'><h3>You are registered successfully.</h3><br/>Click here to <a href='login.php'>Login</a></div>";
}
}
}
elseif {
if (isset($_REQUEST['submit'])){
# code...
$username = stripslashes($_REQUEST['username']); // removes backslashes
$username = mysqli_real_escape_string($con,$username); //escapes special characters in a string
$name = stripslashes($_REQUEST['name']);
$name = mysqli_real_escape_string($con,$name);
$password = stripslashes($_REQUEST['password']);
$password = mysqli_real_escape_string($con,$password);
$trn_date = date("Y-m-d H:i:s");
$query = "INSERT into `employer_details` (username, password, fullname, trn_date) VALUES ('$username', '".md5($password)."', '$name', '$trn_date')";
$result = mysqli_query($con,$query);
if($result){
echo "<div class='form text-center'><h3>You are registered successfully.</h3><br/>Click here to <a href='login.php'>Login</a></div>";
}
}
}
else {?>
<div class="container">
<h1 class="text-center head">GlobalWorkOnline Registration Form</h1>
<div class="col-sm-offset-3 col-sm-6 rform">
<form class="form-horizontal" name="registration" action="" method="post">
<div class="form-group content">
<label class="control-label col-sm-3" for="name">Full Name :</label>
<div class="col-sm-offset-0 col-sm-9">
<input type="text" class="form-control" name="name" placeholder="Full Name" required>
</div>
</div>
<div class="form-group content">
<label class="control-label col-sm-3" for="uname">Username :</label>
<div class="col-sm-offset-0 col-sm-9">
<input type="text" class="form-control" name="username" placeholder="Enter Username" required>
</div>
</div>
<div class="form-group content">
<label class="control-label col-sm-3" for="pwd">Password :</label>
<div class="col-sm-offset-0 col-sm-9">
<input type="password" class="form-control" name="password" placeholder="Enter Password" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-10">
<input class="buttonregister" type="submit" class="register" name="submit" value="Register" />
</div>
</div>
</form>
</div>
</div>
<?php } ?>
</body>
</html>
The values should be inserted as per conditions. But the page goes blank when using condition with else and if.
I am developing a form in html and php and there are multiple section in a page and I want a single submit button for every section. But I am unable to do it. With multiple submit buttons it works. Can anybody help me out with this problem.I need to create a form with single submit button. Here is the example code..
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add Records Form</title>
</head>
<body>
<table style="width:100%">
<tr>
<th rowspan="2">
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<form action="insert1.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<label class="control-label">NCBI Accession number</label>
<input type="text" name="Gene_NCBI_Accession_number" placeholder="NCBI Accession number" class="form-control">
</div>
<div class="form-group">
<label class="control-label">locus tag</label>
<input type="text" name="Gene_name_locus_tag" placeholder="locus tag" class="form-control">
</div>
</th>
<td>
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<form action="insert1.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<label class="control-label"><b>Antibiotic</label>
<input type="text" name="Antibiotic_name" placeholder="Antibiotic name" class="form-control">
</div>
</td>
<td>
<div class="form-group">
<label class="control-label"><b>Name</label>
<input type="text" name="Name" placeholder="Name" class="form-control" required>
</div>
</td>
</tr>
<tr>
<td rowspan="2">
<h4> Please fill in information for other related data or give your comments if any</h4>
<br>
<textarea rows="7" cols="100" name="comment" form="usrform">
Enter text here...</textarea>
</td>
<td>
</div>
<div class="form-group">
<label class="control-label"><b>Protein function</label>
<input type="text" name="Protein_function" placeholder="Protein_function" class="form-control">
</div>
<div class="form-group">
<label class="control-label">Biological process</label>
<input type="text" name="Biological_process" placeholder="Biological process" class="form-control">
</div>
</td>
</tr><br>
<br>
<br>
<br>
<br>
<br>
</form></table>
<input type="submit" value="Add Records">
<?php include 'footer.php'; ?>
</body>
</html>
<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("abc", "abc", "abc", "abc");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Escape user inputs for security
$Gene_NCBI_Accession_number = mysqli_real_escape_string($link, $_REQUEST['Gene_NCBI_Accession_number']);
$Gene_name_locus_tag = mysqli_real_escape_string($link, $_REQUEST['Gene_name_locus_tag']);
$Antibiotic_name = mysqli_real_escape_string($link, $_REQUEST['Antibiotic_name']);
$Name = mysqli_real_escape_string($link, $_REQUEST['Name']);
$Protein_function = mysqli_real_escape_string($link, $_REQUEST['Protein_function']);
$Biological_process= mysqli_real_escape_string($link, $_REQUEST['Biological_process']);
// attempt insert query execution
$sql = "INSERT INTO contact_form_info (Gene_NCBI_Accession_number, Gene_name_locus_tag, Antibiotic_name, Name, Protein_function, Biological_process) VALUES ('$Gene_NCBI_Accession_number', '$Gene_name_locus_tag', '$Antibiotic_name', '$Name','$Protein_function', '$Biological_process' )";
if(mysqli_query($link, $sql)){
#echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// close connection
mysqli_close($link);
?>
Your submit button is outside of form that's why its not working. Refer below code to resolve your issue.
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add Records Form</title>
</head>
<body>
<table style="width:100%">
<tr>
<th rowspan="2">
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<form action="insert1.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<label class="control-label">NCBI Accession number</label>
<input type="text" name="Gene_NCBI_Accession_number" placeholder="NCBI Accession number" class="form-control">
</div>
<div class="form-group">
<label class="control-label">locus tag</label>
<input type="text" name="Gene_name_locus_tag" placeholder="locus tag" class="form-control">
</div>
</th>
<td>
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<form action="insert1.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<label class="control-label"><b>Antibiotic</label>
<input type="text" name="Antibiotic_name" placeholder="Antibiotic name" class="form-control">
</div>
</td>
<td>
<div class="form-group">
<label class="control-label"><b>Name</label>
<input type="text" name="Name" placeholder="Name" class="form-control" required>
</div>
</td>
</tr>
<tr>
<td rowspan="2">
<h4> Please fill in information for other related data or give your comments if any</h4>
<br>
<textarea rows="7" cols="100" name="comment" form="usrform">
Enter text here...</textarea>
</td>
<td>
</div>
<div class="form-group">
<label class="control-label"><b>Protein function</label>
<input type="text" name="Protein_function" placeholder="Protein_function" class="form-control">
</div>
<div class="form-group">
<label class="control-label">Biological process</label>
<input type="text" name="Biological_process" placeholder="Biological process" class="form-control">
</div>
</td>
</tr><br>
<br>
<br>
<br>
<br>
<br><input type="submit" value="Add Records">
</form></table>
<?php include 'footer.php'; ?>
</body>
</html>
<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("abc", "abc", "abc", "abc");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Escape user inputs for security
$Gene_NCBI_Accession_number = mysqli_real_escape_string($link, $_REQUEST['Gene_NCBI_Accession_number']);
$Gene_name_locus_tag = mysqli_real_escape_string($link, $_REQUEST['Gene_name_locus_tag']);
$Antibiotic_name = mysqli_real_escape_string($link, $_REQUEST['Antibiotic_name']);
$Name = mysqli_real_escape_string($link, $_REQUEST['Name']);
$Protein_function = mysqli_real_escape_string($link, $_REQUEST['Protein_function']);
$Biological_process= mysqli_real_escape_string($link, $_REQUEST['Biological_process']);
// attempt insert query execution
$sql = "INSERT INTO contact_form_info (Gene_NCBI_Accession_number, Gene_name_locus_tag, Antibiotic_name, Name, Protein_function, Biological_process) VALUES ('$Gene_NCBI_Accession_number', '$Gene_name_locus_tag', '$Antibiotic_name', '$Name','$Protein_function', '$Biological_process' )";
if(mysqli_query($link, $sql)){
#echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// close connection
mysqli_close($link);
?>
I have been working on this project for hours and need fresh eyes as to why the information from the forum is not being submitted into the database.
I have checked that the connection to the database was working. Whenever I try to submit an entry to the database, it shows that nothing goes wrong and goes to https://example.com/beta/index.php?post=success as it is supposed to but nothing except the auto_incremented id number shows up into the database.
My form page:
if(!session_id()){
session_start();
}
require('loginregister-master/includes/config.php');
if ($_SESSION['username'] !== admin ) {
header("Location: https://www.example.com/beta");
}
//if not logged in redirect to login page
if(!$user->is_logged_in()){ header('Location: loginregister-master/login.php'); }
include('sec/HTTPS.php');
?>
<!DOCTYPE html>
<html>
<head>
<title>Post Blog</title>
<!-- Bootstrap Core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
<script src="vendor/jquery/jquery.min.js"></script>
</head>
<body>
<form action="likesdislike/post.php" method="POST">
<div class="form-group">
<label>Title</label>
<input type="title" class="form-control" name="title' placeholder="Title">
</div>
<div class="form-group">
<label>Content</label>
<input type="content" class="form-control" name="content' placeholder="Content">
</div>
<div class="form-group">
<label>Date</label>
<input type="text" class="form-control" name="etad' placeholder="Date">
</div>
<div class="form-group">
<label>Author</label>
<input type="text" class="form-control" name="author' placeholder="author">
</div>
<div class="form-group">
<label>URL</label>
<input type="text" class="form-control" name="URL' placeholder="URL">
</div>
<button type="submit" name="submit">Submit</button>
</form>
</body>
</html>
The bit that 'should' handle the submission the database:
<?php
include('connect.php');
$title = mysqli_real_escape_string($link, $_POST['title']);
$content = mysqli_real_escape_string($link, $_POST['content']);
$etad = mysqli_real_escape_string($link, $_POST['etad']);
$author = mysqli_real_escape_string($link, $_POST['author']);
$URL = mysqli_real_escape_string($link, $_POST['URL']);
$sql = "INSERT INTO posts (title, content, etad, author, URL) VALUES ('" . $title . "', '" . $content . "', '" . $etad . "', '" . $author . "', '" . $URL . "')";
mysqli_query($link, $sql);
header("Location: https://www.example.com/beta/index.php?post=success");
?>
And of course, the bit that handles the connection to the database:
<?php
$link = mysqli_connect("localhost", "username", "password", "database_name");
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
?>
You have misplaced " in name of html tags. Just do it with "".
<form action="likesdislike/post.php" method="POST">
<div class="form-group">
<label>Title</label>
<input type="title" class="form-control" name="title" placeholder="Title">
</div>
<div class="form-group">
<label>Content</label>
<input type="content" class="form-control" name="content" placeholder="Content">
</div>
<div class="form-group">
<label>Date</label>
<input type="text" class="form-control" name="etad" placeholder="Date">
</div>
<div class="form-group">
<label>Author</label>
<input type="text" class="form-control" name="author" placeholder="author">
</div>
<div class="form-group">
<label>URL</label>
<input type="text" class="form-control" name="URL" placeholder="URL">
</div>
<button type="submit" name="submit">Submit</button>
</form>
My PHP page is unable to pick values from HTML form. It's sending blank strings to database. Here is my HTML and PHP code. Please find error. I am new to PHP, unable to solve the problem.
my html page:
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>LOGIN</title>
<link rel="stylesheet" href="css/reset.css">
<link rel='stylesheet prefetch' href='http://fonts.googleapis.com/css?family=Roboto:400,100,300,500,700,900|RobotoDraft:400,100,300,500,700,900'>
<link rel='stylesheet prefetch' href='http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css'>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<!-- Mixins-->
<!-- Pen Title-->
<div class="pen-title">
<h1>SYNCHPHONY</h1>
</div>
<div class="rerun">Rerun Pen</div>
<div class="container">
<div class="card"></div>
<div class="card">
<h1 class="title">Login</h1>
<form name="login" action="login.php" method="POST">
<div class="input-container">
<input type="text" id="loginid" required="required"/>
<label for="loginid">Login ID</label>
<div class="bar"></div>
</div>
<div class="input-container">
<input type="password" id="password" required="required"/>
<label for="password">Password</label>
<div class="bar"></div>
</div>
<div class="button-container">
<button><span>Go</span></button>
</div>
</form>
</div>
<div class="card alt">
<div class="toggle"></div>
<h1 class="title">Register
<div class="close"></div>
</h1>
<form name="register" action="register.php" method="POST">
<div class="input-container">
<input type="text" id="loginid" required="loginid"/>
<label for="loginid">Login ID</label>
<div class="bar"></div>
</div>
<div class="input-container">
<input type="password" id="password" required="required"/>
<label for="password">Password</label>
<div class="bar"></div>
</div>
<div class="button-container">
<button value'submitb'><span>Next</span></button>
</div>
</form>
</div>
</div>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src="js/index.js"></script>
</body>
</html>
my php page:
**strong text** <?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "syncphony";
$loginid="";
$password="";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if(isset($_POST['loginid'])){ $loginid = $_POST['loginid']; }
if(isset($_POST['password'])){ $password = $_POST['password']; }
// Escape user inputs for security
$loginid = mysqli_real_escape_string($conn,$loginid);
$password = mysqli_real_escape_string($conn,$password);
// attempt insert query execution
$sql = "INSERT INTO users (loginid, password ) VALUES ('$loginid', '$password')";
if(mysqli_query($conn, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn);
}
// close connection
mysqli_close($conn);
?>
The inputs inside your form tag do not have names. Try this for login:
<input type="text" id="loginid" required="required" name="loginid"/>
and this for password:
<input type="password" id="password" required="required" name="password"/>
It would be nice if you would protect your users against XSS attacks and to use encryption when you store a password. Also, you should structure your code and make sure your HTML is valid.