php - Form data is submitting, but isn't going into mySQL -
my db connection correct, able select , echo out rows of table. however, form data isn't updating database. i'm trying submit form on same page, left action blank. here php:
<?php if (isset($_post['submit'])) { $con=mysqli_connect("localhost","hey","password!","dbname"); $sql="insert studentlist (studentnum, lastname, firstname, address, city, state, zip, balance, firsttermattended) values('$_post[inputid]','$_post[inputlast]','$_post[inputfirst]','$_post[inputaddress]','$_post[inputcity]','$_post[inputstate]','$_post[inputzip]','$_post[inputbalance]','$_post[inputterm]')"; echo "it worked"; } ?>
and here form:
<form class="form-horizontal" role="form" method="post" action=""> <div class="form-group"> <div class="col-sm-offset-1 col-sm-10"> <input type="text" class="form-control" id="inputid" placeholder="student id number"> </div> </div> <div class="form-group"> <div class="col-sm-offset-1 col-sm-10"> <input type="text" class="form-control" id="inputlast" placeholder="last name"> </div> </div> <div class="form-group"> <div class="col-sm-offset-1 col-sm-10"> <input type="text" class="form-control" id="inputfirst" placeholder="first name"> </div> </div> <div class="form-group"> <div class="col-sm-offset-1 col-sm-10"> <input type="text" class="form-control" id="inputaddress" placeholder="street address"> </div> </div> <div class="form-group"> <div class="col-sm-offset-1 col-sm-10"> <input type="text" class="form-control" id="inputcity" placeholder="city"> </div> </div> <div class="form-group"> <div class="col-sm-offset-1 col-sm-10"> <input type="text" class="form-control" id="inputstate" placeholder="state"> </div> </div> <div class="form-group"> <div class="col-sm-offset-1 col-sm-10"> <input type="text" class="form-control" id="inputzip" placeholder="zip"> </div> </div> <div class="form-group"> <div class="col-sm-offset-1 col-sm-10"> <input type="text" class="form-control" id="inputbalance" placeholder="current balance"> </div> </div> <div class="form-group"> <div class="col-sm-offset-1 col-sm-10"> <input type="text" class="form-control" id="inputterm" placeholder="first term attended"> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">close</button> <input type="submit" value="save student information" id="submit" name="submit" class="btn btn-primary"> </div> </form>
i have in header, screwing things up?
<?php // create connection $con=mysqli_connect("localhost","hey","password!","dbname"); // check connection if (mysqli_connect_errno()) { echo "failed connect mysql: " . mysqli_connect_error(); } ?>
your code missing mysqli_query , need assign name attribute input field. see sample example here http://www.w3schools.com/php/php_mysql_insert.asp
Comments
Post a Comment