Duplicate rows in MySQL db - php

For some reason every once in a while my code will enter data into the database twice. I have changed my code and made some tweaks but have not had any luck. I know I must be over looking something I just don't know what.
<?php
$con = new mysqli("localhost", "******", "******", "******");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$conpo = new mysqli("localhost", "******", "******", "******");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$resultpo = mysqli_query($conpo, "SELECT * FROM fpo ORDER BY ponum DESC LIMIT 1");
while ($rowp = mysqli_fetch_array($resultpo)) {
$po = $rowp['ponum'];
$ponum = ++$po;
}
$date = $_POST['date'];
$to = $_POST['to'];
$time = $_POST['time'];
$vin = $_POST['stk_vin'];
$reason = $_POST['reason'];
$amount = $_POST['amount'];
$empnum = $_POST['emp'];
$mananger = $_POST['mananger'];
$accnum = $_POST['acc'];
$store_location = $_POST['store'];
$borr = $_POST['borrowed'];
$oldid = $_POST['oldid'];
mysqli_query($con,
"INSERT INTO fpo (" .
"`ponum`, `date`, `to`, `time`, `vin`, `reason`, `amount`, `empnum`, `mananger`, `accnum`, `store_location`, `borr`" .
") VALUES (" .
"'$ponum', '$date', '$to', '$time', '$vin', '$reason', '$amount', '$empnum', '$mananger', '$accnum', '$store_location', '$borr'" .
")");
?>
Here is the html forum page.
<form action="print.php" method="POST" name="form1" id="form1">
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" class="table" style="width:700px">
<tbody>
<tr>
<td height="19" colspan="2" valign="middle" class="to" style="width:450px" ><div class="logo"></div></td>
<td width="95" rowspan="2" valign="bottom"><div class="date">Date:
<label>
<input name="date" type="text" readonly id="date" value="07/15/2015" size="10" />
</label>
</div></td>
<td width="106" rowspan="2" valign="bottom" class="po" style="width:100px" ><div class="date">PO: <span id="sprytextfield3">
<label>
<input name="po" readonly type="text" value="14739" />
<input type="hidden" name="oldid" value="11810">
</label>
<span class="textfieldRequiredMsg">A value is required.</span></span></div></td>
</tr>
<tr>
<td height="20" colspan="2" valign="middle" class="to" style="width:450px" ><div class="toheader">To: <span id="spryselect1">
<label>
<select name="to" id="to">
<option selected="selected" disabled="disabled">Select One</option>
<option value="1">Kum-N-Go</option>
</select>
</label>
<span class="selectRequiredMsg">Please select an item.</span></span>
<input name="time" type="hidden" id="time" value="
11:13:33 ">
</div></td>
</tr>
<tr>
<td colspan="2" style="height:125px" ><b> Reason For Gas Ticket: </b> <br>
<span id="spryselect2">
<label>
<select name="reason" id="reason">
<option selected="selected" disabled="disabled">Select One</option>
<option value="Advertising">Advertising</option>
<option value="Auction">Auction</option>
</select>
</label>
<span class="selectRequiredMsg">Required</span></span><br>
<br>
Car Borrowed From Another Dealership? <br>
<span id="spryselect3">
<label>
<select name="borrowed" id="borrowed">
<option selected="selected" disabled="disabled">Select One</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</label>
<span class="selectRequiredMsg">Please select an item.</span></span><br></td>
<td><b>stk/vin/RO#:</b><br>
<span id="sprytextfield2">
<label>
<input name="stk_vin" type="text" id="stk_vin" onclick="return stk()" size="12" />
</label>
<span class="textfieldRequiredMsg"><br />
Stock or Vin .</span></span></td>
<td align="center"><b> Amount<br>
<div class="money"><span id="spryselect5">
<label><b>
<select name="amount" id="amount">
<option value="5.00" selected="selected">5.00</option>
<option value="1.00">1.00</option>
<option value="2.00">2.00</option>
<option value="3.00">3.00</option>
<option value="4.00">4.00</option>
<option value="5.00">5.00</option>
<option value="6.00">6.00</option>
<option value="7.00">7.00</option>
<option value="8.00">8.00</option>
<option value="9.00">9.00</option>
<option value="10.00">10.00</option>
</select>
</b></label>
<span class="selectRequiredMsg">Please select an item.</span></span></div>
</b></td>
</tr>
<tr>
<td width="257">Employee Requesting Po:<span id="spryselect9">
<label>
<select name="emp" id="acc">
<option selected="selected" disabled="disabled">Select One</option>
<option value="5223">5223</option>
</optgroup>
</select>
</label>
<span class="textfieldRequiredMsg">Required</span><span class="textfieldInvalidFormatMsg">Required</span></span></td>
<td width="219">Acc #:<span id="spryselect4">
<label>
<select name="acc" id="acc">
<option selected="selected" disabled="disabled">Select One</option>
<option value="51">Sales</option>
<option value="52">Services</option>
<option value="53">Parts</option>
<option value="FI">F&I</option>
</select>
</label>
<span class="selectRequiredMsg">Required</span></span></td>
<td colspan="2" align="right"><label> Mananger:
<input name="mananger" onclick="return getfoc()" type="text" id="mananger" size="12" readonly />
</label></td>
</tr>
<tr>
<td></td>
<td>Store: <span id="spryselect6">
<label>
<select name="store" id="store">
<option disabled="disabled" selected="selected">Select One</option>
<option value="chevy">Chevy</option>
<option value="Ford">Ford</option>
<option value="Dodge">Dodge</option>
</select>
</label>
<span class="selectRequiredMsg">Required</span></span></td>
<td colspan="2" align="right"><div id="btn"> </div>
<script language='javascript' type='text/javascript'>
function GetValueFromChild(myVal)
{
document.getElementById('mananger').value = myVal;
document.getElementById('btn').innerHTML = '<input type="submit" id="register" value="Print Ticket" />';
}
</script></td>
</tr>
</tbody>
</table>
<p> </p>
</form>

