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>
Related
When I submit an SQL query there is no record created in the database, but also no error message is displayed.
** Sorry for long code because I don't know where is the problem with the code and I also just have basic knowledge in programming.
I am using 2 different tables for query and insert:
<?php
if(isset($send))
{
$today=date('Y-m-d');
$fname=isset ($_POST['fname']) ? $_POST['fname'] : '';
$fname=mysqli_real_escape_string($con, $fname);
$sql=mysqli_query("SELECT * FROM kc54i_workforce_employees WHERE fname='$fname'");
$row=mysqli_fetch_array($sql);
$namestaff=$row['lname'];
$sql2 = "
INSERT INTO `avenue`.`staff_movement` (`id`, `staff_no`, `department`, `name`, `status`, `category`, `dateStart`, `dateEng`)
VALUES (NULL, '$fname','$department','$namestaff','$status','$category','$dateStart','$dateEnd');";
if(#mysqli_query($con, $sql2))
{
echo "<script type='text/javascript'>\n";
echo "alert('New record created successfully');\n";
echo "window.navigate('add_move_test.php');";
echo "</script>";
}
else
echo "Error: " . $sql2 . "<br>" . mysqli_error();
}
else
?>
<html>
<body>
<form name="add_move_test.php" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return formCheck(this);">
<table>
<tr>
<tr>
<td valign="top">Department</td>
<td valign="top">
<select name="department" onchange='this.form.submit();'>
<?php $department=isset($_POST[ 'department']) ? $_POST[ 'department'] : '';
$department=mysqli_real_escape_string($con, $department); ?>
<option value="">-Select One-</option>
<option value="7" <?php if ($department=="7" ) echo "selected";?>>Management</option>
<option value="2" <?php if ($department=="2" ) echo "selected";?>>Administration</option>
<option value="5" <?php if ($department=="5" ) echo "selected";?>>Human Resource</option>
<option value="25" <?php if ($department=="25" ) echo "selected";?>>Business Development</option>
<option value="12" <?php if ($department=="12" ) echo "selected";?>>Finance</option>
<option value="19" <?php if ($department=="19" ) echo "selected";?>>Procurement</option>
<option value="1" <?php if ($department=="1" ) echo "selected";?>>IT Support</option>
<option value="6" <?php if ($department=="6" ) echo "selected";?>>Project</option>
<option value="13" <?php if ($department=="13" ) echo "selected";?>>Project(Control)</option>
<option value="10" <?php if ($department=="10" ) echo "selected";?>>Project(Management)</option>
<option value="8" <?php if ($department=="8" ) echo "selected";?>>Project(Transportation)</option>
<option value="24" <?php if ($department=="24" ) echo "selected";?>>Construction</option>
<option value="16" <?php if ($department=="16" ) echo "selected";?>>Construction(Management)</option>
<option value="4" <?php if ($department=="4" ) echo "selected";?>>Construction(Planning & Cost Estimation)</option>
<option value="18" <?php if ($department=="18" ) echo "selected";?>>Engineering</option>
<option value="15" <?php if ($department=="15" ) echo "selected";?>>Engineering(Civil)</option>
<option value="14" <?php if ($department=="14" ) echo "selected";?>>Engineering(Fire & Gas)</option>
<option value="23" <?php if ($department=="23" ) echo "selected";?>>Engineering(Electrical)</option>
<option value="22" <?php if ($department=="22" ) echo "selected";?>>Engineering(Instrument)</option>
<option value="3" <?php if ($department=="3" ) echo "selected";?>>Engineering(Mechanical)</option>
<option value="9" <?php if ($department=="9" ) echo "selected";?>>Engineering(Layout & Piping)</option>
<option value="20" <?php if ($department=="20" ) echo "selected";?>>Engineering(Process)</option>
<option value="17" <?php if ($department=="17" ) echo "selected";?>>HSSE</option>
<option value="11" <?php if ($department=="11" ) echo "selected";?>>Quality(QA/QC)</option>
</select>
</td>
</tr>
<tr>
<td valign="top">Name</td>
<td valign="top">
<select name="fname">
<option selected>-Select Name-</option>
<?php $sql="select * from kc54i_workforce_employees where department='$department' ORDER BY lname ASC" ;
$results=mysqli_query($con, $sql);
while ($row=mysqli_fetch_array($results)) { $department=$row[ 'department'];
$name=$row[ 'lname']; $fname=$row['fname']; ?>
<option value="<?php echo $fname;?>">
<?php echo $name;?>
</option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td valign="top">Category</td>
<td valign="top">
<select name="category">
<?php $category=i sset($_POST[ 'category']) ? $_POST[ 'category'] : ''; $category=mysqli_real_escape_string($con, $category); ?>
<option value="">-Select One-</option>
<option value="office" <?php if ($category=="office" ) echo "selected";?>>Office</option>
<option value="site" <?php if ($category=="site" ) echo "selected";?>>Site</option>
</select>
</td>
</tr>
<tr>
<td valign="top">Date Start</td>
<td valign="top">
<script>
DateInput('dateStart', true)
</script>
</td>
</tr>
<tr>
<td valign="top">Date End</td>
<td valign="top">
<script>
DateInput('dateEnd', true)
</script>
</td>
</tr>
<tr>
<td valign="top">Status</td>
<td valign="top">
<input name="status" type="text" id="status" size="50" maxlength="50">
</td>
</tr>
<tr align="center" valign="middle">
<td colspan="2">
<input name="send" type="submit" id="send" value="Send">
<input name="clear" type="reset" id="clear" value="Clear">
<input type="button" name="back" value="Back" onClick="javascript:history.back();">
</td>
</tr>
</table>
</form>
</body>
</html>
There is space in between isset function all things are already there,I just run it because I don't have table structure of yours,
<html>
<body>
<form name="add_move_test.php" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return formCheck(this);">
<table>
<tr>
<tr>
<td valign="top">Department</td>
<td valign="top">
<select name="department" onchange='this.form.submit();'>
<?php
$department=isset($_POST[ 'department']) ? $_POST[ 'department'] : '';
$department=mysqli_real_escape_string($con, $department); ?>
<option value="">-Select One-</option>
<option value="7" <?php if ($department=="7" ) echo "selected";?>>Management</option>
<option value="2" <?php if ($department=="2" ) echo "selected";?>>Administration</option>
<option value="5" <?php if ($department=="5" ) echo "selected";?>>Human Resource</option>
<option value="25" <?php if ($department=="25" ) echo "selected";?>>Business Development</option>
<option value="12" <?php if ($department=="12" ) echo "selected";?>>Finance</option>
<option value="19" <?php if ($department=="19" ) echo "selected";?>>Procurement</option>
<option value="1" <?php if ($department=="1" ) echo "selected";?>>IT Support</option>
<option value="6" <?php if ($department=="6" ) echo "selected";?>>Project</option>
<option value="13" <?php if ($department=="13" ) echo "selected";?>>Project(Control)</option>
<option value="10" <?php if ($department=="10" ) echo "selected";?>>Project(Management)</option>
<option value="8" <?php if ($department=="8" ) echo "selected";?>>Project(Transportation)</option>
<option value="24" <?php if ($department=="24" ) echo "selected";?>>Construction</option>
<option value="16" <?php if ($department=="16" ) echo "selected";?>>Construction(Management)</option>
<option value="4" <?php if ($department=="4" ) echo "selected";?>>Construction(Planning & Cost Estimation)</option>
<option value="18" <?php if ($department=="18" ) echo "selected";?>>Engineering</option>
<option value="15" <?php if ($department=="15" ) echo "selected";?>>Engineering(Civil)</option>
<option value="14" <?php if ($department=="14" ) echo "selected";?>>Engineering(Fire & Gas)</option>
<option value="23" <?php if ($department=="23" ) echo "selected";?>>Engineering(Electrical)</option>
<option value="22" <?php if ($department=="22" ) echo "selected";?>>Engineering(Instrument)</option>
<option value="3" <?php if ($department=="3" ) echo "selected";?>>Engineering(Mechanical)</option>
<option value="9" <?php if ($department=="9" ) echo "selected";?>>Engineering(Layout & Piping)</option>
<option value="20" <?php if ($department=="20" ) echo "selected";?>>Engineering(Process)</option>
<option value="17" <?php if ($department=="17" ) echo "selected";?>>HSSE</option>
<option value="11" <?php if ($department=="11" ) echo "selected";?>>Quality(QA/QC)</option>
</select>
</td>
</tr>
<tr>
<td valign="top">Name</td>
<td valign="top">
<select name="fname">
<option selected>-Select Name-</option>
<?php $sql="select * from kc54i_workforce_employees where department='$department' ORDER BY lname ASC" ;
$results=mysqli_query($con, $sql);
while ($row=mysqli_fetch_array($results)) {
$department=$row[ 'department'];
$name=$row[ 'lname']; $fname=$row['fname']; ?>
<option value="<?php echo $fname;?>">
<?php echo $name;?>
</option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td valign="top">Category</td>
<td valign="top">
<select name="category">
<?php $category=isset($_POST[ 'category']) ? $_POST[ 'category'] : ''; $category=mysqli_real_escape_string($con, $category); ?>
<option value="">-Select One-</option>
<option value="office" <?php if ($category=="office" ) echo "selected";?>>Office</option>
<option value="site" <?php if ($category=="site" ) echo "selected";?>>Site</option>
</select>
</td>
</tr>
<tr>
<td valign="top">Date Start</td>
<td valign="top">
<script>
DateInput('dateStart', true)
</script>
</td>
</tr>
<tr>
<td valign="top">Date End</td>
<td valign="top">
<script>
DateInput('dateEnd', true)
</script>
</td>
</tr>
<tr>
<td valign="top">Status</td>
<td valign="top">
<input name="status" type="text" id="status" size="50" maxlength="50">
</td>
</tr>
<tr align="center" valign="middle">
<td colspan="2">
<input name="send" type="submit" id="send" value="Send">
<input name="clear" type="reset" id="clear" value="Clear">
<input type="button" name="back" value="Back" onClick="javascript:history.back();">
</td>
</tr>
</table>
</form>
</body>
</html>
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.
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);
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>
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