php - Why can't I insert data to MySQL? -
my idea put data in textfield , pass database mysql , when text field filled , button clicked nothing happened. when checked database there nothing there. why that? please me?
<?php //connection string database mysql require 'db.php'; //check if it's set. if(isset($_post['dateloangrantedmonth'], $_post['dateloangrantedday'], $_post['dateloangrantedyear'], $_post['maturitymonth'], $_post['maturityday'], $_post['maturityyear'], $_post['expirymonth'], $_post['expiryday'], $_post['expiryyear'], $_post['mrs'], $_post['name'], $_post['resident'], $_post['loaninwords'], $_post['pesos'], $_post['interest'], $_post['daysmonths'], $_post['pesosinwords'], $_post['pesos2'], $_post['penaltyinterest'], $_post['itemtype'], $_post['grams'], $_post['idpresented'], $_post['contactnumber'], $_post['birthdaymonth'], $_post['birthdayday'], $_post['birthdayyear'], $_post['sex'], $_post['citizenship'], $_post['complexion'], $_post['principal'], $_post['interestabsoluteamount'], $_post['servicechargeamount'], $_post['netproceeds'], $_post['peranum'], $_post['permonth'], $_post['others'], $_post['descriptionpawn'])) { //loan_assignment $dateloangrantedmonth = mysqli_real_escape_string($connection, $_post['dateloangrantedmonth']); $dateloangrantedday = mysqli_real_escape_string($connection, $_post['dateloangrantedday']); $dateloangrantedyear = mysqli_real_escape_string($connection, $_post['dateloangrantedyear']); //collateral $itemtype = mysqli_real_escape_string($connection, $_post['itemtype']); $descriptionpawn = mysqli_real_escape_string($connection, $_post['descriptionpawn']); $maturitymonth = mysqli_real_escape_string($connection, $_post['maturitymonth']); $maturityday = mysqli_real_escape_string($connection, $_post['maturityday']); $maturityyear = mysqli_real_escape_string($connection, $_post['maturityyear']); $expirymonth = mysqli_real_escape_string($connection, $_post['expirymonth']); $expiryday = mysqli_real_escape_string($connection, $_post['expiryday']); $expiryyear = mysqli_real_escape_string($connection, $_post['expiryyear']); $mrs = mysqli_real_escape_string($connection, $_post['mrs']); $resident = mysqli_real_escape_string($connection, $_post['resident']); $loaninwords = mysqli_real_escape_string($connection, $_post['loaninwords']); $pesos = mysqli_real_escape_string($connection, $_post['pesos']); $interest = mysqli_real_escape_string($connection, $_post['interest']); $daysmonths = mysqli_real_escape_string($connection, $_post['daysmonths']); $pesosinwords = mysqli_real_escape_string($connection, $_post['pesosinwords']); $pesos2 = mysqli_real_escape_string($connection, $_post['pesos2']); $penaltyinterest = mysqli_real_escape_string($connection, $_post['penaltyinterest']); $grams = mysqli_real_escape_string($connection, $_post['grams']); //pawner $name = mysqli_real_escape_string($connection, $_post['name']); $idpresented = mysqli_real_escape_string($connection, $_post['idpresented']); $contactnumber = mysqli_real_escape_string($connection, $_post['contactnumber']); $birthdaymonth = mysqli_real_escape_string($connection, $_post['birthdaymonth']); $birthdayday = mysqli_real_escape_string($connection, $_post['birthdayday']); $birthdayyear = mysqli_real_escape_string($connection, $_post['birthdayyear']); $sex = mysqli_real_escape_string($connection, $_post['sex']); $citizenship = mysqli_real_escape_string($connection, $_post['citizenship']); $complexion = mysqli_real_escape_string($connection, $_post['complexion']); //loan $principal = mysqli_real_escape_string($connection, $_post['principal']); $interestabsoluteamount = mysqli_real_escape_string($connection,$_post['interestabsoluteamount']); $servicechargeamount = mysqli_real_escape_string($connection, $_post['servicechargeamount']); $netproceeds = mysqli_real_escape_string($connection, $_post['netproceeds']); $peranum = mysqli_real_escape_string($connection, $_post['peranum']); $permonth = mysqli_real_escape_string($connection, $_post['permonth']); $others = mysqli_real_escape_string($connection, $_post['others']); // insert query loan. $sql = "insert loan (principal_loan, interest_absolute_amount, service_charge, net_proceeds)". "values ($principal, $interestabsoluteamount, $servicechargeamount, $netproceeds);"; // insert query pawner. $sql .= "insert pawner (name, birthdate, contact_number, resident, valid_id)". "values ('".$name."', str_to_date('".$birthdayyear."-".$birthdaymonth."-".$birthdayday."', '%y-%m-%d'), '".$contactnumber."', '".$resident."', '".$idpresented."');"; // insert query collateral. $sql .= "insert collateral (type, description, maturity_date, expiry_date)". "values ('".$itemtype."', '".$descriptionpawn."', str_to_date('".$maturityyear."-".$maturitymonth."-".$maturityday."', '%y-%m-%d'), str_to_date('".$expiryyear."-".$expirymonth."-".$expiryday."', '%y-%m-%d'));"; // insert query loan_assignment. $sql .= "insert loan_assignment (date_loan_granted, renewal_date)". "values (str_to_date('".$dateloangrantedyear."-".$dateloangrantedmonth."-".$dateloangrantedday."', '%y-%m-%d'), curdate())"; mysqli_multi_query($connection, $sql); mysqli_close($connection); //require 'pdf'; } ?>
this html code pass data , when clicked save , print should pass data database.
<html> <head> <meta charset="utf-8"> <title>home</title> <!--<link rel="stylesheet" href="css/bootstrap.css"> <link rel="stylesheet" href="css/custom.css">--> <link href="css/simple-sidebar.css" rel="stylesheet"> </head> <body> <nav class="navbar navbar-custom navbar-fixed-top" role="navigation"> <div class="container"> <div class="navbar-header"> <p class="systemname">pawn broking management system <a href="#menu-toggle" class="btn btn-default" id="menu-toggle">toggle menu</a> </p> </div> <div class="logout" align="right"><a href="#" class="textlogout">logout</a> </div> </div> </nav> <br><br><br> <div id="wrapper"> <div id="sidebar-wrapper"> <ul class="sidebar-nav"> <br><br><br><br> <li> <a href="pricereference.php">price reference</a> </li> <li> <a href="scan.php">scan barcode</a> </li> <li> <a data-toggle="collapse" data-target="#demo"> manage peónline account <i class="fa fa-fw fa-caret-down"></i></a> <ul id="demo" class="collapse"> <li> <a href="upload.php">upload photos</a> </li> <li> <a href="viewpost.php">view posts</a> </li> <li> <a href="viewreservation.php">view reservation</a> </li> </ul> </li> <li> <a href="alltransactions.php">all transactions</a> </li> </ul> </div> <div id="page-content-wrapper"> <div class="container-fluid"> <div class="row"> <div class="col-lg-12"> <form method="post" class="formfont"> <div class="container"> <div class="row"> <div class="col-md-6"></div> <div class="col-md-5"> <br><br> maturity date: <select name="maturitymonth" id = "month" onfocus = "monthfunction();"> <option value = "">month</option> </select> <select name="maturityday" id = "day" onfocus = "dayfunction();"> <option value = "">day</option> </select> <select name="maturityyear" id = "year" onfocus = "yearfunction();" > <option value = "">year</option> </select> <br> expiry date: <select name="expirymonth"id = "emonth" onfocus = "emonthfunction();"> <option value = "">month</option> </select> <select name="expiryday" id = "eday" onfocus = "edayfunction();"> <option value = "">day</option> </select> <select name="expiryyear" id = "eyear" onfocus = "eyearfunction();" > <option value = "">year</option> </select> </div> <div class="col-lg-10"> date loan granted: <select name="dateloangrantedmonth" id = "dlgmonth" onfocus = "dlgmonthfunction();"> <option value = "">month</option> </select> <select name="dateloangrantedday" id = "dlgday" onfocus = "dlgdayfunction();"> <option value = "">day</option> </select> <select name="dateloangrantedyear" id = "dlgyear" onfocus = "dlgyearfunction();" > <option value = "">year</option> </select> <div class="form-group"> <br> <label class="radio-inline"> <input type="radio" name="mrs" value="mr.">mr. </label> <label class="radio-inline"> <input type="radio" name="mrs" value="mrs.">mrs. </label> <label class="radio-inline"> <input type="radio" name="mrs" value="ms.">ms. </label> <input type="text" name="name" class="input-custom"> resident of <input type="text" name="resident" class="input-custom"> <br><br> loan of <input type="text" name="loaninwords" class="input-custom"> pesos ₱ <input type="text" name="pesos" class="input-custom-peso"> interest of <select name="interest" name="interest" id="interestof" onfocus="interestoffunction();"> <option value="">%</option> </select><br><br> <select name="count" name="daysmonths" id="for" onfocus="forfunction();"> <option value = "">choose</option> </select> <input type="radio" name="daysm" value="days"> day/s <input type="radio" name="daysm" value="months"> month/s has pledge pawnee security loan, article(s) described below appraised<br><br> @ pesos <input type="text" name="pesosinwords" class="input-custom"> ₱ <input type="text" name="pesos2"class="input-custom-peso"> subject terms , conditions <br><br>stated on reverse side hereof. <br><br> penalty interest, if any: <select name="penaltyinterest" id="penaltyinterest" onfocus="penaltyinterestfunction();"> <option value="0">0%</option> </select><br><br><br> <div class="col-md-6"> description of pawn <br><br> <textarea class="form-control-custom2" name="descriptionpawn" rows="3" placeholder="ring, necklace, etc."></textarea> <br> item type <select name="itemtype" id="itemtype" onfocus="itemtypefunction();"> <option value="">choose</option> </select><br><br> grams <input type="text" class="customerhw"><br> id presented <select name="idpresented" id="idpresented" onfocus="idpresentedfunction();"> <option value="">choose</option> </select><br><br><br> contact number: <br> <input type="text" name="contactnumber" class="contactnumber"> <br><br> miscellaneous <br><br> birthday <select name="birthdaymonth" id = "bmonth" onfocus = "bmonthfunction();"> <option value = "">month</option> </select> <select name="birthdayday" id = "bday" onfocus = "bdayfunction();"> <option value = "">day</option> </select> <select name="birthdayyear" id = "byear" onfocus = "byearfunction();" > <option value = "">year</option> </select> <br><br> sex <label class="radio-inline"> <input type="radio" name="sex" value="male">male </label> <label class="radio-inline"> <input type="radio" name="sex" value="females">female </label> <br><br> citizenship <br> <input type="text" name="citizenship" class="customerhw"><br> complexion <br> <input type="text" name="complexion" class="customerhw"><br> <hr> </div> <br><br> <div class="col-md-6"> <a class="principaltext">principal </a> ₱ <input type="text" name="principal" class="input-custom"> <br><br> <a class="principaltext">interest in absolute amount</a> <select name="interestabsoluteamount" id="interestabsoluteamount" onfocus="interestabsoluteamountfunction();"> <option value="0">0%</option> </select><br><br> <a class="sca">service charge in amount</a> <input type="text" name="servicechargeamount" class="input-custom"> <br><br> <a class="np">net proceeds</a> ₱ <input type="text" name="netproceeds" class="input-custom"> <br><br><br> effective interest rate in percent <br> please check: <br><br> <input type="checkbox" name="peranum" value="peranum"> per anum <input type="checkbox" name="permonth" value="permonth"> per month <br> <input type="checkbox" name="others" value="others"> others <input type="text" class="input-custom"> <br><br><br><br> <hr><br><br><br><br><br><br><br><br><br><br><br><br> appraiser name <input type="text" name="appraisername" class="input-custom"> <br><br><br><br> <button id="" type="submit" class="btn btn-danger" align="right">save , print</button> </div> </div> </div> </div> </div> </form> </div> </div> </div> </div> <script src="js/jquery.js"></script> <script src="js/custom.js"></script> <script src="js/bootstrap.min.js"></script> <script> $("#menu-toggle").click(function(e) { e.preventdefault(); $("#wrapper").toggleclass("toggled"); }); </script> <footer> <center> copyright 2015 - pbms. rights reserved. </center> </footer> </body> </html>
your sql queries don't have terminating semi-colons part of query, when concatenate them there no way server know 1 query ends , next starts.
update eacch query this:
// insert query loan. $sql = "insert loan". "(principal_loan, interest_absolute_amount, service_charge, net_proceeds)". "values ('".$principal."', '".$interestabsoluteamount."', '".$servicechargeamount."', '".$netproceeds."');"; on there --> add semi-colon here ^
additionally, should check return value of calls mysqli
ensure no errors reported. if don't, mysqli
fail silently.
this easy single queries - check return value , if it's false @ mysqli_error()
$result = mysqli_query($con, 'some query...'); if ($result === false) { echo mysqli_error($con); exit; }
if you're using multi-query
it's more complicated have call mysqli_next_result()
check return value of each query. more detals given in manual here;
unless have real performance issues multi-query()
offers little benefit , complication. i'd advise use series of single queries. if you're concerned having 'all or nothing' update, wrap whole series in transaction.
Comments
Post a Comment