Because you are not doing atomic operation. Lets assume the below flow:
SELECT1 -> SELECT2-> INSERT1-> INSERT2
How are avoid this - no synchronization or locking. You can avoid this with few options.
Use a lock before entering this block and free once insert is done( in PHP). This can be based on file lock or memcache lock
You can add an index on the column you want to keep unique say, (ponum, from, to). Instead of using INSERT, you can use INSERT IGNORE

I am pretty sure your users are clicking the submit button twice I had this issue before I fixed it using jquery's validator such as following.
$(document).ready(function(){
$("#form1").validate({submitHandler: function(form) {if (!this.beenSubmitted) {this.beenSubmitted = true;form.submit();} }});
});

Related

php mysql can't multiply a mysql result and a variable

I can't for the life of me figure out why i keep coming up with 0 on this ... i'm pulling a price from one of my tables and multiplying it by the quantity they are putting in in the form ... for some reason it when i try and do the math, it keeps coming up as 0 ... any help?
code:
$get_code = "SELECT * FROM products WHERE p_code LIKE '%$po_code%'";
$run_code = mysqli_query($con, $get_code);
$row_code = mysqli_fetch_array($run_code);
$count = $_POST['ord_amt'];
$price = $row_code['p_price'];
$sum_total = $price * $count;
form code:
<form action="" method="post">
<?php
include('includes/connection.php');
global $con;
$cust = "SELECT * FROM users WHERE u_id = '".$_SESSION['u_id']."'";
$r_cs = mysqli_query($con, $cust);
$rw_c = mysqli_fetch_array($r_cs);
echo "<input type='hidden' name='c_id' value='".$rw_c['c_id']."'>";
?>
<table id="datatable1" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Product</th>
<th>Distal Opening</th>
<th>Material</th>
<th>Ply</th>
<th>Size</th>
<th>Length</th>
<th>Options</th>
<th>Or Enter Code (If Known)</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<select class="form-control" name="prod" id="selectProd" onchange="get_prod(this.value)" required="required">
<?php get_prod_kind() ?>
</select>
</td>
<td>
<select class="form-control" name="opening" id="distOpen" required="required">
<option value="">Select Opening</option>
<option value="1">Rubberized Reinforced</option>
<option value="2">Standard Opening</option>
<option value="">None</option>
</select>
</td>
<td>
<select class="form-control" name='mat' id="selectMat" onchange="get_ply(this.value)" required="required">
</select>
</td>
<td>
<select class="form-control" name="ply" id="plySelect" onchange="get_size(this.value)" required="required">
<option value=""></option>
</select>
</td>
<td>
<select class="form-control" name="size" id="sizeSelect" onchange="get_len(this.value)" required="required">
<option value=""></option>
</select>
</td>
<td>
<select class="form-control" name="length" id="selectLength" required="required">
<option value=""></option>
</select>
</td>
<td>
<select class="form-control" name="opts" required="required">
<option value="">Select Options</option>
<option value="1">Sewn Top (S)</option>
<option value="2">Seal-In-Liner (C)</option>
<option value="">None</option>
</select>
</td>
<td><input class="form-control" type='text' name='cust_code'></td>
<td><input class="form-control" type='text' name='ord_amt' required="required"></td>
</tr>
</tbody>
</table>
<button class="button button-3d button-rounded button-aqua" name="p_order"><i class="icon-repeat"></i>Next Item</button>
<button class="button button-3d button-rounded button-green"><i class="icon-ok"></i>Submit Order</button>
</form>

