Im having issues with data not being entered into the db. I have a form with 5 inputs and a select The drop down select is a dynamic list fro the db. When the form is submitted nothing is entered in the db for the campaign_owner columns. I have the values="" which I think is the problem, but I also tried
<option value="<?php echo $user['username']; ?>"><?php echo $user['username']; ?></option>
yet that doesn't help.The dropdown shows the data I want and allows you to select it on the page it just doesn't submit it and I dont know why.
HTML:
<div class="col-sm-5 col-sm-push-1 form-group required">
<label class="control-label" ><?php echo $entry_owner; ?></label>
<select name="user-list" id="user-list">
<?php foreach ($users as $user) { ?>
<option value="<?php echo $user['username']; ?>"><?php echo $user['username']; ?></option>
<?php } ?>
</select>
</div>
HTML forms work with the input/select/textarea etc. names. Your select is named "user-list" which means that when submitted it will be under the key user-list. You'll need to map that to the campaign_owner column.
Related
I want to block the user to input I just want him to choose only from the list
I tried disable and readonly but this will disable my list and I don't want that.
This is my code
<div class="form-group row justify-content-center" id=" input-champs " style="margin-left:;" ><!-- grossistee -->
<label for="grossiste" class="col-2 col-form-label"></label>
<div class="col-3">
<input type="text" list="list-gro" placeholder="Grossiste1" id="g_name1" name="g_name1" class="form-control">
<datalist id="list-gro">
<?php while($row = mysqli_fetch_array($resultg)) { ?>
<option value="<?php echo $row['g_name']; ?>"><?php echo $row['g_name']; ?></option>
<?php } ?>
</datalist>
</div>
From the living standard spec of the datalist element:
Each option element that is a descendant of the datalist element, that is not disabled, and whose value is a string that isn't the empty string, represents a suggestion. Each suggestion has a value and a label.
Conversely, this means that a user can enter anything he wants. The datalist element only contains suggestions that the user can use, but does not have to.
For your puprose I 'd suggest a select element. A select element dictates strict values for the user to use.
<label for="my-select">My Select</label>
<select name="my-select" id="my-select" required>
<option value="" disabled selected>Select your option</option>
<?php foreach ($databaseresult as $row): ?>
<option value="<?= htmlspecialchars($row['value']) ?>">
<?= htmlspecialchars($row['label']) ?>
</option>
<?php endforeach ?>
</select>
Its better to use select in place of input as you dont want the user to type in anything from himself/herself.
You can do like this to implement select with database query
<select name="g_name1" id="g_name1" class="form-control">
<?php while($row = mysqli_fetch_array($resultg)) { ?>
<option value="<?php echo $row['g_name']; ?>"><?php echo $row['g_name']; ?></option>
<?php } ?>
</select>
How do I get this to work?
<div class="form-group">
<label for="data[day]">Day:</label>
<?php $day_of_week = array('','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday') ?>
<select class="form-control">
<?php foreach($day_of_week as $day):?>
<option value="<?php echo $day; ?>"><?php echo $day; ?></option>
<?php endforeach; ?>
</select>
</div>
I wanted the user to select day of the week using the combobox and it should return the value of the option tag into database.I am wondering why this method does not return any value in database. Any correction would be appreciated. This div tag is in form tag where it will return the form to the database.
Your <select> tag doesn't have a name, so the value won't be submitted to the server. It also doesn't have an id, so the label won't be linked with it.
<select id="data[day]" name="day" class="form-control">
When the form is submitted, the value will be in $_POST['day'].
The following is my HTML code
<div class="col-md-6">
<label for="martial_status">Martial Status</label>
<select name="martial_status" id="martial_status" class="form-control" value="<?php echo set_value('martial_status'); ?>">
<option value="">Select Martial Status</option>
<?php foreach ($martial_status as $status) { ?>
<option value="<?php echo $status['id'] ?>"><?php echo $status['status_name'] ?></option>
<?php } ?>
</select>
Even though i have used the form_validation in controller side, the value is not getting set in drop down once the form fails submitting. How to set the previous value selected in drop down on form failure. Where am I going wrong.
You cannot set the value straightly to select tag. You need to set the selected attribute to option tag which you want it to be get selected. Just like it below....
<div class="col-md-6">
<label for="martial_status">Martial Status</label>
<select name="martial_status" id="martial_status" class="form-control" value="<?php echo set_value('martial_status'); ?>">
<option value="">Select Martial Status</option>
<?php foreach ($martial_status as $status) { ?>
<option value="<?php echo $status['id'] ?>" <?php if ($status['id'] == set_value('martial_status')) echo "selected = 'selected'"?>><?php echo $status['status_name'] ?></option>
<?php } ?>
</select>
On generating the options tag check which option got selected and echo selected = 'selected' in the attribute of that option tag.
I am trying to populate two dropdown menus with items in a lookup table. So far I have this:
<label for="search_for_<?php echo $field['name']; ?>"><?php echo $field['label']; ?></label>
<select name="search" class="select">
<option value="<?php echo $field['name']; ?>"><?php echo $field['label']; ?></option>
</select>
which gives me the drop down menus but only populates them with the names of the columns and not the data in the rows.
Searched high and low for this but most suggestions remove even the 'header' and leave the drop downs blank.
I am new in this forum..Forgive me for any kind of mistake & help me.
I have a form with only two fields,first one textfield & next dropdown list.Now I want to show value in list from database based on textfield value from database.i.e If I type perfect username it will show me in dropdown the corresponding emailid(s) of that user.It will change after the username being changed.
Hope someone will help me in this matter.I was working a long time,but cant satisfied.Thanks in advance.This is the code what I have tried.But I want just the reverse.
`
function CBtoTB()
{document.getElementById("username").value=document.getElementById("usernameselect").value}
<?php
$result=mysql_query("select Username from users");
$options="";
while ($row=mysql_fetch_array($result)) {
$username=$row["Username"];
$options.="<OPTION VALUE=\"$username\">".$username.'</option>';
}
?>
<select name="usernameselect" id="usernameselect" onchange="CBtoTB()">
<option value="">< select user ><?php echo $options ?></option>
</select>
<input name="username" type="text" id="username" value="<?php echo $username ?>" size="25" readonly="readonly" />`
You option was writen wrongly please try this :
<select name="usernameselect" id="usernameselect" onchange="CBtoTB()">
<option value="">< select user ></option>
<?php echo $options ?>
</select>