insert data into database from array - php

i need to add data to database from array(table). but this POST.php is not working properly. so can you guys please give me any solution for this.
this is the error that it give.
Illegal string offset 'h_name' in C:\wamp\www\confirm\post.php on line 11
line 11 is: VALUES ('$row[h_name]', '$row[room]', '$row[nors]', '$row[nights]', '$row[euro]', '$row[date]', '09090')";
all inserted value give that error. Array to string conversion
Thank you.
</br>
<h4 id="italic">Hotel Details :</h4>
</br>
<div class="reqtable">
<table>
<tr ><td>Hotel Name</td><td>Room Type</td><td>Number of Rooms</td><td>Nights</td><td>EURO</td><td>Date</td></tr>
<tr><td><?php
include "conn.php";
$query = "SELECT h_id, h_name FROM hotels";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn)); // Run your query
echo '<select name="list[h_name]" id="h_name" ">';
echo '<option value=""> Choose a Hotel </option>';
while($row = mysqli_fetch_assoc($result)) {
echo '<option value="'.$row['h_id'].'">'.$row['h_name'].'</option>';
}
echo '</select>';/
?>
</td>
<td>
<?php echo '
<select name="list[room]" id="room" >
<option value="">Choose a Room Type</option>
<option value="1">Single Room</option>
<option value="2">Double Room</option>
<option value="3">Triple Room</option>
<option value="4">Family Room</option>
<option value="5">Custom Room</option>
</select>';
?>
</td>
<td><input type="text" name="list[nors]" placeholder="Number of Rooms"></td>
<td> <input type="text" class="zxc" nname="list[nights]" placeholder="Nights"></td>
<td><input type="text" name="list[euro]" placeholder="euro"></td>
<td><input type="date" name="list[date]" placeholder="Date"></td>
<td><pre> </pre></td>
<td><input type='button' class='AddNew' value='Add new item'></td></tr>
<tr><td>Total</td><td></td><td></td><td><input name="result" id="result"></td><td></td><td></td></tr>
</table>
</div>
</br>
<input type="submit" id="submit" name="submit" value="Register" color="red" style="width: 77px; height: 50px"></div>
</form>
post.php(php process)
<?php
include "conn.php";
print_r($_POST['list']);
foreach ($_POST as $row) {
$query = "INSERT INTO reqhotels (reqh_h_name, reqh_rtype, reqh_nor, reqh_nights, reqh_euro, reqh_date, reqh_req_no)
VALUES ('$row[h_name]', '$row[room]', '$row[nors]', '$row[nights]', '$row[euro]', '$row[date]', '09090')";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
if($result > 0) {
echo"successfull";
}
else {
echo"fail";
}
}
?>
EDIT : ported from answer to question : Aug.05
this is my html codes. (html table). in here used a jquery to add some extra rows to this table. so i want to insert all data to database.
table columns:
rq_h_name, rq_rtype, rq_nors, rq_nights, rq_euro, rq_date
<form action="post.php" method="POST" id="register-form" novalidate="novalidate">
</br>
<h4 id="italic">Hotel Details :</h4>
</br>
<div class="reqtable">
<table>
<tr >
<td>Hotel Name</td>
<td>Room Type</td>
<td>Number of Rooms</td>
<td>Nights</td>
<td>EURO</td>
<td>Date</td>
</tr>
<tr>
<td>
<?php
include "conn.php";
$query = "SELECT h_id, h_name FROM hotels";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn)); // Run your query
echo '<select name="list[0][]" id="h_name" ">';
echo '<option value=""> Choose a Hotel </option>';
while($row = mysqli_fetch_assoc($result)) {
echo '<option value="'.$row['h_id'].'">'.$row['h_name'].'</option>';
}
echo '</select>';
?>
</td>
<td>
<?php echo '
<select name="list[0][]" id="room" >
<option value="">Choose a Room Type</option>
<option value="1">Single Room</option>
<option value="2">Double Room</option>
<option value="3">Triple Room</option>
<option value="4">Family Room</option>
<option value="5">Custom Room</option>
</select>';
?>
</td>
<td><input type="text" name="list[0][]" placeholder="Number of Rooms"></td>
<td> <input type="text" class="zxc" name="list[0][]" placeholder="Nights"></td>
<td><input type="text" name="list[0][]" placeholder="euro"></td>
<td><input type="date" name="list[0][]" placeholder="Date"></td>
<td><input type='button' class='AddNew' value='Add new item'></td></tr>
<tr>
<td>Total</td>
<td><input name="result" id="result"></td>
</tr>
</table>
</div>
</br>