Post table rows which are checked with other select boxes

This may be a duplicate question,
But still, I did not find the answer.
My requirement is :
How to get the table rows which are CHECKED.
Here is my issue's screenshot. enter image description here
My checkbox name is 'check[]'
and the name of the select box is 'class[]',
and the form is posted to process.php.
How to get the value of 'class[]' where the checked boxes are checked so that I can then process with PHP-MYSQL?
My code is here:
<div class="col-md-5">
<form action="process.php" method="post">
<table class="table" id="table">
<tr><th>Opt</th><th>Name</th><th>Next Class</th></tr>
<? $q = $sdb->where('ac_CurClass',4)->get('tbl_accounts');
foreach ($q as $r){ ?>
<tr>
<td><input type="checkbox" name="sel[]" class="checkbox small" value="<?=$r['ac_Id'];?>"></td>
<td><?=ac_details($r['ac_Id'])->ac_Name;?></td>
<td>
<select class="form-control small" name="class[]">
<? $c = $sdb->where('c_Id',ac_details($r['ac_Id'])->ac_CurClass,">")->get("tbl_classes");
foreach($c as $d) {?>
<option value="<?=$d['c_Id'];?>"><?=$d['c_Name'];?></option>
<? } ?></select>
</td>
</tr>
<? } ?>
</table>
<button type="submit" class="btn btn-danger">Update</button>
</form>
</div>
Hope this code is help full for you
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<div class="col-md-5">
<form action="#" method="post">
<table class="table" id="table">
<thead><tr><th>Opt</th><th>Name</th><th>Next Class</th></tr></thead>
<tbody id="cont">
<tr>
<td><input type="checkbox" name="sel[]" class="checkbox small" value="1"></td>
<td>asass</td>
<td>
<select class="form-control small" name="class[]">
<option value="">Select option</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
</td>
</tr>
<tr>
<td><input type="checkbox" name="sel[]" class="checkbox small" value="2"></td>
<td>asass</td>
<td>
<select class="form-control small" name="class[]">
<option value="">Select option</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
</td>
</tr>
<tr>
<td><input type="checkbox" name="sel[]" class="checkbox small" value="3"></td>
<td>asass</td>
<td>
<select class="form-control small" name="class[]">
<option value="">Select option</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
</td>
</tr>
</tbody>
</table>
<button type="button" class="btn btn-danger" id="submit">Update</button>
</form>
</div>
<script>
$(document).ready(function(){
$('#submit').click(function(){
$("#cont input:checkbox:checked").map(function(){
alert('Checkbox value - '+$(this).val()+' / Select Box value - '+$(this).parent().next().next('td').find('select').val());
//alert('Select Box value - '+$(this).parent().next().next('td').find('select').val());
});
});
});
</script>
After that you can pass a Ajax so that only checked rows post.
Try as follows
Post as form
<form action="process.php" method="post">
In process.php file
if($check[0]===true){
$nextclass1 = $_POST['list_box'];
}
if($check[1]===true){
$nextclass2= $_POST['list_box'];
}

