Posting Form Into SQL Database - php

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

Related

Duplicate rows in MySQL db

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

Echo data in same form after submitting

I have a simple html form, which is included in a Spry Tabbed Panel.
So, i would like to know, is it possible to submit that form, and only that form in the Panel, and then echo the submitted data back in the correct fields.
The echo part is not a problem doing it on a different page, or redirect after submitting, but my issue comes in with the other forms that should/can not be cleared if this one is submitted.
A hint in the right direction would be greatly appreciated!
Thank you in advance.
see code below:
(i know that the form action should not direct to a different file, but that is just how I've been using it until now...)
<form action="caller_upd.php" method="post" name="contact" >
<table width="200" border="0">
<?php
$_SESSION['uid'] = $uid;
?>
<tr>
<td width="68">Title</td>
<td width="4">:</td>
<td width="144"><select name="title" id="title">
<option selected="selected" disabled="disabled"</option>
<option value="Mr">Mr</option>
<option value="Ms">Ms</option>
<option value="Dr">Dr</option>
</select></td>
<td width="6"> </td>
<td width="53">Number</td>
<td width="3">:</td>
<td width="301"><input style="color:rgb(255,0,0);" autofocus="autofocus" type="text" name="contactnr" id="contactnr" /></td>
</tr>
<tr>
<td>Name</td>
<td>:</td>
<td><input type="text" name="fname" id="fname" /></td>
<td> </td>
<td>Surname</td>
<td>:</td>
<td><input type="text" name="sname" id="sname" /></td>
</tr>
<tr>
<td>Nature of Call</td>
<td>:</td>
<td><select name="type" id="type">
<option disabled="disabled" selected="selected"></option>
<option value="Domestic">Domestic</option>
<option value="MVA">MVA</option>
<option value="Assult">Assult</option>
<option value="Padestrian">Padestrian</option>
<option value="Transfer">Transfer</option>
<option value="Private">Private</option>
</select></td>
<td> </td>
<td>Nr of Patients:</td>
<td>:</td>
<td><select name="nop" id="nop">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10+">10+</option>
</select></td>
</tr>
<tr>
<td>Location</td>
<td><label for="location"></label></td>
<td colspan="5"><input name="location" type="text" id="location" size="50" /> <?php if (!empty($location)){ ?>Show Map<?php } else { } ; ?></td>
</tr>
<tr>
<td>Comments:</td>
<td colspan="6"><textarea name="comment" id="comment" cols="70" rows="5"></textarea></td>
</tr>
<tr>
<td colspan="7" class="form"><input type="submit" name="submit" id="submit" value="Update" /></td>
</tr>
</table>
</form>
Check if the post value exists, and if so either select the option or put the value in the input element...
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="contact" >
<table width="200" border="0">
<tr>
<td width="68">Title</td>
<td width="4">:</td>
<td width="144"><select name="title" id="title">
<option value="Mr" <?php if(isset($_POST['title']) && $_POST['title'] == "Mr") echo "selected"; ?>>Mr</option>
<option value="Ms" <?php if(isset($_POST['title']) && $_POST['title'] == "Ms") echo "selected"; ?>>Ms</option>
<option value="Dr" <?php if(isset($_POST['title']) && $_POST['title'] == "Dr") echo "selected"; ?>>Dr</option>
</select></td>
<td width="6"> </td>
<td width="53">Number</td>
<td width="3">:</td>
<td width="301"><input style="color:rgb(255,0,0);" autofocus="autofocus" type="text" name="contactnr" id="contactnr" value="<?php if(isset($_POST['contactnr'])) echo $_POST['contactnr']; ?>" /></td>
</tr>
<tr>
<td>Name</td>
<td>:</td>
<td><input type="text" name="fname" id="fname" value="<?php if(isset($_POST['fname'])) echo $_POST['fname']; ?>" /></td>
<td> </td>
<td>Surname</td>
<td>:</td>
<td><input type="text" name="sname" id="sname" value="<?php if(isset($_POST['sname'])) echo $_POST['sname']; ?>" /></td>
</tr>
...
</table>
</form>

Why is my PHP is not inserting data into MySQL database? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have this form to input data into a MySQL database. It's not giving me any errors, but also not inserting data. I have looked around the web, with no avail. I'm not sure if it's my code or maybe I've misconfigured my database. Here's all the code.
<!DOCTYPE html>
<html>
<head>
<title>Steam Traps Form</title>
<style type="text/css">
table tr > td { text-align: right; }
table tr > td + td { text-align: left; }
</style>
</head>
<body>
<form action="FormHandler.php" method="post" >
<table border="0">
<tr>
<td align="center"><h1>Steam Trap Form Input</h1></td>
</tr>
<tr>
<td>
<tr>
<td>Date of Survey</td>
<td><input type="date" name="dateSurvey">
</td>
<tr>
<tr>
<td>Plant Name</td>
<td><input type="text" name="plantName"></td>
</tr>
<tr>
<td>Plant Location</td>
<td><input type="text" name="plantLoc"></td>
</tr>
<tr>
<td>Plant Contact Name</td>
<td><input type="text" name="plantContact"></td>
</tr>
<tr>
<td>Direction</td>
<td><select name="direction">
<option value="N">N</option>
<option value="NE">NE</option>
<option value="NW">NW</option>
<option value="S">S</option>
<option value="SE">SE</option>
<option value="SW">SW</option>
<option value="E">E</option>
<option value="W">W</option>
</select>
</td>
</tr>
<tr>
<td>Location (detailed as possible)</td>
<td><input type="text" name="location" size="40">
</td>
</tr>
<tr>
<td>Floor Level</td>
<td><select name="flrLevel">
<option value="grd">Ground</option>
<option value="1st">1st</option>
<option value="2nd">2nd</option>
<option value="3rd">3rd</option>
<option value="4th">4th</option>
<option value="5th">5th</option>
<option value="6th">6th</option>
<option value="7th">7th</option>
<option value="8th">8th</option>
<option value="9th">9th</option>
<option value="10th">10th</option>
<option value="11th">11th</option>
<option value="12th">12th</option>
<option value="13th">13th</option>
<option value="14th">14th</option>
<option value="15th">15th</option>
</select>
</td>
</tr>
<tr>
<td>Elevation (in ft)</td>
<td><input type="number" name="elevation" size="5">
</td>
</tr
<tr>
<td>Tag Number</td>
<td><input type="text" name="tagNum" size="20">
</td>
</tr>
<tr>
<td>MFG Model Number</td>
<td><input type="text" name="mmn" size="30">
</td>
</tr>
<tr>
<td>Size</td>
<td><input type="text" name="size" size="10">
</td>
</tr>
<tr>
<td>Pressure</td>
<td><input type="number" name="pressure" size="5">
</td>
</tr>
<tr>
<td>Service</td>
<td><input type="text" name="service" size="5">
</td>
</tr>
<tr>
<td>Trap Conditions</td>
<td><select name="trapCond">
<option value="OK">OK</option>
<option value="BT">BT</option>
<option value="RCL">RCL</option>
<option value="CP">CP</option>
<option value="VO">VO</option>
</select>
</td>
</tr>
<tr>
<td align="right"><input type="submit"
name="submit" value="Submit"></td>
</tr>
</form>
</td>
</tr>
</table>
<br />
</body>
</html>
Here is the PHP
<?php
$dateSurvey = $_POST["dateSurvey"];
$plantName = $_POST["plantName"];
$plantLoc = $_POST["plantLoc"];
$plantContact = $_POST["plantContact"];
$direction = $_POST["direction"];
$location = $_POST["location"];
$flrLevel = $_POST["flrLevel"];
$elevation = $_POST["elevation"];
$tagNumb = $_POST["tagNum"];
$mmn = $_POST["mmn"];
$size = $_POST["size"];
$pressure = $_POST["pressure"];
$service = $_POST["service"];
$trapCond = $_POST["trapCond"];
$sql_connection = mysql_connect("localhost", "******", "******");
mysql_select_db("******", $sql_connection) or die( "Unable to select database");
$sql = "INSERT INTO steamtraps (
dateSurvey,
plantName,
plantLoc,
plantContact,
direction,
location,
flrLevel,
elevation,
tagNum,
mmn,
size,
pressure,
service,
trapCond,
ContactDateCreated,
)
VALUES (
'{$dateSurvey}',
'{$plantName}',
'{$plantLoc}',
'{$plantContact}',
'{$direction}',
'{$location}',
'{$flrLevel}',
'{$elevation}',
'{$tagNum}',
'{$mmn}',
'{$size}',
'{$pressure}',
'{$service}',
'{$trapond}',
NOW()
)";
mysql_query($sql, $sql_connection);
mysql_close($sql_connection);
?>
Try to change the mysql_query to show errors meaningfully:
mysql_query($sql, $sql_connection) or die(mysql_error() . "<br/>Query was: " . $sql);
If you have an error, it will stop execution and you will see both the error and the query that was attempted to be executed.
I'm not sure what version of PHP you are running, but mysql_query and other related commands have been deprecated since PHP-5.5.0. http://php.net/manual/en/function.mysql-query.php
Try using the newer mysqli_query (you will need to update all of your sql commands like mysqli_connect and mysqli_close to match).
http://php.net/manual/en/mysqli.query.php

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

