jQuery Chosen Plugin Insert Multiple data into database - php

I have problem with this :
Please visit http://s13.postimg.org/na4ppenfb/Stack.jpg
I use jQuery choosen. I have download that, from this address : http://harvesthq.github.io/chosen/, but I have modified that. this my code, can anybody help my problem :
<div class="side-by-side clearfix">
<div><em>Dosen Pembimbing</em>
<select data-placeholder="DOSEN PEMBIMBING KP" style="width:350px;" class="chosen-select" tabindex="5" id="dosen_pembimbing_kp" name="dosen_pembimbing_kp">
<option disabled selected>PILIH DOSEN PEMBIMBING</option>
<?php
include('config.php');
$query="SELECT * FROM dosen";
$daftar=mysql_query($query);
while ($dosen=mysql_fetch_object($daftar))
{
echo"<option>$dosen->nama</option>";
}
?>
</select>
</div>
<div><em>Mahasiswa</em>
<select data-placeholder="Pilih Mahasiswa KP" style="width:350px;" class="chosen-select" multiple tabindex="6" id="mhs" name="mhs">
<option value=""></option>
<?php
include('config.php');
$query="SELECT * FROM mahasiswa_kp";
$daftar=mysql_query($query);
while ($mhs=mysql_fetch_object($daftar))
{
echo"<option value='$mhs->nim_mhs_kp'>$mhs->nim_mhs_kp</option>";
}
?>
</select>
</div>
<div></div>
<div></div>
<div class="side-by-side clearfix">
<p> </p>
<p>
<input type="submit" name="login" value="Simpan" />
<input type="reset" name="reset" id="reset" value="Reset" class="ui-widget ui-widget-content padding ui-corner-all"/>
</p>
</div>
</div>
</div>
</div>
Please help me for insert data into database with PHP code.

Related

select tag name not working while using it in php

