I have an Oracle database. In my database I have a table called "DRIVER". I created 3 collumns inside the table called ID,CAR and PERSON.
I need to create a drop down menu where I will be able to choose one from all the cars that are in the column "CAR". When I choose a car from drop down menu, automatically in the textbox bellow will be written a name of the person that owns the car.
Example:
Let's choose a car in the 3rd position from drop down menu. Automatically when I choose the 3rd car the textbox bellow will write name of the person with an ID = 3.
I only made a drop down menu and an empty textbox. I don't have a clue what to do next. Please keep in mind that I am a beginner and I had a help even with this part of the code.
<?php
$ora_sql2 = oci_parse($conn, 'SELECT DRIVER.ID,DRIVER.CAR,DRIVER.PERSON FROM DRIVER');
oci_execute($ora_sql2, OCI_DEFAULT);
?>
<form method="post" action="insert.php">
<table width="319" border="1" cellspacing="0" cellpadding="4">
<tr>
<td>
<select name="drop_menu" id="drop_menu">
<?php
while(oci_fetch($ora_sql2))
{ ?>
<option value="<?php echo oci_result($ora_sql2, 'ID')?>"><?php echo oci_result($ora_sql2, 'CAR')?></option>
<?php
}?>
</select>
</td>
</tr>
<tr>
<td>
<label for="textbox"></label>
<input type="text" name="textbox" id="textbox" />
</td>
</tr>
</table>
</form>
You need to use JavaScript for that. You can listen to the 'change' event of the select box and if fired, assign the text box.
The first example on http://api.jquery.com/change/ is the answer of your question.
Related
I am trying to make a rating system using multi-select dynamically generated from rating text on the database. The final result should look like this: Rating Service but now I need to save selected option after save is clicked.
in the database there is two table the first one have 2 column the first is the id and the second is the text of the rate
the second table is where i wont to save the selection that the user chose using php
page code
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>About</th>
<th>Provider</th>
<th>Rating</th>
</tr>
</thead>
<?php
$query_rate_text = "SELECT * FROM rateing_text";
$selecting_rates = mysqli_query($con,$query_rate_text);
$i = 0;
while($row_rate = mysqli_fetch_assoc($selecting_rates)){
$rate_id= $row_rate['rate_id'];
$rate_text= $row_rate['rate_text'];
$i++
?>
<form name="rating_form">
<tbody>
<tr>
<td><?php echo $i ?></td>
<td> <?php echo $rate_text ?></td>
<td><span class="badge badge-danger">
<?php echo $provider_name ?></span></td>
<td>
<select name="p<?php echo $i ?>">
<option value="1">Very Bad</option>
<option value="2">Bad</option>
<option value="3">Good</option>
<option value="4">Very Good</option>
<option value="5">Excelent</option>
</select>
</td>
</tr>
</tbody>
<?php } ?>
<tfoot>
<tr>
<td colspan="3"><button type="submit" name="save_rate"> Save </button> </td>
</tr>
</tfoot>
`enter code here`
</form>
</table>
How can I get info form the select and save them to the database ?
Radio button is much better than <select>.
The rate id and selected value must be passed as a key=>value
You need to stop using Word Press syntax.
Learn to use Herdoc Syntax
Using SELECT * is a poor standard practice.
Fetch array and assign values with a list
This code is untested.
<?php
echo <<<EOT
<form name="rating_form" action="#">
<table class="table table-striped">
<tr><th>#</th><th>About</th><th>Provider</th><th>Rating</th></tr>
EOT;
$query_rate_text = "SELECT `rate_id`,`rate_text` FROM rateing_text WHERE 1 ORDER BY `rate_id`";
$selecting_rates = mysqli_query($con,$query_rate_text);
$i = 0;
while(list($rate_id, $rate_text) = mysqli_fetch_array($selecting_rates)){
$i++;
echo "<tr><td>$i</td><td>$rate_text</td><td>$provider_name</td><td>5<input type="radio" name=\"$rate_id\" value=\"5\" /> 4<input type="radio" name=\"$rate_id\" value=\"4\" /> 3<input type="radio" name=\"$rate_id\" value=\"3\" /> 2<input type="radio" name=\"$rate_id\" value=\"2\" /> 1<input type="radio" name=\"$rate_id\" value=\"1\" /></td></tr>\n";
}
echo '</table><button type="submit" name="save_rate"> Save </button></form>';
?>
UPDATE
thank you very much that's helped to understand new way's,one more
thing how can i get the data out from this radio 5 buttons to insert
them to the database to the table named rating which have let's say 3
column id and provider name and the rate it self , again thank you for
helping
The radio input type is a more user friendly way then the cumbersome select.
The way I setup the radio buttons with the rate_id as the "name" so the selected "value" is passed as a key=>value pair to the form's action script.
Your select name should also contain the rate_id
The problem your code has is, the action script will receive will receive keys of sequential numbers that have no meaning and difficult to know how many were posted by the form.
To pass the provide name add a hidden input type:
<input type="hidden" name="provider" value="$provider_name" />
And I would remove the provider from the table td.
Not knowing your rate_id convention I could not improve the radio button naming convention.
The way I would do it is when passing key=>value pairs I would begin the key "name" with a unique character where no other "name" in the form would start with that character.
For example if the rate_id is a numeric value I may prepend a 'k' to the numeric key value.
So instead of
name=\"$rate_id\"
I would use
name=\"k$rate_id\"
The in the receiving action script I would get the key=>values like this
$provider_name = $_GET['provider']
foreach($_GET as $key => $value)){
if(substr($key,0,1) == 'k'){
$rate_id = intval(substr($key,1));
$rating = intval($value);
$sql = "INSERT INTO `table` (`rate_id`, `provider_name`, `rating`) VALUES ($rate_id, '$provider_name', $rating)";
mysqli_query($link,$sql);
}
}
My problem is only user id is inserted into database but I want to insert user id, date and radio button value. How can I insert radio button value into the database?
I have 3 employees and I want to insert user id, date and status of a particular user. I have a single submit button and if I press submit then I want to insert all data into database.
Here is my Code:
<form>
<input type="date" name="date" >
<table class="display data_tbl">
<thead>
<tr>
<th>
Date
</th>
<th>
Employee Name
</th>
<th>
Status
</th>
<th>
Action
</th>
</tr>
</thead>
<tbody>
<?php
error_reporting(0);
$us=0;
$at="select * from user_information";
$atd=mysql_query($at);
while($data=mysql_fetch_array($atd))
{
$us++;
if(isset($_GET['submit']) && $_GET['submit']!='' && $_GET['date']!='')
{
$a=$_GET['date'];
echo $b=date('d-m-Y',strtotime($a));
$insert=mysql_query("insert into attendence set user_id='".$data['user_id']."',date='".$b."',status='".$_GET['radio']$us."'");
}
?>
<tr>
<td><?php echo $b;?></td>
<td align="center"> <?php echo $data['name'];?>
</td>
<td class="center">
</td>
<td class="center">
<input type="radio" name="radio<?php echo $us;?>" value="Late">Late
<input type="radio" name="radio<?php echo $us;?>" value="Absent">Absent
<input type="radio" name="radio<?php echo $us;?>" value="Present">Present
<input type="radio" name="radio<?php echo $us;?>" value="Halfday">Halfday
<input type="radio" name="radio<?php echo $us;?>" value="Leave">Leave
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<input type="submit" name="submit" value="Take Attendance">
</form>
firstly there is no need to give radio button name like you give because in radio button only one value can be selected at a time so remove the php value(i think you are using this to make radio button name unique) you are using with radio button name value from radio button name and than try.
You're insert statement has a syntax error, try replacing the following line
$insert=mysql_query("insert into attendence set user_id='".$data['user_id']."',date='".$b."',status='".$_GET['radio']$us."'");
with the following
$insert=mysql_query("insert into attendence(user_id, date, status) values('".$data['user_id']."','".$b."','".$_GET['radio'].$us."')");
There are many problem in your posted script
firstly as cyber_rookie mentioned, there is query syntax error in
data insert
secondly you have added submit button code inside while loop, which
is wrong, as while you are using for preparing display data and
submit code should be executed on submit button click
I have tried to make bit correct, please find code here https://jsfiddle.net/h5e5Lxnm/ you can check and modify it according to your requirement.
This code will give you all selected data (including date, radio vlaues and all)
EDIT:
My bad for saying you shouldn't use SET but here's another way for INSERT query:
INSERT INTO tablename (column1, column2, etc...) VALUES(value1, value2, etc....)
Applying to your code, this:
$insert=mysql_query("insert into attendence set user_id='".$data['user_id']."',date='".$b."',status='".$_GET['radio']$us."'");
to this:
$insert=mysql_query("insert into attendence (user_id, date, status)
values('".$data['user_id']."', '".$b."','".$_GET['radio'].$us."')");
And, your radio button should not have a different name so that the user can only select one option.
I have a query to display all the records of the ebooks table from the database.
I displayed it in a table with a checkbox from the first column.
I'm trying to save the rows from the selected checkbox in the table width the Name of School but I don't have any idea.
I'm just a beginner in php, any help is appreciated. Here is my codes:
HTML codes:
$result1 = mysql_query("SELECT * FROM school GROUP BY SCHOOL_NAME");
while($row1=mysql_fetch_array($result1)) {
?>
<option><?php echo $row1['SCHOOL_NAME'];?></option>
<?php } ?>
</select>
<table class="table table-striped table-hover table-bordered datatable">
<thead style="background: #a83535; color: black;">
<tr>
<th style="width: 50px;"></th>
<th style="color: #3b3b3b;">Ebook Title</th>
<th style="color: #3b3b3b;">Category</th>
<th style="color: #3b3b3b;">File Name</th>
</tr>
</thead>
<tbody>
<?php
$result = mysql_query("SELECT * from ebooks ORDER BY EBOOK_TITLE");
$count = mysql_num_rows($result);
while($row=mysql_fetch_array($result)) {
?>
<tr>
<td>
<center><input type="checkbox" name="check[]" ></center>
</td>
<td><input type="" name="ebookname[]" value="<?php echo $row['EBOOK_TITLE'];?>"></label></td>
<td><input type="" name="ebookcategory[]" value="<?php echo $row['EBOOK_CATEGORY'];?>"></label></td>
<td><input type="label" name="ebookfilename[]" value="<?php echo $row['EBOOK_FILENAME'];?>"></label></td>
</tr>
<?php } //end of while loop ?>
</tbody>
</table>
<button type="submit" class="btn btn-hg btn-primary" name="AddEbooks">Submit</button>
I want to save the rows selected by the checkbox to database:
Table: school_management
Columns: ID_NUMBER, SCHOOL, EBOOK, FILE_NAME, DATE_ASSIGN
Values (from the HTML table to database): ('','$school_ebook','$ebookname','$ebookfilename','')
Here is the screenshot:
First, you will need to assign an ID number to the checkboxes so that you can differentiate each record. Using the ID_NUMBER would be ideal here. In your current script where you are displaying the checkbox, your line that reads this:
<center><input type="checkbox" name="check[]" ></center>
Should include the ID_NUMBER like this in the name. Additionally, a value should be assigned to the checkbox so we can verify later.
<center><input type="checkbox" name="check[<?php echo $row['ID_NUMBER'];?>]" value="1"></center>
Now you can go ahead and set up something that gets triggered when your form is submitted. You can essentially loop through each record and check it against the "check[ID_NUMBER]" checkbox to see if the value is 1. If the value is 1 then the record had been checked to save and you can then carry on saving the record.
How you want to handle the form is up to you - you could do AJAX to avoid reloading the entire page or you could do a simple form action="page_name_here.php" and handle the submission there. If you go about doing a simple form post without AJAX, it could be something like this -
Current page form tag:
<form name="" action="page_name_here.php" method="POST">
If you want to use the school_ebook var you need to assign the select options for the school_ebook a value:
<option value="<?php echo $row1['SCHOOL_NAME']'?>">
page_name_here.php:
<?php
/* Get the school name */
$school_ebook=$_POST["school_ebook"];
/* Query your books DB to get the records */
$result=mysql_query("SELECT * from ebooks ORDER BY EBOOK_TITLE");
$count=mysql_num_rows($result);
while($row=mysql_fetch_array($result)) {
$bookID=$row['ID_NUMBER'];
/* Get the Book ID and now we have to fetch from $_POST the value from the form */
if (array_key_exists($bookID, $_POST["check"])) {
$ischecked=$_POST["check"][$bookID];
/* See if this has a value of 1. If it does, it means it has been checked */
if ($ischecked==1) {
/* It is checked, so now in this area you can finish the code to retrieve the data from the row and save it however you like */
}
}
}
?>
Once completed with your inserts, etc., it should accomplish what you need.
I have a form that has many text fields. Among them I have an issue with textfields (seating area and price). They can me added more and more according to the user clicks.
Here are my conditions:
1 - if (either of them) seating area textfield is empty or the price textfield is
empty the form should not be submitted.
2 - I have already used jquery plugin to validate some text fields but not all.
3 - As the field(seating area and price are related to each other in my condition
I have used their name as array to post all the value in array like:
<tr>
<td>
<input type="text" name="fldSeatingarea[]" id="fldSeatingarea[]">
</td>
<td>
<input type="text" name="fldPrice[]" id="fldPrice[]">
</td>
</tr>
<tr>
<td>
<input type="text" name="fldSeatingarea[]" id="fldSeatingarea[]">
</td>
<td>
<input type="text" name="fldPrice[]" id="fldPrice[]">
</td>
</tr>
<tr>
<td>
<input type="text" name="fldSeatingarea[]" id="fldSeatingarea[]">
</td>
<td>
<input type="text" name="fldPrice[]" id="fldPrice[]">
</td>
</tr>
4 - and whenever the user clicks add more the table row is inserted with fields
5 - I have not validate these fields(fldSeatingarea[] and fldPrice[])
6 - User must put value to both field of same row or to none of same tbl row.
SO my question is: how am I gonna find either of the two fields (fldSeatingarea[] and fldPrice[]) of the same table row are not empty when the form is submitted?
If either of the fields of same table row is empty the form should not be submitted.
I am doing this small experiment using html, php, and a little bit of javascript.
<tr>
<td>
<input type="text" name="fldSeatingarea[]" id="fldSeatingarea_1">
</td>
<td>
<input type="text" name="fldPrice[]" id="fldPrice_2">
</td>
</tr>
<tr>
<td>
<input type="text" name="fldSeatingarea[]" id="fldSeatingarea_2">
</td>
<td>
<input type="text" name="fldPrice" id="fldPrice_2">
</td>
</tr>
Use Id's Like this to reference the fields for validation.. otherwise it will not work.
I don't particularly agree with how you have used IDs on your form. I would keep a JS array variable to indicate the selected seating areas, while you populate the form.
Then you can change the ID of the element to be fldSeatingarea_3 or fldSeatingarea_5 and target both area and price elements by looping through the array for (var n in selection) { //check the 'fldSeatingarea_'+n field }
if you wana concept than you can do it with parent and child concept through jquery
what you have to do find all tr in table and than for each tr find their fldSeatingarea[] and fldPrice[]
after it validate it if you find both are empty return false for submit event
here are some link which may help you more for it
http://api.jquery.com/child-selector/
http://api.jquery.com/parent/
Just my opinion
After submiting the form all the field(fldSeatingarea[] and fldPrice[])
is passed in an array.both of them..
You can used count to compare the how many value are inserted and how many fields are added and if they ddon`t have the same value the form will triger and not submit unless they have the same value.
dear all..i have a textfield
<tr>
<td>
<td><input type="text" id="model_name"></td>
</td>
</tr>
and a cell
<tr>
<td><div id="value">//i want data show here after fill textfield</div>
</td>
</tr>
beside that, i've a table "settingdata" in database it consist of 2 field:itemdata and remark..
itemdata's value are "UD" and remark's value are "FM=87.5-108.0MHZ"...
what must i do if i want after type model name "car01UD" at textfield inside
<div id="value"></div>
can show "FM=87.5-108.0mhz"...
if you want "0103" + value of itemdata then do following
<input type="text" id="mod" value="0103<?PHP echo $itemdata ?>">
Looks like you are trying to do basic Ajax functionality. Consider reading some Ajax tutorials to get an idea how to do this.