PHP Unable to POST select box values

I'am trying to get some values from users and after that I'am inserting these values to my database but I can't get some of my select boxes's values using $_POST.
Users first select intership type via selectbox and depending on value of this selectbox the bottom menu changes via jQuery (That's why these IENG349ReqCourses and IENG449ReqCourses div's are hidden).
But I can't get the values of grade selecboxes inside of these hidden div's. Rest of input fields are okay, I can get their values and save to my database.
HTML:
<form id="intershipStage1Form" method="POST" action="form1.php">
<div id="generalInfo">
<center>
<table>
<tr>
<td colspan="2" valign="middle" align="center">
<label id="stuNameLabel">Student Full Name: <?php echo $_SESSION['username']; ?></label>
</td>
</tr>
<tr>
<td title="Your student number contains only numbers and should be 11 digits " valign="middle"><label id="stuNumberLabel">Student Number:</label></td>
<td><input id="stuNumberText" class="form1Text" type="text" name="stuNumberText" /></td>
</tr>
<tr>
<td title="A sample format: 3.16 and do not use comma(,)" valign="middle"><label id="stuGPALabel">Student GPA:</label></td>
<td><input id="stuGPAText" class="form1Text" type="text" name="stuGPAText" /></td>
</tr>
<tr>
<td title="Choose your academic advisor" valign="middle"><label id="stuAdvisorLabel">Student Advisor:</label></td>
<td align="center">
<select id="advisorSelectionBox" name="advisorSelectionBox">
<option value="">--select--</option>
<?php
$userType = "A";
$stmt = $db->prepare("SELECT * FROM users WHERE UserType = ?");
if($stmt == "false"){
die('Query error !'.$db->error);
}
$stmt->bind_param('s', $userType);
$stmt->execute();
$result = $stmt -> get_result();
while($advisor = $result ->fetch_array(MYSQLI_BOTH)){
echo '<option value="'.$advisor["UserID"].'">'.$advisor['FirstName']." ".$advisor['LastName'].'</option>';
}
?>
</select>
</td>
</tr>
<tr>
<td title="Choose your current study year" valign="middle">
<label>Study Year:</label>
</td>
<td align="center">
<select id="studyYearBox" name="studyYearBox">
<option value="">--select--</option>
<option value="SOPHOMORE">SOPHOMORE</option>
<option value="JUNIOR">JUNIOR</option>
<option value="SENIOR">SENIOR</option>
</select>
</td>
</tr>
<tr>
<td title="Choose your internship type before try to sent this form to your advisor" valign="middle">
<label>Internship Type:</label>
</td>
<td align="center">
<select id="intershipTypeBox" name="intershipTypeBox">
<option value="">--select--</option>
<option value="IENG349">IENG 349</option>
<option value="IENG449">IENG 449</option>
</select>
</td>
</tr>
</table>
</center>
</div>
<div id="litleSpacer"></div>
<div id="IENG349ReqCourses" class="reqCourses" hidden="true">
<center>
<table>
<caption style="color:#f00;">Please select your grades</caption>
<tr>
<td valign="middle">
<label>IENG 102 - Intro to IE:</label>
</td>
<td>
<select name="IENG102Grade">
<option value="">--select--</option>
<option value="A">A</option>
<option value="A-">A-</option>
<option value="B+">B+</option>
<option value="B">B</option>
<option value="B-">B-</option>
</select>
</td>
</tr>
</table>
</center>
</div>
<div id="IENG449ReqCourses" class="reqCourses" hidden="true">
<center>
<table>
<caption style="color:#f00;">Please select your grades</caption>
<tr>
<td valign="middle">
<label>IENG 312 - System Simulation:</label>
</td>
<td>
<select name="IENG312Grade">
<option value="">--select--</option>
<option value="A">A</option>
<option value="A-">A-</option>
<option value="B+">B+</option>
<option value="B">B</option>
<option value="B-">B-</option>
</select>
</td>
</tr>
</table>
</center>
</div>
<div id="litleSpacer"></div>
<input id="sendButton" type="submit" name="sendButton" value="SEND FOR APPROVEMENT"/>
</form>
PHP:
<?php
$stuID = $_SESSION['user_id'];
$stuFullName = $_SESSION['username'];
$stuNumber = $_POST['stuNumberText'];
$stuGPA = $_POST['stuGPAText'];
$stuAdvisor = $_POST['advisorSelectionBox'];
$studyYear = $_POST['studyYearBox'];
$internshipType = $_POST['intershipTypeBox'];
$coordinatorAppr = "SENT";
$advisorAppr = "SENT";
$IENG102 = $_POST['IENG102Grade'];
$IENG312 = $_POST['IENG312Grade'];
$insert_stmt = $db->prepare("INSERT INTO internship_form_info VALUES(NULL,?,?,?,?,?,?,?,?,?)");
if($insert_stmt === false){
die('Query Error: '.$db->error);
}
$insert_stmt ->bind_param("sssssssii",$stuFullName,$stuNumber,$stuGPA,$studyYear,$internshipType,$advisorAppr,$coordinatorAppr,$stuID,$stuAdvisor);
$insert_stmt ->execute();
$formID = $db->insert_id;
if($internshipType=="IENG349"){
$insert_stmt2 = $db->prepare("INSERT INTO ieng349_req_courses_grades VALUES(NULL,?,?,?)");
if($insert_stmt2 === false){
die('Query Error: '.$db->error);
}
$insert_stmt2 ->bind_param("iisssssss",$stuID,$formID,$IENG102);
$insert_stmt2 ->execute();
}
else if($internshipType=="IENG449"){
$insert_stmt3 = $db->prepare("INSERT INTO ieng449_req_courses_grades VALUES(NULL,?,?,?)");
if($insert_stmt3 === false){
die('Query Error: '.$db->error);
}
$insert_stmt3 ->bind_param("iisssssssssssss",$stuID,$formID,$IENG312);
$insert_stmt3 ->execute();
}
$db->close();
So what can be the problem? Any help would be appriciated!
You have to make one option as selected to get it posted to the server.
If field is hidden and no option is marked selected, you will get no value on server.
I suggest to you, to check for example in Live Http Headers, which $_POST date you send. Also in your very top of script put
var_dump($_POST);

