PHP not being able to pick data from HTML form -
my php page unable pick values html form. it's sending blank strings database. here html , php code. please find error. new php, unable solve 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"><a href="">rerun pen</a></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> 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 security $loginid = mysqli_real_escape_string($conn,$loginid); $password = mysqli_real_escape_string($conn,$password); // attempt insert query execution $sql = "insert users (loginid, password ) values ('$loginid', '$password')"; if(mysqli_query($conn, $sql)){ echo "records added successfully."; } else{ echo "error: not able execute $sql. " . mysqli_error($conn); } // close connection mysqli_close($conn); ?>
the input
s inside form
tag not have name
s. try login:
<input type="text" id="loginid" required="required" name="loginid"/>
and password:
<input type="password" id="password" required="required" name="password"/>
it nice if protect users against xss attacks , use encryption when store password. also, should structure code , make sure html valid.
Comments
Post a Comment