I am using this code to serach database and I am using 4 fields in this code but this code does not serach database value.
where problem in this code tell me plz edit my code for full working serach with 4 fields
my code :
<?php
{
include ('connection.php');
if(isset($_REQUEST['submit'])){
$optid = $_POST['OPRID'];
$optdec = $_POST['OPRDEFNDESC'];
$empid = $_POST['EMPLID'];
$empmail = $_POST['EMAILID'];
$query ="SELECT * FROM OPERATOR WHERE OPRID LIKE '%".$optid."%'
or OPRDEFNDESC LIKE '%".$optdec."%' or EMPLID LIKE '%".$empid."%'
or EMAILID LIKE '%".$empmail."%' ";
}
else{
$query="SELECT * FROM OPERATOR";
$objParse = oci_parse ($ora_conn, $query);
}
?>
<form action="multi.php" method="get" action="<?=$_SERVER['SCRIPT_NAME'];?>">
<table width="500" border="1" align="center">
<tr>
<th>Operator ID
<input name="OPRID" type="text" id="OPRID" value="";>
<tr>
<th>Operator Name
<input name="OPRDEFNDESC" type="text" id="OPRDEFNDESC" value="";>
<tr>
<th>Person ID
<input name="EMPLID" type="text" id="EMPLID" value="";>
<tr>
<th>Email ID
<input name="EMAILID" type="text" id="EMAILID" value="";>
<input type="submit" value="Search"></th>
</tr>
</table>
</form>
<table>
<tr>
<td>Operator ID</td>
<td>Operator Name</td>
<td>Person ID</td>
<td>Email ID</td>
</tr>
<?
$success = oci_execute($objParse);
//while($objResult = oci_fetch_array($objParse,OCI_BOTH))
while($objResult = oci_fetch_array($objParse, OCI_RETURN_NULLS+OCI_ASSOC))
{
?>
<tr>
<td><div align="center"><?=$objResult["OPRID"];?></div></td>
<td><?=$objResult["OPRDEFNDESC"];?></td>
<td><?=$objResult["EMPLID"];?></td>
<td><div align="center"><?=$objResult["EMAILID"];?></div></td>
<td align="center"><a href="Optr_Edit.php?OprID=
<?=$objResult["OPRID"];?>">Edit</a></td>
</tr>
<?
}
?>
</table>
<?
oci_free_statement($objParse);
oci_close($ora_conn);
}
?>
Try like this
<tr>
<td><div align="right"><strong>Password Encrypted:</strong></div></td>
<td>
<select name="txtENCRYPTED">
<option value="">Select</option>
<option <?php if ($objResult["ENCRYPTED"] == "Y") {echo 'selected';} ?>value="Y">Y</option>
<option <?php if ($objResult["ENCRYPTED"] == "N") {echo 'selected';} ?> value="N">N</option>
</select>
</td>
</tr>
You are doing it wrong
Select element do not have value attribute
You have value attribute only in options element.
For eg:
<select name="txtENCRYPTED" id="txtENCRYPTED">
<option value="">Select</option>
<option value="Y">Y</option>
<option value="N">N</option>
</select>
In your code you have provided the db-retrived-data in tags setting .
The tag defines the menu. It can have the following settings
The name setting adds an internal name to the field so the program that handles the form can identify the fields.
The size option defines how many items should be visible at a time. Default is one item.
The multiple setting will allow for multiple selections if present.
The tag defines the single items in the menu.
The value setting defines what will be submitted if the item is selected.
one solution :-
<form method="post" action="" >
<select name="encrypt" value="encrypted" id='select'>
<option value="">Select</option>
<option value="<?php if($objResult["ENCRYPTED"]=='Y'){ echo 'Y'; } ?>">Y</option>
<option value="<?php if($objResult["ENCRYPTED"]=='N'){ echo 'N'; } ?>">N</option>
</select>
<input type="submit" value="submit" id='form'/>
</form>
</td>
</tr>
//script type jquery.js
//script type javascript
$(document).ready(function(){
$('form').submit(function(){
alert($('#select').val());
});
});
</script>
Related
I have some combobox with onchange event, and they're reset each other when selected the orther one of them, does any suggest how to retain the value on the page? this my script :
<form method="POST" name="form1" action="<?php $_SERVER['PHP_SELF'];?>">
<table border="0">
<tr>
<td colspan="6"></td>
</tr>
<tr>
<td>
<select name="select_petugas1" style="width:18px;" onchange="this.form.submit('select_petugas1');"> //first combobox
<option></option>
<?php include 'dbconn.php';
$sql_peg1="SELECT * FROM users"; $result_peg1=$conn->query($sql_peg1);
while( $row_peg1=$result_peg1->fetch_assoc() ){
echo "<option>".$row_peg1['nama']."</option>";
}
?>
</select>
</td>
<td>
<?php
if(isset($_POST['select_petugas1'])){
$select_petugas1=$_POST['select_petugas1'];
echo "<input type='text' name='select_petugas1' value='".$select_petugas1."'>"; // Throw 1st result into the text box
$sql_NIP1="SELECT NIP FROM users WHERE nama='$select_petugas1'";
$result_NIP1=$conn->query($sql_NIP1);
$row_NIP1=$result_NIP1->fetch_assoc();
$NIP1=$row_NIP1['NIP'];
?>
</td>
<td> NIP</td>
<td>:</td>
<td><input type="text" name='NIP1' value="<?php echo $NIP1; ?>"></td>
</tr> <!-- child of first result -->
<tr>
<td colspan="5" bgcolor="blue"></td>
</tr>
<tr>
<td>
<select name="peg_2" style="width:18px;" onchange="submit(this)"><!--2nd combobox-->
<option></option>
<?php
$sql_peg2="SELECT nama FROM users";
$result_peg2=$conn->query( $sql_peg2 );
while ($row_peg2=$result_peg2->fetch_assoc()){
echo "<option value='".$row_peg2['nama']."'>".$row_peg2['nama']."</option>";
}
?>
</select>
</td>
<td>
<?php
if( isset($_POST['peg_2']) ){
$peg_2=$_POST['peg_2'];
echo "<input type='text' name='peg2' value='".$peg_2."'>"; // 2nd result throw into 2nd texbox
$sql_NIP2="SELECT NIP FROM users WHERE nama='$peg_2'";
$result_NIP2=$conn->query($sql_NIP2);
$row_NIP2=$result_NIP2->fetch_assoc();
?>
</td>
<td> NIP</td>
<td>:</td>
<td><input type='text' name='NIP2' value="<?php echo $row_NIP2['NIP'];?>"> <!--2nd child of result-->
<?php
}
}
if(isset($_POST['NIP2'])){
$NIP2=$_POST['NIP2'];
echo "<br /> NIP2 :".$NIP2."<br />";
}
mysqli_close($conn);
?>
</td>
</tr>
</table>
</form>
<form method="POST" name="wilayah" id="wilayah" action="<?php $_SERVER['PHP_SELF'];?>">
<table border="1">
<tr>
<td>
<select name="select_provinsi" onchange="submit(this)" style="width:18;">
<option selected>PROVINSI</option>
<?php
include 'dbconn.php';
$sql_prov="SELECT * FROM wilayah GROUP BY provinsi";
$result_prov=$conn->query($sql_prov);
echo "";
while($row_prov=$result_prov->fetch_assoc()){
$provinsi=$row_prov['provinsi'];
echo "<option value='".$provinsi."'>".$provinsi."</option>";
}
?>
</select>
<?php
if(isset($_POST['select_provinsi'])){
$select_provinsi=$_POST['select_provinsi'];
echo "
<input type='text' name='select_provinsi' value='".$select_provinsi."' placeholder='PROVINSI'>
</td>
</tr>";
$sql_kabkota="SELECT * FROM wilayah WHERE provinsi='$select_provinsi' GROUP BY kab_kota";
$result_kabkota=$conn->query($sql_kabkota);
?>
<tr>
<td>
<select name="select_kabkota" style="width:18px;" onchange="submit(this)"><option>KAB/KOTA</option>
<?php
while($row_kabkota=$result_kabkota->fetch_assoc()){
echo "<option>".$row_kabkota['kab_kota']."</option>";
}
?>
</select>
<?php
}
if(isset($_POST['select_kabkota'])){
$select_kabkota=$_POST['select_kabkota'];
?>
<input type="text" name="kab_kota" value="<?php echo $select_kabkota;?>">
<?php
}
mysqli_close($conn);
?>
</td>
</tr>
</table>
</form>
hope any suggestion for resolved of my problem with them,,
onchange="submit(this)" means that you want to submit the form when the value of the combobox changes. So, when the form is sent, the page reloads and you get the default value of your form.
To restore the chosen value, I would do something like :
<select name="select_kabkota" style="width:18px;" onchange="submit(this)">
<option>KAB/KOTA</option>
<?php
if(isset($_POST['select_kabkota']))
$select_kabkota=$_POST['select_kabkota'];
while($row_kabkota=$result_kabkota->fetch_assoc())
{
$selected = $select_kabkota == $row_kabkota['kab_kota'] ? 'selected="selected"' : '';
echo "<option ".$selected." >".$row_kabkota['kab_kota']."</option>";
}
?>
</select>
Im trying to display my database value into the textbox using drop down menu. which is i did and it is displaying. the problem here is that when i choose an item in the drop down list, it goes back to the first choice or last choice, the explanation i got was, my loop is selecting all of the items in the field causing the drop down menu to go back to the first choice when i click on other items. can you help me with the code on how to stop going back to the first choice when i select other options. Here is my whole code. i also use functions.
home.php
<?php
session_start();
include('dbconnect.php');
include('functions.php');
if(isset($_POST['brandname'])){
$id = $_POST['brandname'];
$result = mysql_query("SELECT * FROM tblstore WHERE brandname = '$id'");
while($row = mysql_fetch_array($result)){
$price = $row['price'];
$stocks = $row['stocks'];
}
}
?>
<html>
<body>
<form method="POST" name="">
<table align="center">
<tr>
<td>Choose here:</td>
<td>
<select name = "brandname" onchange = "this.form.submit()">
<?php dropdown() ?>
</select>
</td>
</tr>
<tr>
<td>Quantity:</td>
<td><input type="text" name="qty" id="qty" value="" /></td>
</tr>
<tr>
<td>Price:</td>
<td><input type="text" name="price" id="price" value="<?php echo $price ?>" disabled/></td>
</tr>
<tr>
<td>Stocks:</td>
<td><input type="text" name="stocks" id="stocks" value="<?php echo $stocks ?>" disabled/></td>
</tr>
<tr>
<td>Total:</td>
<td><input type="text" name="total" id="total" disabled/></td>
</tr>
<tr>
<td></td>
</tr>
</table>
</form>
<div align = "center">
hi' <?php echo $userRow['username']; ?> Sign Out
</div>
</body>
</html>
functions.php
<?php
function dropdown(){
$all = mysql_query("SELECT * FROM tblstore");
while($row = mysql_fetch_array($all)){
echo "<option value = '".$row['brandname']."' selected='selected'>" .$row['brandname'] . "</option>";
}
}
feel free to edit the whole code.. im a beginner in php and learning my way to it. thanks
Can add the multiple option if you need to select multiple
<select name="brandname" multiple>
<option value="Select">Select</option>
<?php
do {
?>
<option value="<?php echo $row['brandname']?>"> <?php echo $row['brandname'] ?></option>
<?php
} while ($row = mysql_fetch_assoc($all));
?>
</select>
I'm trying to create a changing drop down list in php, but without a database. Here's what I came up with so far
<body>
<form method = "post">
<table>
<tr>
<td>
<p>Name</p>
</td>
<td><input type="text" name="Name" /></td>
</tr>
<tr>
<td><p>State</p>
</td>
<td>
<select name = "State">
<option value = "PA"> Pennsylvania</option>
<option value = "CA"> California</option>
<option value = "AZ"> Arizona</option>
<option value = "NY"> New York</option>
<option value = "FL"> Florida</option>
</select>
</td>
</tr>
<td><input type="submit" name = "formSubmit" value="Submit" /></td>
</td>
</tr>
</table>
</form>
<?php
if(isset($_POST['formSubmit']))
{
if(empty($_POST['Name']))
{
echo("You forgot your name");
}
else
{
}
}
?>
</body>
I had planned to use the 'else' statement to generate my second drop down list, but so far nothing I've tried has worked. I've looked all over for ideas, but most of the information I've come across has dealt with databases. This isn't a database, it's a single PHP program. Maybe I have the wrong idea of how this works. Should I try calling a function that creates the form ahead of time or am I completely off base for what I'm attempting?
To do so you need javascript
There is already a question posted related to yours
javascript-dynamic-drop-down-box-update
jQuery would give you a true dynamic result without having to reload the page. However if you want to use PHP to add what is in the textbox to the list of values then you can use PHP session as an array to hold the values like this.
<?php
session_start();
if(isset($_POST['formSubmit']))
{
if(empty($_POST['Name']))
{
echo("You forgot your name");
}
else
{
$name = $_POST['Name'];
if(isset($_SESSION['List']))
{
$index = count($_SESSION['List']);
$_SESSION['List'][$index+1] = $name;
}
else
{
$_SESSION['List'][0] = $name;
}
}
}
?>
<body>
<form method = "post">
<table>
<tr>
<td>
<p>Name</p>
</td>
<td><input type="text" name="Name" /></td>
</tr>
<tr>
<td><p>State</p>
</td>
<td>
<select name = "State">
<option value = "PA"> Pennsylvania</option>
<option value = "CA"> California</option>
<option value = "AZ"> Arizona</option>
<option value = "NY"> New York</option>
<option value = "FL"> Florida</option>
<?php
if(isset($_SESSION['List']))
{
foreach($_SESSION['List'] as $name)
{
echo '<option value="'.$name.'">'.$name.'</option>';
}
}
?>
</select>
</td>
</tr>
<td><input type="submit" name = "formSubmit" value="Submit" /></td>
</td>
</tr>
</table>
</form>
</body>
I try to show some data by dropdown option from mySQL
when the user choose option United states and click submit, the page will go to the next page and show the data only for United states
here is my code for test.html
<body>
<table border="0">
<tr>
<th>test
</th>
</tr>
<tr>
<td>Select Foreign Agent Country</td>
<td></td>
<td>
<select>
<option value="US">United States</option>
<option value="AUD">Australia</option>
</select>
</td>
</tr>
<td>
<button type="submit">submit</button>
</td>
</table>
</body>
here is my second page showDB.php
<?php
//connect to server
$connect = mysql_connect("localhost", "root", "");
//connect to database
mysql_select_db("asdasd");
//query the database
//$query = mysql_query("SELECT * FROM auip_wipo_sample");
if($_POST['value'] == 'US') {
// query to get all US records
$query = mysql_query("SELECT * FROM auip_wipo_sample WHERE app_country='US'");
}
elseif($_POST['value'] == 'AUD') {
// query to get all AUD records
$query = mysql_query("SELECT * FROM auip_wipo_sample WHERE app_country='AUD'");
} else {
// query to get all records
$query = mysql_query("SELECT * FROM auip_wipo_sample");
}
//fetch the result
Print "<table border cellpadding=3>";
while($row = mysql_fetch_array($query))
{
Print "<tr>";
Print "<th>Name:</th> <td>".$row['invention_title'] . "</td> ";
Print "<th>Pet:</th> <td>".$row['invention-title'] . " </td></tr>";
}
Print "</table>";
?>
I try the above code, but I got 2 error which are
Undefined index: value in C:\xampp\htdocs\folder\showDB.php on line 10
Undefined index: value in C:\xampp\htdocs\folder\showDB.php on line 14
line 10 is
if($_POST['value'] == 'US') {
and line 14 is
elseif($_POST['value'] == 'AUD') {
anyone can give solution
thanks
You need to add a name parameter to test.html - either set it to name="value" to make showDB.php to work without any alterations, or set lines 10 and 14 to match the name parameter you set. Example below:
edit:
#adeneo is right, you also need to add a form and a valid submit button
<body>
<form action="showDB.php" method="post">
<table border="0">
<tr>
<th>test</th>
</tr>
<tr>
<td>Select Foreign Agent Country</td>
<td></td>
<td>
<select name="value">
<option name="country" value="US">United States</option>
<option name="country" value="AUD">Australia</option>
</select>
</td>
</tr>
<td>
<input type="submit" name="btn_submit" />
</td>
</table>
</form>
</body>
and the php:
if($_POST['country'] == 'US') {
// query to get all US records
$query = mysql_query("SELECT * FROM auip_wipo_sample WHERE app_country='US'");
}
elseif($_POST['country'] == 'AUD') {
You have no element with the name value in your form, so you don't have a $_POST['value'] either! Actually, you don't even have a form to submit at all, you just placed a link to another page inside the submit button ?
<body>
<form action="showDB.php">
<table border="0">
<tr>
<th>test</th>
</tr>
<tr>
<td>Select Foreign Agent Country</td>
<td></td>
<td>
<select name="value">
<option value="US">United States</option>
<option value="AUD">Australia</option>
</select>
</td>
</tr>
<td>
<button type="submit">submit</button>
</td>
</table>
</form>
</body>
I'm working on a profile page, where a registered user can update their information. Because the user has already submitted their information, I would like their information from the database to populate my HTML form.
Within PHP, I'm creating the HTML form with the values filled in. However, I've tried creating an IF statement to determine whether an option is selected as the default value. Right now, my website is giving me a default value of the last option, Undeclared. Therefore, I'm not sure if all IF statements are evaluation as true, or if it is simply skipping to selected=selected.
Here is my HTML, which is currently embedded with PHP(<?php ?>):
<?php
// Connect to MySQL
$db = mysql_connect("", "xxx", "xxx");
if (!$db)
{
exit("Error - Could not connect to MySQL");
}
$er = mysql_select_db("cs329e_fall11_nemo008", $db);
if (!$er)
{
exit("Error - Could not select the database");
}
$query = "SELECT *
FROM tblMembers
WHERE Username = 'fzr11017' ";
$result = mysql_query($query);
if (!$result)
{
print("Error - The query could not be executed");
$error = mysql_error();
print("<p>:" . $error . "</p>");
exit;
}
$row = mysql_fetch_array($result);
print <<<FORM
<form id="frmRegister" action="update.php" method="post" onsubmit="return Validate()" >
<table>
<tr>
<th><br /></th>
<td><br /></td>
</tr>
<tr>
<th align="left">Username:</th>
<td><input type="text" name="Username" maxlength="10" value=$row[Username] readonly="readonly"/></td>
</tr>
<tr>
<th align="left">First Name:</th>
<td><input type="text" name="FirstName" value=$row[FirstName] readonly="readonly" /></td>
</tr>
<tr>
<th align="left">Last Name:</th>
<td><input type="text" name="LastName" value=$row[LastName] readonly="readonly" /></td>
</tr>
<tr>
<th align="left">Email Address:</th>
<td><input type="text" name="Email" value=$row[Email] /></td>
</tr>
<tr>
<th align="left">Phone Number:</th>
<td><input type="text" name="Phone" maxlength="10" value=$row[Phone] /></td>
</tr>
<tr>
<th align="left">Year:</th>
<td>
<select name="Year" >
<option if(strcmp($row[Year], 'Freshman') == 0){ selected="selected"} >Freshman</option>
<option if(strcmp($row[Year], 'Sophomore') == 0){ selected="selected"} >Sophomore</option>
<option if(strcmp($row[Year], 'Junior') == 0){ selected="selected"} >Junior</option>
<option if(strcmp($row[Year], 'Senior') == 0){ selected="selected"} >Senior</option>
</select>
</td>
</tr>
<tr>
<th align="left">Primary Major:</th>
<td>
<select name="Major">
<option if($row[Major] == Accounting){ selected="selected"}>Accounting</option>
<option if($row[Major] == Business Honors Program){ selected="selected"}>Business Honors Program</option>
<option if($row[Major] == Engineering Route to Business){ selected="selected"}>Engineering Route to Business</option>
<option if($row[Major] == Finance){ selected="selected"}>Finance</option>
<option if($row[Major] == International Business){ selected="selected"}>International Business</option>
<option if($row[Major] == Management){ selected="selected"}>Management</option>
<option if($row[Major] == Management Information Systems){ selected="selected"}>Management Information Systems</option>
<option if($row[Major] == Marketing){ selected="selected"}>Marketing</option>
<option if($row[Major] == MPA){ selected="selected"}>MPA</option>
<option if($row[Major] == Supply Chain Management){ selected="selected"}>Supply Chain Management</option>
<option if($row[Major] == Undeclared){ selected="selected"}>Undeclared</option>
</select>
</td>
</tr>
<tr>
<th><br /></th>
<td><br /></td>
</tr>
<tr>
<td align="center"><input type="submit" name="btnSubmit" value="Submit" /></td>
<td align="center"><input type="reset" value="Reset" /></td>
</tr>
</table>
</form>
FORM;
?>
You've mixed HTML and PHP without declaring PHP tags and you've also used 'selected' as an attribute...
<select name="Major">
<option <?php echo ($row['Major'] == "Accounting") ? " selected" : ""; ?>>Accounting</option>
....
</select>
I've done the first one, but you can follow the same pattern
That code looks like it could use a towel:
<select name="Major">
<?php
$options = array(
'Accounting'
, 'Business Honors Program'
, 'Engineering Route to Business'
, 'Finance'
, 'International Business'
, 'Management'
, 'Management Information Systems'
, 'Marketing'
, 'MPA'
, 'Supply Chain Management'
, 'Undeclared'
);
foreach( $options as $option )
{
printf(
"<option%s>%s</option>\n"
, ($row['Major'] == $option ? ' selected="selected"' : '')
, htmlentities($option)
);
}
?>
</select>
You might find some of this reading useful to help explain some of the concepts used above:
arrays
foreach loop
ternary operator (?:)
printf()
htmlentities()
You seem to be missing any tags in your code, which means that nothing is being processed. Something more along the lines of this should be used:
<option <?php if($row["Major"] == "Accounting"){ echo "selected"; } ?>>Accounting</option>