Error: Champ 'product_name' inconnu dans field list

I am trying to store form data in a database using WampServer.
When I click on the submit button it shows me this error:
"Error: Champ 'product_name' inconnu dans field list".
I am using the same work for another form. That form is working but i dont know what is wrong with this one, Please help me out
My form code is :
<form action="saddproduct.php" enctype="multipart/form-data" name="myForm" id="myForm"
method="post">
<table width="90%" border="1" cellpadding="6">
<tr>
<td width="20%">Product Name</td>
<td width="80%">
<label>
<input name="product_name" type="text" id="product_name" size="60" />
</label>
</td>
</tr>
<tr>
<td width="20%">Product Code</td>
<td width="80%">
<label>
<input name="product_code" type="text" id="product_code" size="60" />
</label>
</td>
</tr>
<tr>
<td width="20%">Product Availability</td>
<td width="80%">
<label>
<select name="availability" id="availability">
<option value=""></option>
<option value="in"> In Stock </option>
<option value="out"> Out Of Stock </option>
</select>
</label>
</td>
</tr>
<tr>
<td width="20%">Product Price</td>
<td width="80%">
<label>
Rs.
<input name="price" type="text" id="price" size="12" />
</label>
</td>
</tr>
<tr>
<td align="right">Category</td>
<td>
<label>
<select name="category" id="category">
<option value=""></option>
<option value="living"> Living Rooms </option>
<option value="bed"> Bed Rooms </option>
<option value="dining"> Dining Rooms </option>
</select>
</label>
</td>
</tr>
<tr>
<td align="right">Sub category</td>
<td>
<label>
<select name="subcategory" id="subcategory">
<option value=""></option>
<option value="lsofa"> Lining Sofa </option>
<option value="lchair"> Living Chair </option>
<option value="ltable"> Living Table </option>
<option value="bking"> King Beds </option>
<option value="bqueen"> Queen Beds </option>
<option value="dtable"> Dining Tables </option>
<option value="dchairs"> Dining Chairs </option>
<option value="hsale"> Sale Item For Home Page </option>
<option value="psale"> Sale Item For Sale Page </option>
</select>
</label>
</td>
</tr>
<tr>
<td width="20%">Product Detail</td>
<td width="80%">
<label>
<textarea name="details" id="details" cols="64" rows="5"> </textarea>
</label>
</td>
</tr>
<tr>
<td> </td>
<td width="80%">
<label>
<input type="submit" name="button" id="button" class="button" value="Add This
Product Now" />
</label>
</td>
</tr>
<tr>
<td width="20%"> </td>
<td width="80%"> </td>
</tr>
</table>
</form>
And my processing PHP page is saddproduct.php which look like :
<?php
$con=mysqli_connect("localhost","root","03005225400","furniture");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security
$product_name = mysqli_real_escape_string($con, $_POST['product_name']);
$product_code = mysqli_real_escape_string($con, $_POST['product_code']);
$availability = mysqli_real_escape_string($con, $_POST['availability']);
$price = mysqli_real_escape_string($con, $_POST['price']);
$category = mysqli_real_escape_string($con, $_POST['category']);
$subcategory = mysqli_real_escape_string($con, $_POST['subcategory']);
$details = mysqli_real_escape_string($con, $_POST['details']);
$sql="INSERT INTO employee
(product_name , product_code, availability, price,
category, subcategory, details, date_added)
VALUES('$product_name','$product_code', '$availability',
'$price','$category','$subcategory','$details',now())"
or die (mysql_error());
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
mysqli_close($con);
?>
I am sure that if you verify your table structure you wont find any column named product_name, at least not with the exact case.
Try verifying your column names, and if you still dont have a clue, try removing column names and sticking to the order of your table structure while putting NULL in fields with default content like auto increment and timestamps.
Simple typo. Table employee should be products
Sometimes this(Error: Champ 'Yes' inconnu dans field list) type error occurs due to using (`) this single quotes rather than using (') this quotes in INSERT query.

Posting Form Into SQL Database

The very first field named Forte ID posts a value of 0 no matter what selection I choose. Here are my two files:
Index.php(Form)
</head>
<h1> Customer Service Log Form </h1>
<form method="post" action="insert.php">
<table width="625" border="0">
<tr>
<td> Forte ID:</td>
<td><select id="ForteID" name="ForteID">
<option value="0">Select Your ID</option>
<option value="as7326">as7326</option>
<option value="aw8743">aw8743</option>
<option value="bj0920">bj0920</option>
<option value="bs1441">bs1441</option>
<option value="dk7017">dk7017</option>
<option value="dl7686">dl7686</option>
<option value="dm2940">dm2940</option>
<option value="jn2468">jn2468</option>
<option value="jw9598">jw9598</option>
<option value="kp4945">kp4945</option>
<option value="nl2589">nl2589</option>
<option value="rp7021">rp7021</option>
<option value="sh1346">sh1346</option>
</select></td>
</tr>
<tr>
<td> Disposition</td>
<td><select id="disposition" name="disposition">
<option value="0">Select a Disposition</option>
<option value="Save">Save</option>
<option value="Sale">Sale</option>
<option value="LOC">LOC</option>
<option value="Backout">Backout</option>
<option value="Revision">Revision</option>
<option value="Revision">Revision/Save</option>
</select>
</td>
</tr>
</table>
<hr />
<br />
<table width="400" border="0">
<tr>
<td>App Number:</td>
<td></td>
<td><input name="appnumber" type="text" required="required"></td>
</tr>
<tr>
<td>Finance Number:</td>
<td></td>
<td><input type="text" name = "Finance_Num"></td>
</tr>
<tr>
<td>Phone Number:</td>
<td></td>
<td><input type="text" name = "Phone_Num"></td>
</tr>
<tr>
<td># of Payments Collected:</td>
<td></td>
<td><input type="text" name = "num_payments"></td>
</tr>
<tr>
<td>ACH/CC</td>
<td></td>
<td><select id="ForteID" name="ForteID">
<option value="0">Select Payment</option>
<option value="ach">Checking</option>
<option value="cc">Credit Card</option>
</select></td>
</tr>
<tr>
<td>Date:</td>
<td></td>
<td><input name = "date" type="text" id="datepicker" autocomplete="off" required="required"></td>
</tr>
</table>
<br />
Notes:
<br />
<textarea name="notes" id="notes" cols="45" rows="5"></textarea>
</fieldset>
<hr />
<input type="Submit" name="formSubmit" value="Submit">
<input type="Reset" name="formReset" value="Reset">
<input type="button" value="View Logs" onClick="window.location.href='logs.php';">
</form>
</head>
Insert.php (PHP file to insert data from form into SQL Server Database):
$serverName = 'Server\SQLEXPRESS';
$connectionInfo = array('Database'=>'database', 'UID'=>'username', 'PWD'=>'password');
$connection = sqlsrv_connect($serverName, $connectionInfo);
if( $connection === false )
{
echo "Connection could not be established.\n";
die( print_r( sqlsrv_errors(), true));
}
$tsql = "INSERT INTO logs(ForteID, disposition, appnumber, Finance_Num, num_payments, ach_cc, date, notes, Phone_Num) VALUES (?,?,?,?,?,?,?,?,?)";
$parameters = array( $_POST[ForteID], $_POST[disposition], $_POST[appnumber], $_POST[Finance_Num], $_POST[num_payments], $_POST[ach_cc], $_POST[date], $_POST[notes], $_POST[Phone_Num]);
$stmt = sqlsrv_query($connection, $tsql, $parameters);
if( $stmt === false ){
echo "Statement could not be executed.\n";
die( print_r( sqlsrv_errors(), true));
} else {
echo "Rows affected: ".sqlsrv_rows_affected( $stmt )."\n";
}
No matter what option is selected in the index.php field Forte ID, it posts a value of 0. What is wrong. It was working before I added a field named Phone Number. But doesnt make sense why that would screw up the selections.
Let me know if I need to clarify anything and thanks for the help in advance!
You have to fields called ForteID
<select id="ForteID" name="ForteID">
<option value="0">Select Payment</option>
<option value="ach">Checking</option>
<option value="cc">Credit Card</option>
is the 2nd one

Categories