I have a form in html and I am saving it as search.php:
<form name="myform" action="" method="POST" onsubmit="search_clicked(); return false;">
Keyword<input type="text" name="Keyword" id="Keyword" value="XYZ" required/><!-- value is the default name that appears in the text box-->
<br>
Type
<select name="sel" id="sel" class="form-control" onchange="checkcolors(this.value)">
<option selected value="Users">Users</option>
<option value="Pages">Pages</option>
<option value="Events">Events</option>
<option value="Places">Places</option>
<option value="Groups">Groups</option>
</select>
</form>
<div id="loc_dist_displayarea" style="display:none;">
Location<input type="text" name="Location" value="90007" required/> Distance(meters)<input type="text" name="distance" value="10000" required/>
</div>
<br><br>
<input type="submit" name="Search"/>
<input type="submit" value="clear" id="clear" onclick="return clearclicked()"/>
</form>
and my php script is in the same file:
<div id="body_area" style="display:none">
<?php
echo "hi I am searching ";
if($_SERVER["REQUEST_METHOD"]=="POST")
{
//echo "yes value is selected";
//echo $_POST["Keyword"];
if (isset($_POST['sel'])) {
$selectedval= $_POST["sel"];
echo "$selectedval";
}
//echo $_POST["Location"];
}
echo "no value is selected";
?>
</div>
I am not able to display the $_POST['sel'] while $_POST['Keyword'] is echoed.Please help.
First of all, you arent using good programming practices, you use quotation marks (these " and these ') Indiscriminately. You should only alternate between them when you have them nested.
Next, on the action paramenter you should put the name of the file, even if it's the same.

Text not allowed in element select in this context

I created a forum, where students have to fill out their year of graduation. When I was validating my file, as shown by the comment, the line below produces an error, "Text not allowed in element select in this context." I need to name "year" in the select tag, so I can use the post array to get the year. How can I fix this validation error?
<form method="post">
<div class = "mailInput">
Name: <input type="text" name="name">
<span class="error"> <?php echo $nameErr;?></span></div>
<div class = "mailInput">
Email: <input type="text" name="email">
<span class="error"> <?php echo $emailErr;?></span> </div>
<div class = "mailInput">
Major: <input type="text" name="major">
<span class="error"> <?php echo $majorErr;?></span> </div>
<div class = "mailInput">
Year: <select class="select" name="year"> // this line produces an error
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
</select>
</div>
<div class = "mailInput lastInput"> Gender:
<input type="radio" name="gender" value="Female">Female
<input type="radio" name="gender" value="Male">Male
</div>
<span class="error"> <?php echo $genderErr;?></span>
<div class = "submitButton"><input type="submit" name="submit" value="Join">
</div>
<div class="message"> <?php echo $submitMessage;?></div>
</form>
if(isset($_POST['submit']) && !empty($_POST['submit'])) {
if (!empty($_POST["year"])) {
$year = $_POST["year"];
}
}
// this line produces an error will prevent your code from working as it is not the correct way to write comments in HTML code.
The correct way is by using <!-- --> and therefore, in your case, it should have been <!-- this line produces an error -->
// is used to write comments in PHP and JavaScript.
/* */ is used to write comments in CSS.

PHP Possible to build form elements after a selection is made?

I have a form with a select box that determines if a div is hidden or shown. Each div has text boxes and a button. Since my validation is validating ALL divs hidden or shown, is it possible IF a select option is selected PHP can echo the form picked? For example, below I have
<div id="1" class="colors" style="display:none">
<input type="text" name="1">
<button type="submit" name="submit">Submit</button>
</div>
Is it possible to create an array to build the code above when that option is picked? Same goes for the second hidden div -
<div id="2" class="colors" style="display:none">
<input type="text" name="1">
<input type="text" name="2">
<button type="submit" name="submit">Submit</button>
</div>
This way only one form will be created at a time when a option is picked in the select box. Is this possible? Is this a good idea? The original form will have more form elements.. this is just a sample. Here's the code below.
<script>
$(function() {
$('#colorselector').change(function(){
$('.colors').hide();
$('#' + $(this).val()).show();
});
});
</script>
<form action="" onSubmit="return validateForm(this)" method="post" name="form">
<select id="colorselector">
<option selected></option>
<option value="1">1</option>
<option value="2">2</option>
</select>
<div id="1" class="colors" style="display:none">
<input type="text" name="1">
<button type="submit" name="submit">Submit</button>
</div>
<div id="2" class="colors" style="display:none">
<input type="text" name="1">
<input type="text" name="2">
<button type="submit" name="submit">Submit</button>
</div></form>
If this is possible and a good idea, can you provide an example on how this can be accomplished?

PHP echo ID and Pop Up form

I have a pop-up form when user clicks "update", there should be a pop up form where user should be able to update but the pop up does not appear because the "a href" has "echo" in the id value. See below: echo $orderId
Update
But if I delete the <?php echo $orderId ?>part, for example Update the pop up works but echo wrong ID.
Below is the form
<div class="popup">
<form method = "post" action="">
<div>
<label for="Order ID">Order ID:</label><?php echo $orderId ?>
</div><br>
<div>
<label for="Order Date">Order Date:</label><?php echo $orderDate ?>
</div><br>
<div>
<label for="Order Total">Order Total:</label><?php echo $totalAmount ?>
</div><br>
<div>
<label for="Preparation Status">Preparation Status:</label>
<select name="preparationStatus"/>
<option value="<?php echo $preparationStatus; ?>">Default(<?php echo $preparationStatus; ?>)</option>
<option value="Pending">Pending</option>
<option value="Prepared">Prepared</option>
</select>
</div><br>
<div>
<label for="Payment Status">Payment Status:</label>
<select name="paymentStatus">
<option value="<?php echo $paymentStatus;?>">Default(<?php echo $paymentStatus;?>)</option>
<option value="Pending">Pending</option>
<option value="Paid">Paid</option>
</select>
</div><br>
<input type="submit" id="btn" name="submit" value="Save" />
<a class="close" href="#close"></a>
</form>
It only echoes id="id=1"
How can I make the popup form appear?

Get selected text from dropdown in PHP

I am totally new in PHP, in fact the reason I am doing this is to customize a wordpress plugin so it can fit my need. So far I have a default form, what I am doing now is to add a country dropdown. Here's how I add it
<div class="control-group">
<label class="control-label" for="Country">Country :</label>
<div class="controls">
<select id="itemType_id" name="cscf[country]" class="input-xlarge">
<option value="malaysia#email.com">Malaysia</option>
<option value="indonesia#email.com">Indonesia</option>
</select>
<span class="help-inline"></span>
</div>
</div>
So far I only able to retrieve the value of selected item with
$cscf['country'];
How can I get the display text which is the country name in this case ?
You can use a hidden field, and with JavaScript and jQuery you can set the value to this field, when the selected value of your dropdown changes.
<select id="itemType_id" name="cscf[country]" class="input-xlarge">
<option value="malaysia#email.com">Malaysia</option>
<option value="indonesia#email.com">Indonesia</option>
</select>
<input type="hidden" name="country" id="country_hidden">
<script>
$(document).ready(function() {
$("#itemType_id").change(function(){
$("#country_hidden").val(("#itemType_id").find(":selected").text());
});
});
</script>
Then when your page is submitted, you can get the name of the country by using
$_POST["country"]
<select name="text selection" onchange="getText(this)">
<option value="">Select text</option>
<option value="1">my text 1</option>
<option value="2">my text 2</option>
</select>
First put a java script function on the attribute "onchange" of the select.
Then, create your function that will transfer the text in a text box by using getElementById
<script>
function getText(element) {
var textHolder = element.options[element.selectedIndex].text
document.getElementById("txt_holder").value = textHolder;
}
</script>
Then create a temporary holder:
<input type="" name="txt_holder" id="txt_holder"> type should be hidden
Then assign it in a PHP variable:
$variableName=$_POST['txt_holder'];
Try this
<?php
if(isset($_POST['save']))
{
$arrayemail = $_POST['cscf'];
$mail = $arrayemail['country'];
$explode=explode('#',$mail);
// print_r($explode);
if(isset($explode[0]))
echo ucfirst($explode[0]);
}
?>
<form method="post">
<div class="controls">
<select id="itemType_id" name="cscf[country]" class="input-xlarge">
<option value="malaysia#email.com">Malaysia</option>
<option value="indonesia#email.com">Indonesia</option>
</select>
<span class="help-inline"></span>
</div>
<div class="controls">
<input type="submit" name='save' value="Save"/>
<span class="help-inline"></span>
</div>
</form>
Try it like,
<?php
if(isset($_POST['save']))
{
//Let $_POST['cscf']['country']= malaysia#email.com
// you can explode by # and get the 0 index name of country
$cnt=explode('#',$_POST['cscf']['country']);
if(isset($cnt[0]))// check if name exists in email
echo ucfirst($cnt[0]);// will echo Malaysia
}
?>
<form method="post">
<div class="controls">
<select id="itemType_id" name="cscf[country]" class="input-xlarge">
<option value="malaysia#email.com">Malaysia</option>
<option value="indonesia#email.com">Indonesia</option>
</select>
<span class="help-inline"></span>
</div>
<div class="controls">
<input type="submit" name='save' value="Save"/>
<span class="help-inline"></span>
</div>
</form>

Categories