I have a form in php to select 3 choices , when i select all three no error is shown, but when i select two choices it shows error but choice is saved in data base, and shows record saved, but also show Notice: Undefined index: hb3 in C:\wamp\www\uni1\admin\courses.php on line 14
07/25/2014
<?php
include('auth.php');
include('conect.php'); $msg='';
if(isset($_POST['save']))
{
$category = $_POST['category'];
$cname = $_POST['cname'];
$code = $_POST['code'];
$type = $_POST['type'];
$dur = $_POST['dur'];
$fee = $_POST['fee'];
$hb1 = $_POST['hb1'];
$hb2 = $_POST['hb2'];
$hb3 = $_POST['hb3'];
$catid =mysql_insert_id();
$sql = mysql_query("select * from category where catid='$category'");// to get category code from category table
$rs = mysql_fetch_array($sql);
mysql_query("INSERT INTO courses1 (catid,cname, code, type, dur, fee, hb1, hb2, hb3)
VALUES ('$category','$cname','$code','$type','$dur','$fee','$hb1','$hb2','$hb3')");
$msg = '<h3>Record Saved</h3>';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>courses</title>
<link rel="stylesheet" type="text/css" href="headerstyle.css" />
</head>
<body>
07/25/2014
<div class="fixx"><?php include('header.php');?></div>
<div class="tabl">
<table width="700" border="0">
<tr>
<td>
<form method="post" action="courses.php">
<table width="700" border="1" cellpadding="10">
<tr>
<td colspan="2"><h3> ADD COURSES | EDIT </h3></td>
</tr>
<tr>
<td colspan="2"><?php echo $msg;?></td>
</tr>
<tr>
<td width="174"><h4>Select Category </h4></td>
<td width="674"><label for="category"></label>
<select name="category" id="category">
<?php $qre = mysql_query("select * from category ORDER BY name");
while($res = mysql_fetch_array($qre))
{
echo '<option value="'.$res['catid'].'">'.$res['name'].'</option>';
}
?>
</select> </td>
</tr>
<tr>
<td width="174"><h4>Enter Course Name</h4></td>
<td width="674"><label for="cname"></label>
<input name="cname" type="text" id="cname" size="70" /></td>
</tr>
<tr>
<td><h4>Course Code</h4></td>
<td><input type="text" name="code" id="code" /></td>
</tr>
<tr>
<td><h4>Type</h4></td>
<td><label for="type"></label>
<select name="type" id="type">
<option value="Month"><h4>Month</h4></option>
<option value="Semester"><h4>Semester</h4></option>
<option value="Year"><h4>Year</h4></option>
</select></td>
</tr>
<tr>
<td><h4>Duration</h4></td>
<td><p>
<select name="dur" id="dur">
<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>
</select>
</p></td>
</tr>
<tr>
<td><h4>Fee</h4></td>
<td><input type="text" name="fee" id="fee" /></td>
</tr>
<tr>
<td><h4>Mode</h4></td>
<td><h4>Online
<input type="checkbox" name="hb1" id="hb1" value="online" /></h4><br />
<h4>Private
<input type="checkbox" name="hb2" id="hb2" value="private" /></h4>
<br />
<h4>Regular
<input type="checkbox" name="hb3" id="hb3" value="regular" />
</h4> <br />
</label></td>
</tr>
<tr>
<td><input type="submit" name="save" id="save" value="Submit" /></td>
</tr></h2>
</table>
</form>
</td>
</tr>
</table>
</div>
</body>
</html>
Please solve my problem
There is error because when you are selecting only two choices then third choice has null means no value
$hb3 has no value for choice
you should check is value set or not if not then assign some default values
$hb1 = isset($_POST['hb1'])?$_POST['hb1']:'';
$hb2 = isset($_POST['hb2'])?$_POST['hb2']:'';
$hb3 = isset($_POST['hb3'])?$_POST['hb3']:'';
You should do like that if don't want notice "Undefined index"
$hb1 = isset($_POST['hb1'])?$_POST['hb1']:'';
$hb2 = isset($_POST['hb2'])?$_POST['hb2']:'';
$hb3 = isset($_POST['hb3'])?$_POST['hb3']:'';
use hidden filed
<input type="hidden" id="hb1_" name="hb1" value="-1">
<input type="checkbox" id="hb1" name="hb1" value="online" />
<input type="hidden" id="hb2_" name="hb2" value="-1">
<input type="checkbox" id="hb2" name="hb2" value="private" />
<input type="hidden" id="hb3_" name="hb3" value="-1">
<input type="checkbox" id="hb3" name="hb3" value="regular" />
When checkox in not checked, then $_POST doesn't contain given key, so you cannot assign its value. Whenever you use checkbox, assign given post value like this:
$hb3 = isset($_POST['hb3'])?$_POST['hb3']:'';
then in case of undefined value you will assign an empty string and you will not see those notices.
Related
Hey guys I'm just practising inserting data into my database for the first time and i've got a few issues with my code.
So what my code does is that it takes information from a form and simply inserts it into the database I have connected to. I'm getting 2 types errors, one is an undefined index at my POSTS and I'm also getting a SQL syntax error. I've tried looking around with no such luck in helping me fix the problem.
(yea I forgot to add the messages when I posted) Edit:
Undefined index: customerid on line 57
Problem with queryYou have an error in your SQL syntax; '', '', '', '', '', '')' at line 2
Any advice would be helpful:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Form</title>
</head>
<body>
<h1>Customer Information Collection <br /></h1>
<form method="post" action="task12.php" id="custinfo" >
<table>
<tr>
<td><label for="customerid">Customer ID (integer value): </label></td>
<td><input type="text" id="customerid" name="customerid" size=11/></td>
</tr>
<tr>
<td><label for="customerfname">Customer First Name: </label></td>
<td><input type="text" id="customerfname" name="customerfname" size=50/></td>
</tr>
<tr>
<td><label for="customerlname">Customer Last Name: </label></td>
<td><input type="text" id="customerlname" name="customerlname" size=50/></td>
</tr>
<tr>
<td><label for="customeraddress">Customer Address: </label></td>
<td><input type="text" id="customeraddress" name="customeraddress" size=65/></td>
</tr>
<tr>
<td><label for="suburb"> Suburb: </label></td>
<td><input type="text" id="suburb" name="suburb"/></td>
</tr>
<tr>
<td> State: </td>
<td> <select name="state" id="state">
<option value="--">--</option>
<option value="ACT">ACT</option>
<option value="NSW">NSW</option>
<option value="NT">NT</option>
<option value="QLD">QLD</option>
<option value="SA">SA</option>
<option value="TAS">TAS</option>
<option value="VIC">VIC</option>
<option value="WA">WA</option>
</select>
</td>
</tr>
<tr>
<td><label for="postcode"> Post Code (default "2000"): </label></td>
<td><input type="text" id="postcode" name="postcode" value="2000" size=4/></td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Submit"/> </td>
<td> <input type="reset" value="Clear" /> </td>
</tr>
</table>
</form>
<?php
$customeridstr = $_POST['customerid'];
$customerfnamestr = $_POST['customerfname'];
$customerlnamestr = $_POST['customerlname'];
$customeraddressstr = $_POST['customeraddress'];
$suburbstr = $_POST['suburb'];
$statestr = $_POST['state'];
$postcodestr = $_POST['postcode'];
?>
<?php
$conn = mysql_connect("xxxxx", "xxxxx", "xxxxxx");
mysql_select_db("xxxxxxx", $conn)
or die ('Database not found ' . mysql_error() );
$sql = "INSERT INTO Customer (customerID, firstName, lastName, Address, suburb, state, postcode)
VALUES ( '$customeridstr', '$customerfnamestr’, '$customerlnamestr', '$customeraddressstr', '$suburbstr', '$statestr', '$postcodestr');";
$rs = mysql_query($sql, $conn)
or die ('Problem with query' . mysql_error());
?>
</body>
</html>
<?php
if(isset($_POST['customerid'])){
$customeridstr = $_POST['customerid'];
$customerfnamestr = $_POST['customerfname'];
$customerlnamestr = $_POST['customerlname'];
$customeraddressstr = $_POST['customeraddress'];
$suburbstr = $_POST['suburb'];
$statestr = $_POST['state'];
$postcodestr = $_POST['postcode'];
$conn = mysql_connect("xxxxx", "xxxxx", "xxxxxx");
mysql_select_db("xxxxxxx", $conn) or die ('Database not found ' . mysql_error() );
$sql = "INSERT INTO Customer (customerID, firstName, lastName, Address, suburb, state, postcode) VALUES ( '{$customeridstr}', '{$customerfnamestr}’, '{$customerlnamestr}', '{$customeraddressstr}', '{$suburbstr}', '{$statestr}', '{$postcodestr}');";
$rs = mysql_query($sql, $conn);
if($rs){
echo 'Records Inserted';
}else{
die ('Problem with query' . mysql_error());
}
}else{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Form</title>
</head>
<body>
<h1>Customer Information Collection <br /></h1>
<form method="post" action="" id="custinfo" >
<table>
<tr>
<td><label for="customerid">Customer ID (integer value): </label></td>
<td><input type="text" id="customerid" name="customerid" size=11/></td>
</tr>
<tr>
<td><label for="customerfname">Customer First Name: </label></td>
<td><input type="text" id="customerfname" name="customerfname" size=50/></td>
</tr>
<tr>
<td><label for="customerlname">Customer Last Name: </label></td>
<td><input type="text" id="customerlname" name="customerlname" size=50/></td>
</tr>
<tr>
<td><label for="customeraddress">Customer Address: </label></td>
<td><input type="text" id="customeraddress" name="customeraddress" size=65/></td>
</tr>
<tr>
<td><label for="suburb"> Suburb: </label></td>
<td><input type="text" id="suburb" name="suburb"/></td>
</tr>
<tr>
<td> State: </td>
<td> <select name="state" id="state">
<option value="--">--</option>
<option value="ACT">ACT</option>
<option value="NSW">NSW</option>
<option value="NT">NT</option>
<option value="QLD">QLD</option>
<option value="SA">SA</option>
<option value="TAS">TAS</option>
<option value="VIC">VIC</option>
<option value="WA">WA</option>
</select>
</td>
</tr>
<tr>
<td><label for="postcode"> Post Code (default "2000"): </label></td>
<td><input type="text" id="postcode" name="postcode" value="2000" size=4/></td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Submit"/> </td>
<td> <input type="reset" value="Clear" /> </td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
?>
For now, try the above solution, this should work.
For further learning try these things:
Using mysqli instead my mysql library, it is deprecated now. try sanitizing the data (data you are getting from $_POST or $_GET).
Set a separate file for database connection and include it where it is needed but only one time in one php script/page.
Its also not a good practice to post the values on the same page, post it on some other page which is just dealing with the submitted data.
Also we just check one variable that is it set or not, and also that doesn't verifies that is it empty or not, so try checking every required variable and condition you want to check.
Cheers :)
i've searched and searched and maybe i found actually the right post but nothing worked for me so sorry for any duplication but maybe someone can help me out.
I have a php that gets me a form with multiple rows (based on an form input before).
Here's the php that creates the input table:
<html>
<head></head>
<body>
New report with EEM Number:<input type="text" name="eemnumber" />
<tr>
<td>Expense Date</td>
<td>Category</td>
<td>Vendor</td>
<td>Receipt Amount</td>
<td>Currency</td>
<td>Payment Amount</td>
<td>Currency</td>
<td>Payment Type</td>
<td>Country</td>
</tr>
<?php
$rows = $_POST['rows'];
$n = 0;
while($n < $rows)
{
$n++;
?>
<tr>
<td><input type="date" name="expensedate"/><br /></td>
<td><select name="category">
<option value="AirFare">AirFare</option> />
<option value="AutoRental">Auto Rental - Employee</option> />
<option value="DailyAllowance">Daily Allowance Standard</option> />
<option value="Gasoline">Gasoline - Auto Rental</option> />
<option value="Lodging">Lodging (Hotel) - Room / Tax</option> />
<option value="Meals">Meals / Entertain - HP only, Travel</option> />
<option value="Misc">Miscellaneous</option> />
<option value="Taxi">Taxi / Subway / Bus / Train</option> />
<br/>
</td>
<td><input type="text" name="vendor"/><br /></td>
<td><input type="text" name="receiptamount"/>
</td>
<td><select name="currrec">
<option value="EUR">EUR</option> />
<option value="SEK">SEK</option> />
<option value="USD">USD</option> />
</td>
<td><input type="text" name="paymentamount"/>
</td>
<td><select name="currpay">
<option value="EUR">EUR</option> />
<option value="SEK">SEK</option> />
<option value="USD">USD</option> />
</td>
<td><select name="paytype">
<option value="cash">Cash</option> />
<option value="cc">Credit Card</option> />
<br/>
</td>
<td><select name="country">
<option value="DE">Germany</option> />
<option value="SE">Sweden</option> />
<option value="US">USA</option> />
<br/>
</td>
</tr>
<?PHP
}
?>
</table>
</div>
<p>
<input type="submit"/>
</form>
<!-- End of FORM -->
Back
</body>
</html>
So once all data was entered I click on Submit and would of course like to get every line into my DB. Here's the script i tried do use but only gets me the last...
<?php
$con=mysqli_connect("localhost","user","pass","db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$eemnumber=$_POST['expensedate'];
$expensedate=$_POST['expensedate'];
$category=$_POST['category'];
$vendor=$_POST['vendor'];
$receiptamount=$_POST['receiptamount'];
$currrec=$_POST['currrec'];
$paymentamount=$_POST['paymentamount'];
$currpay=$_POST['currpay'];
$paytype=$_POST['paytype'];
$eemnumber=$_POST['eemnumber'];
$country=$_POST['country'];
$sql="INSERT INTO tbl_eem_data
(ExpenseDate, Category, Vendor, ReceiptAmount, CurrRec, PaymentAmount, CurrPay, PayType, EEMNumber, Country)
VALUES
$expensedate,
$category,
$vendor,
$receiptamount,
$currrec,
$paymentamount,
$currpay,
$paytype,
$eemnumber,
$country)";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
mysqli_close($con);
header("location:index.php");
?>
Anyone any clue?
Thanks!!!
You need to change form Structure and form Fields
<?php
$rows = $_POST['rows'];
$n = 0;
while($n < $rows)
{
$n++;
?>
<tr>
<td><input type="date" name="expensedate[<?echo $n?>]"/><br /></td>
<td><select name="category">
<option value="AirFare">AirFare</option> />
<option value="AutoRental">Auto Rental - Employee</option> />
<option value="DailyAllowance">Daily Allowance Standard</option> />
<option value="Gasoline">Gasoline - Auto Rental</option> />
<option value="Lodging">Lodging (Hotel) - Room / Tax</option> />
<option value="Meals">Meals / Entertain - HP only, Travel</option> />
<option value="Misc">Miscellaneous</option> />
<option value="Taxi">Taxi / Subway / Bus / Train</option> />
<br/>
</td>
<td><input type="text" name="vendor[<?echo $n?>]"/><br /></td>
<td><input type="text" name="receiptamount[<?echo $n?>]"/>
</td>
<td><select name="currrec">
<option value="EUR">EUR</option> />
<option value="SEK">SEK</option> />
<option value="USD">USD</option> />
</td>
<td><input type="text" name="paymentamount[<?echo $n?>]"/>
</td>
<td><select name="currpay[<?echo $n?>]">
<option value="EUR">EUR</option> />
<option value="SEK">SEK</option> />
<option value="USD">USD</option> />
</td>
<td><select name="paytype[<?echo $n?>]">
<option value="cash">Cash</option> />
<option value="cc">Credit Card</option> />
<br/>
</td>
<td><select name="country[<?echo $n?>]">
<option value="DE">Germany</option> />
<option value="SE">Sweden</option> />
<option value="US">USA</option> />
<br/>
</td>
</tr>
<?PHP
}
?>
<input type="hidden" name="rows" value="<?echo $n?>" />
Then apply similar loop to fetch those values.
You also need to have hidden variable which stores total number of rows you have.
Thanks
You seem to be missing an open parenthesis ( in your SQL right after VALUES.
Fix it and hopefully it will work: VALUES ( . . . )
Basically, run this test:
HTML:
<input type="text" name="key" value="1" />
<input type="text" name="key" value="2" />
PHP:
<?
print_r($_POST);
?>
And then run this:
HTML:
<input type="text" name="key[]" value="1" />
<input type="text" name="key[]" value="2" />
PHP:
<?
print_r($_POST);
?>
See if you can make any conclusions with this, and let me know what you think.
You are generating form fields based on the number of $rows received from the Request.
<form ... <!- this line was missing in your code -->
$rows = $_POST['rows'];
while($n < $rows)
...
</form>
And after submit, you are not reading parameters into arrays.
$eemnumber=$_POST['expensedate']; /* this is wrong again */
$expensedate=$_POST['expensedate'];
$category=$_POST['category'];
$vendor=$_POST['vendor'];
Which lead the last value from the submitted array values assigned to the variable in concern.
And hence you see that only last row read and pushed into DB.
Change your code accordingly and it should be working.
Refer to:
PHP: Reading POST data with arrays
My Selectbox Items from aircraft table
<select name="selectaircraft">
<option id="0">-- Select Aircraft -- </option>
<?php
require("dbc.php");
$getallaircraft = mysql_query("SELECT * FROM aircrafttable");
while($viewallaircraft = mysql_fetch_array($getallaircraft)){
?>
<option id="<?php echo $viewallaircraft['ID']; ?>">
<?php echo $viewallaircraft['aircraft'] ?> </option>
<?php } ?>
</select>
hi guys im trying to use the the value of selectaircraft to search and display the result to textbox.. here is my code so far
<?php
require("dbc.php");
$getallconfig = mysql_query("SELECT * FROM aircrafttable WHERE aircraft LIKE 'PR200'");
while($viewallconfig= mysql_fetch_array($getallconfig)){
?>
<input type="text" name="aconfig "value="<?php echo $viewallconfig['config']; ?>" />
<?php } ?>
As you can see, I only put PR200 to search, my question is how can i use the select value instead? I also want the search query to happen everytime i click the select box.
guys can some1 help me? i know how to code this in VB6 it will be like this
assume : select name or in VB6 combobox = selectbox
Private Sub Combo3_Click()
adodc1.recorsource ="Select * from aircrafttable where aircraft = " & selectbox & "'"
adodc1.refresh
Text1.Text = Adodc1.Recordset("aircraft")
everytime i click combo/selectbox the query will perform and give different answer to textbox.
i dont know how to do this in PHP pls help!
Edited Added all codes
<form action="addrecord.php" method="post" >
<table border=1>
<tr><td bgcolor="#999999">
<strong>Area:</strong> </td>
<td>
<input type="text" required="required" name="aarea" size=10 /><br /></td></tr>
<tr><td bgcolor="#999999">
<strong>Aircraft:</strong></td>
<td>
<form method="post" action="aircraft.php">
<select name="selectaircraft" onchange="this.form.submit();">
<option id="0">Aircraft</option>
<?php
require("dbc.php");
$getallaircraft = mysql_query("SELECT * FROM aircrafttable");
while($viewallaircraft = mysql_fetch_array($getallaircraft)){
?>
<option id="<?php echo $viewallaircraft['ID']; ?>">
<?php
echo $viewallaircraft['aircraft'] ?> </option>
<?php } ?>
</select>
<?php
require("dbc.php");
if(isset($_POST)){
$takeaircraft = mysql_real_escape_string($_POST['selectaircraft']);
{
?>
<input type="text" name="aaircraft" size=3 value="<?php echo $takeaircraft; ?>" />
<?php }
}?>
</form>
</td></tr>
<tr><td bgcolor="#999999">
<strong>Flight:</strong> </td>
<td><input type="text" name="aflight" size=10 /><br /></td></tr>
<tr><td bgcolor="#999999">
<strong>Configuration:</strong> </td>
<td>
<?php
require("dbc.php");
if(isset($_POST)){
$selectaircraft = mysql_real_escape_string($_POST['selectaircraft']);
$getallconfig = mysql_query("SELECT * FROM aircrafttable WHERE aircraft LIKE '".$selectaircraft."'");
while($viewallconfig= mysql_fetch_array($getallconfig)){
?>
<input type="text" name="aconfig" value="<?php echo $viewallconfig['config']; ?>" />
<?php }
}?>
<br /></td></tr>
<tr><td bgcolor="#999999">
<strong>Month:</strong> </td>
<td>
<select name="amonth">
<option value="na">Month</option>
<option value="January">January</option>
</select>
</td></tr>
<tr><td bgcolor="#999999">
<strong>Frequency:</strong> </td>
<td><span style="font-size:11px; font-weight:bolder" >
Mon<input type="checkbox" id='check1' onClick='checkmon()'>
<input type="hidden" id="txt1" name="hiddenmon" value="n/a">
Tue<input type="checkbox" id='check2' onClick='checktue()'>
<input type="hidden" id="txt2" name="hiddentue" value="n/a">
Wed<input type="checkbox" id='check3' onClick='checkwed()'>
<input type="hidden" id="txt3" name="hiddenwed" value="n/a">
Thu<input type="checkbox" id='check4' onClick='checkthu()'>
<input type="hidden" id="txt4" name="hiddenthu" value="n/a">
Fri<input type="checkbox" id='check5' onClick='checkfri()'>
<input type="hidden" id="txt5" name="hiddenfri" value="n/a">
Sat<input type="checkbox" id='check6' onClick='checksat()'>
<input type="hidden" id="txt6" name="hiddensat" value="n/a">
Sun<input type="checkbox" id='check7' onClick='checksun()'>
<input type="hidden" id="txt7" name="hiddensun" value="n/a">
</span>
<br /></td></tr>
<tr><td bgcolor="#999999">
<strong>Menu:</strong> </td>
<td><input type="text" name="amenu" size=10 /><br /></td></tr>
<tr><td bgcolor="#999999">
<strong>Cycle:</strong> </td>
<td>
<select name="acycle">
<option value="na">Cycle</option>
<option value="Cycle 1">Cycle 1</option>
</select>
<tr><td bgcolor="#999999">
<strong>Items:</strong> </td>
<td>
<select name="aitem">
<option value="na">Items</option>
</select>
<tr><td bgcolor="#999999">
<strong>STD Time:</strong> </td>
<td><input type="text" name="astdtime" size=5 /><br /></td></tr>
<tr><td bgcolor="#999999">
<strong>Quantity:</strong> </td>
<td><input type="text" name="aqty" size=5 /><br /></td></tr>
<tr>
<td colspan="2" align="right" bgcolor="#999999">
<input type='submit' name="add" value="Add Records" />
</td>
</tr>
</table>
</form>
trigger submit on change of select box as below
<form action="path/to/your/query/file.php" method="post"> //if query in same page leave your action blank
<select name="selectaircraft" onchange="this.form.submi();">
<option id="0">-- Select Aircraft -- </option>
<?php
require("dbc.php");
$selected_aircraft=isset($_POST['selectaircraft'])?$_POST['selectaircraft']:"";
$getallaircraft = mysql_query("SELECT * FROM aircrafttable");
while($viewallaircraft = mysql_fetch_array($getallaircraft)){
$selectstr="";
if($selected_aircraft==$viewallaircraft['aircraft'] ){
$selectstr="selected='selected'";
}
?>
<option id="<?php echo $viewallaircraft['ID']; ?>" <?php echo $selectstr ?> >
<?php
echo $viewallaircraft['aircraft'] ?> </option>
<?php } ?>
</select>
</form>
and change you query as below:
<?php
require("dbc.php");
if(isset($_POST)){
$selectaircraft = mysql_real_escape_string($_POST['selectaircraft']);
$getallconfig = mysql_query("SELECT * FROM aircrafttable WHERE aircraft LIKE '{ $selectaircraft}'");
while($viewallconfig= mysql_fetch_array($getallconfig)){
?>
<input type="text" name="aconfig "value="<?php echo $viewallconfig['config']; ?>" />
<?php }
}?>
Update updated code to maintain state of select box.
Try like this;
$aircraft = mysql_real_escape_string($_POST['selectaircraft']); //or $_GET
$getallconfig = mysql_query("SELECT * FROM aircrafttable WHERE aircraft LIKE '".$aircraft."'");
You can keep the select box(1st) inside a form , on change submit the form to the next page .
And get the POST/GET value , and use it for select query for searching.
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
I want to create a php variable depending on what was selected in a drop down.
This is the drop down:
<td width="5" rowspan="2"><select id="ddlTime">
<option selected="selected" value="perhour" name="perhour">per hour</option>
<option value="perannum" name="perannum">per annum</option>
</select></td>
Depending if "per hour" or "per annum" was selected, I want to do the following (I'm not quite sure syntax wise if this is correct and this part is on another page):
// if per hour is selected:
$result_pharmacist = $_POST["pharmacist"];
$result_dispenser = $_POST["dispenser"];
// if per annum is selected:
$user_pharmacist = $_POST["pharmacist"];
$result_pharmacist = $user_pharmacist/37.5/52;
$user_dispenser = $_POST["dispenser"];
$result_dispenser = $user_dispenser/37.5/52;
How can this be done?
Here's my full form:
<form action="<?php the_permalink(); ?>calculations" method="post">
<h2>Savings calculator</h2>
<div class="calculator-divide"></div>
<table border="0">
<tr>
<td colspan="3"><h3>Current service costs</h3></td>
</tr>
<tr>
<td width="440"><p>Pharmacist</p></td>
<td><p style="padding-left:5px!IMPORTANT;">£
<input style="width:145px!IMPORTANT;" value="22.00" type="text" name="pharmacist" />
</p></td>
<td width="5" rowspan="2"><select id="ddlTime">
<option selected="selected" value="perhour" name="perhour">per hour</option>
<option value="perannum" name="perannum">per annum</option>
</select></td>
</tr>
<tr>
<td><p>Dispenser / Technician</p></td>
<td><p style="padding-left:5px!IMPORTANT;">£
<input style="width:145px!IMPORTANT;" value="8.00" type="text" name="dispenser" />
</p></td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="3"><h3>Time taken to carry out manual dispensing tasks</h3></td>
</tr>
<tr>
<td><p>Measure 50mls dose by hand including Pharmacist check</p></td>
<td colspan="2"><p style="padding-left:5px!IMPORTANT;">
<input value="1" type="text" name="measure-check" />
Minute(s)</p></td>
</tr>
<tr>
<td><p>Preparing labels from dispensary system</p></td>
<td colspan="2"><p style="padding-left:5px!IMPORTANT;">
<input value="0.5" type="text" name="labels" />
Minute(s)</p></td>
</tr>
<tr>
<td><p>Write up CD register</p></td>
<td colspan="2"><p style="padding-left:5px!IMPORTANT;">
<input value="2" type="text" name="cd-register" />
Minute(s)</p></td>
</tr>
<tr>
<td></td>
<td colspan="3"><div class="estimate">
<input style="margin-bottom:20px;" type="submit" value="Estimate my savings" />
</div></td>
</tr>
</table>
</form>
<select id="ddlTime" name="ddlTime">
and
if( $_POST['ddlTime']=='perhour' ){
// if per hour is selected:
$result_pharmacist = $_POST["pharmacist"];
$result_dispenser = $_POST["dispenser"];
}elseif( $_POST['ddlTime']=='perannum' ){
// if per annum is selected:
$user_pharmacist = $_POST["pharmacist"];
$result_pharmacist = $user_pharmacist/37.5/52;
$user_dispenser = $_POST["dispenser"];
$result_dispenser = $user_dispenser/37.5/52;
}
I hope this help you :
<?php
if(isset ($_POST['save']))
{
$temp = $_POST['opsi'];
echo $temp;
}
?>
<html>
<body>
<form action="newEmptyPHP.php" method="POST">
<h3> Choose Your Option</h3>
<select name="opsi">
<option value=0 selected>- Customer -</option>
<option value="perannum" name="perannum">perannum</option>
<option value="perhour" name="perhour">perhour</option>
</select> <br> <br>
<input type="submit" name="save" value="Save and Commit">
</form>
</body>
</html>