probably you want to do the following
foreach ($_POST['list'] as $row) {
or similar instead of current
foreach ($_POST as $row) {
In your current manner you have an array in array so and the array could not be substituted directly to a string. I'm not sure this will exactly work, but that's the idea you shoud follow and shows the problem you have. Your code is a bit messy so I'won't guarantee you have no other errors.

Related

mysql update multiple column in multiple rows

i am trying to update multiple data in both rows and columns in my table where client_id = '5' and invoice_number = '11'
My Table tbl_particulars
My code:
<table class="table table-bordered">
<tr>
<th>Date</th>
<th>Car No.</th>
<th>Particulars</th>
<th>Rate</th>
<th>Amount</th>
</tr>
<?php
$sql = "SELECT * FROM tbl_particulars WHERE client_id = '5' AND invoice_number = '11'";
$query = mysql_query($sql);
while($row = mysql_fetch_assoc($query)) {
?>
<tr>
<td width="200px" nowrap="nowrap"><table>
<tr>
<td>From<br>
<input type="hidden" name="numbers" value="3">
<input type="hidden" name="ids[]" value="<?php echo $row['id'] ?>">
<input type="text" name="date_from[]" value="<?php echo $row['date_from'] ?>" class="form-control" placeholder="DD/MM/YYYY"></td>
<td> </td>
<td>To<br>
<input type="text" name="date_to[]" value="<?php echo $row['date_to'] ?>" class="form-control" placeholder="DD/MM/YYYY"></td>
</tr>
</table></td>
<td width="100px"><input type="text" name="car_no[]" value="<?php echo $row['car_no'] ?>" class="form-control"></td>
<td width="250px"><table>
<tr>
<td><select name="particulars[]" class="form-control">
<option value="">--Please Select ur Duty--</option>
<option value="Local 80 Kms. & 8.00 Hrs. Duty" <?php if($row['particulars']=="Local 80 Kms. & 8.00 Hrs. Duty") echo 'selected="selected"'; ?> >Local 80 Kms. & 8.00 Hrs. Duty</option>
<option value="Upto" <?php if($row['particulars']=="Upto") echo 'selected="selected"'; ?>>Upto</option>
<option value="Extra Kms." <?php if($row['particulars']=="Extra Kms.") echo 'selected="selected"'; ?>>Extra Kms.</option>
<option value="Extra Hrs." <?php if($row['particulars']=="Extra Hrs.") echo 'selected="selected"'; ?> >Extra Hrs.</option>
<option value="Local Nights" <?php if($row['particulars']=="Local Nights") echo 'selected="selected"'; ?> >Local Nights</option>
<option value="Parking Toll Tax" <?php if($row['particulars']=="Parking Toll Tax") echo 'selected="selected"'; ?> >Parking Toll Tax</option>
<option value="Out Station" <?php if($row['particulars']=="Out Station") echo 'selected="selected"'; ?> >Out Station</option>
</select></td>
<td style="vertical-align:text-top !important">  #   </td>
<td width="100px"><input type="text" value="<?php echo $row['quantity'] ?>" name="quantity[]" class="form-control"></td>
</tr>
</table></td>
<td width="80px"><input type="text" name="rate[]" class="form-control" value="<?php echo $row['rate'] ?>" onChange="CalcGST()"></td>
<td width="80px"><input type="text" name="amount[]" class="form-control" value="<?php echo $row['amount'] ?>" onChange="CalcGST()"></td>
</tr>
<?php } ?>
<tr>
<td colspan="5"><button type="submit" name="update_invoicee" class="btn btn-info">Save & Continue</button></td>
</tr>
</table>
</div>
</form>
My Php Script:
<?php if(isset($_POST['update_invoicee'])){
$s = "UPDATE `tbl_particulars` SET";
for($i=0;$i<$_REQUEST['numbers'];$i++)
{
$s .="(
date_from='".$_REQUEST['date_from'][$i]."',
date_to='".$_REQUEST['date_to'][$i]."',
car_no='".$_REQUEST['car_no'][$i]."',
particulars='".$_REQUEST['particulars'][$i]."',
quantity='".$_REQUEST['quantity'][$i]."',
rate='".$_REQUEST['rate'][$i]."',
amount='".$_REQUEST['amount'][$i]."' WHERE id='".$_REQUEST['ids'][$i]."'),";
}
$s = rtrim($s,",");
if(!mysql_query($s))
echo mysql_error();
else
echo "<script>alert('Records Updated')</script>";
} ?>
now script does not work gives below error:
Erreur de syntaxe pr�s de '( date_from='newvalue', date_to='newvalue', car_no='newvalue' � la ligne 1
The syntax error you received is due to "(" symbol after the SET keyword. It does not allow set multiple statements with more than one SET or WHERE in one query (MySQL Reference).
It is possible to put conditional expressions to every field and concatenate query string for all received ids (some example). But it will be really too much - one additional loop for every field and complex code to format this query (think about writing, debugging, reviewing and supporting it in future).

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>

how to show selected dropdown value after submit on same page

There is two drop-down list having different values and a submit button. after submiting it the action is on the same page with $_SERVER['PHP_SELF']; now i want to show the selected dropdown value after the report is generated but i cant figure out how to do that.
<form name="gg" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table align="center">
<tr>
<th>
<label>Center Name:</label>
</th>
<td>
<select name="center_name" id="centername" required >
<option value="">Select Center</option>
<option value="xxx">XXX</option>
</select>
</td>
</tr>
<tr>
<th>
Age:
</th>
<td>
<select name="age_bracket" id="agebracket" required >
<option value="" >Select Age</option>
<option value="18-24" >18-23</option>
<option value="25-34" >25-34</option>
<option value="35-44" >35-44</option>
<option value="45-54" >45-54</option>
<option value="55-64" >55-64</option>
<option value="65-74" >65-74</option>
<option value="75" >75+</option>
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" value="Submit"></td>
</tr>
<?php
//db connection goes here
echo "<table style='width:70%' table border='1' style='table-layout:fixed' align='center'>";
echo "<tr>
<th>No</th>
<th>col1</th>
<th>col2</th>
<th>col3</th>
<th>col4</th>
</tr>";
if(isset($_POST['submit'])) {
//processing request here
//echo fetched rows
result comes like this
centername:-
age:-
submit
slno col1 col2 col3 col4
//after submit i get the report fetched here on the same page but could not get the selected drop-down values
I don't understand your question very well... I have read your comments... I think you want something like this?
<form name="gg" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table align="center">
<tr>
<th>
<label>Center Name:</label>
</th>
<td>
<select name="center_name" id="centername" required >
<option value="">Select Center</option>
<option value="xxx"<?php if(isset($_POST["center_name"]) && $_POST["center_name"] == "xxx") { echo " selected"; } ?>>XXX</option>
</select>
</td>
</tr>
<tr>
<th>
Age:
</th>
<td>
<select name="age_bracket" id="agebracket" required >
<option value="" >Select Age</option>
<option value="18-24"<?php if(isset($_POST["age_bracket"]) && $_POST["age_bracket"] == "18-24") { echo " selected"; } ?>>18-23</option>
<option value="25-34"<?php if(isset($_POST["age_bracket"]) && $_POST["age_bracket"] == "25-34") { echo " selected"; } ?>>25-34</option>
<option value="35-44"<?php if(isset($_POST["age_bracket"]) && $_POST["age_bracket"] == "35-44") { echo " selected"; } ?>>35-44</option>
<option value="45-54"<?php if(isset($_POST["age_bracket"]) && $_POST["age_bracket"] == "45-54") { echo " selected"; } ?>>45-54</option>
<option value="55-64"<?php if(isset($_POST["age_bracket"]) && $_POST["age_bracket"] == "55-64") { echo " selected"; } ?>>55-64</option>
<option value="65-74"<?php if(isset($_POST["age_bracket"]) && $_POST["age_bracket"] == "65-74") { echo " selected"; } ?>>65-74</option>
<option value="75"<?php if(isset($_POST["age_bracket"]) && $_POST["age_bracket"] == "75") { echo " selected"; } ?>>75+</option>
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" value="Submit"></td>
</tr>
</table>
</form>
To get the select values you can simply:
<?php
echo $_POST['center_name'];
echo $_POST['age_bracket'];
?>
You can remove <?php echo $_SERVER['PHP_SELF']; ?> from action as well.
<?php
echo "centername:".$_POST['center_name'];
echo "Age:" $_POST['age_bracket'];
?>
<form name="gg" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table align="center">
<tr>
<th>
<label>Center Name:</label>
</th>
<td>
<select name="center_name" id="centername" required >
<option value="">Select Center</option>
<option value="xxx">XXX</option>
</select>
</td>
</tr>
<tr>
<th>
Age:
</th>
<td>
<select name="age_bracket" id="agebracket" required >
<option value="" >Select Age</option>
<option value="18-24" >18-23</option>
<option value="25-34" >25-34</option>
<option value="35-44" >35-44</option>
<option value="45-54" >45-54</option>
<option value="55-64" >55-64</option>
<option value="65-74" >65-74</option>
<option value="75" >75+</option>
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" value="Submit"></td>
</tr>
</form>

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);

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