Value from drop down list html

Trying to pass the value from Drop down list through but couldnt get it.
<tr>
<td>Size <br>
(Only applicable for T-Shirt):</td>
<td><select name=size>
<option value=N>NIL</option>
<option value=S>S</option>
<option value=M>M</option>
<option value=L>L</option>
<option value=XL>XL</option>
</select></td>
</tr>
<tr>
<td></td>
<td><a href= manageProduct.php?size=$_GET[size]>Insert</a></td>
</tr>
Give this a try: (just an example).
<form action="<?php $_SERVER['PHP_SELF']?>" method="GET">
<table>
<tr>
<td nowrap>Size:
(Only applicable for T-Shirt):</td>
<td><select name="size">
<option value="N">NIL</option>
<option value="S">S</option>
<option value="M">M</option>
<option value="L">L</option>
<option value="XL">XL</option>
</select></td>
</tr>
<tr>
<td><p align="right"></p></td>
<td><input type="submit" value="Insert" />
</td>
</tr>
</table>
</form>
<?php
$size = $_GET['size'];
if($_GET['size']=="N")
{
echo "you chose NOTHING, make another choice.";
}
else {
echo "Your choice of size is: $size";
}
?>
Html
<form action="manageProduct.php" method="POST">
<table>
<tr>
<td>Size <br>
(Only applicable for T-Shirt):</td>
<td><select name=size>
<option value=N>NIL</option>
<option value=S>S</option>
<option value=M>M</option>
<option value=L>L</option>
<option value=XL>XL</option>
</select></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Insert" /></td>
</tr>
</table>
</form>
PHP
$size = $_POST['size'];
You need a form using the GET action then you can get your variable.
Assuming this page is the manageProduct.php:
<!--GET your data from the submitted form OR do something depending on what size returns in the url-->
<?php
if($_GET['size']=="SIZE"){ echo whatever or do whatever}
?>
<td>Whatever you're trying to do</td>
<form id="form" method="get" action="manageProduct.php">
<tr>
<td>Size <br>
(Only applicable for T-Shirt):</td>
<td><select name="size">
<option value="N">NIL</option>
<option value="S">S</option>
<option value="M">M</option>
<option value="L">L</option>
<option value="XL">XL</option>
</select></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="Submit" value="Insert" /></td>
<br />
</form>
</tr>

Categories