php - submit form data to database table -



php - submit form data to database table -

i problem in inserting info database table. have checked table fields form fields. ok , print_r prints result info not inserted database. returns empty result set. form code

<?php include('header.php'); ?> <div class="page container"> <div class="row col-12 register-page"> <form class="form-horizontal" role="form" action="register-process.php" method="post"> <div class="form-group"> <label for="firstname" class="col-sm-2 control-label">first name</label> <div class="col-sm-10"> <input type="text" class="form-control" id="firstname" name="firstname" placeholder="enter first name"> </div> </div> <div class="form-group"> <label for="lastname" class="col-sm-2 control-label">last name</label> <div class="col-sm-10"> <input type="text" class="form-control" id="lastname" name="lastname" placeholder="enter lastly name"> </div> </div> <div class="form-group"> <label for="email" class="col-sm-2 control-label">email</label> <div class="col-sm-10"> <input type="text" class="form-control" id="email" name="email" placeholder="enter email"> </div> </div> <div class="form-group"> <label for="password" class="col-sm-2 control-label">password</label> <div class="col-sm-10"> <input type="password" class="form-control" id="password" name="password" placeholder="enter password"> </div> </div> <div class="form-group"> <label for="confirm-password" class="col-sm-2 control-label">confirm password</label> <div class="col-sm-10"> <input type="password" class="form-control" id="cpassword" name="cpassword" placeholder="confirm password"> </div> </div> <div class="form-group"> <label for="birth-year" class="col-sm-2 control-label">birth year</label> <div class="col-sm-10"> <select id="year" class="birth-year" name="birth-year"> <?php for($i = 1970; $i < date("y")+1; $i++){ echo '<option value="'.$i.'">'.$i.'</option>'; } ?> </select> </div> </div> <div class="form-group"> <label for="gender" class="col-sm-2 control-label register-gender">gender</label> <div class="col-sm-10"> <select id="registration_gender" class="select-register " required="required" name="gender"> <option selected="selected" value="">gender</option> <option value="_ue_m">male</option> <option value="_ue_mrs">female</option> </select> </div> </div> <div class="form-group form-action"> <div class="form-action"> <input type="submit" name="submit" class="btn btn-large btn-primary" value="lets started" > </div> </div> </form> </div> </div>

, register-process code

<div class="page container"> <div class="row col-12 register-page"> <?php $fname = $_post['firstname']; $lname = $_post['lastname']; $email = $_post['email']; $password = md5($_post['password']); $cpassword = md5($_post['cpassword']); $birthyear = $_post['birth-year']; $gender = $_post['gender']; if($fname && $lname && $email && $password && $cpassword){ if($password == $cpassword){ include("config.php"); $insert = 'insert users(firstname,lastname,email,password,birth-year,gender) values("'.$fname.'","'.$lname.'","'.$email.'","'.$password.'","'.$birthyear.'","'.$gender.'")'; mysql_query($insert); echo "registered successfully"; } else{ header("location: register.php"); echo "your password not match."; } } else{ echo "complete form please."; header("location: register.php"); } ?> </div> </div>

the line

if($fname && $lname && $email && $password && $cpassword){

is checking if these values true, aren't. php code around result in sql injections you're not validating values entered in form. @ escaping sql , removing html entities.

use function isset() on $_post variables, way can validate form filled in correctly. 1 time you're happy form filled in correctly, sql escape , removal of html entities local variables , utilize these insert sql.

php mysql forms

Comments

Popular posts from this blog

javascript - I need to update the text of a paragraph by inline edit -

javascript - THREE.js reposition vertices for RingGeometry -

assembly - What is the addressing mode for ld, add, and rjmp instructions? -