Hello fellow programmers, I have created a search form for my webpage which allows users to use three different fields to refine their search. I have been trying to align these objects with the main heading of the search page. I have tried many different methods but seems to move the objects into the centre. It's really bugging me and I have no clue in how to fix this! Any recommendations?
<p style="text-align:center">View Recipes which satisfy the following criteria:</p>
<div class="container cols justify-content center">
<div style="margin-bottom: 30px; width: 300px;">
<label for="author">By Author:</label>
<select name="author" id="author">
<option value="">Any Author</option>
<?php foreach ($authors as $author): ?>
<option value="<?php html($author['id']);?>"><?php html($author['name']);?></option>
<?php endforeach;?>
</select>
</div>
<div style="margin-bottom: 30px; width: 300px;">
<label for="category">By Category:</label>
<select name="category" id="category">
<option value="">Any Category</option>
<?php foreach ($categories as $category): ?>
<option value="<?php html($category['id']);?>"><?php html($category['name']);?></option>
<?php endforeach;?>
</select>
</div>
<div style="margin-bottom: 30px; width: 300px;">
<label for="text">Containing Text:</label>
<input type="text" name="text" id="text">
</div>
<div style="margin-bottom: 30px; width: 300px;">
<input class="btn btn-primary" type="submit" name="action" value="Search">
</div>
</div>
</form>
</div>
Change the margin-bottom: 30px; on all 4 div to margin: 30px auto;
If you want the align to centre then also add text-align:center; along with this margin: 30px auto;
Codepen: https://codepen.io/manaskhandelwal1/pen/PoGdxpa
Related
I have these divs (links) that can be clicked on.
I want to change a dropdown selection accordingly.
So if it's clicked on select2, it would change the dropdown value to 666
If select3, it would change to 667
and so on.
I can't modify dropdown values, however the target id's CAN be exact as dropdown values, if that will make things easier to code.
I know there are some mistakes in my jQuery script.
Any help would be appreciated.
<script>
const select = $('#sel2');
// Initialize at position 1
selectElement('665');
select.change(function() {
selectElement($(this).val());
})
function selectElement(id) {
$('#' + target).addClass("selected");
others.removeClass("selected");
}
</script>
<div style="display: inline-block; margin-bottom: 0.4em;" class="showSingle greenactive" target="01">select1</div>
<div style="display: inline-block; margin-bottom: 0.4em" class="showSingle" target="02">select2</div>
<div style="display: inline-block; margin-bottom: 0.4em" class="showSingle" target="03">select3</div>
<div style="display: inline-block; margin-bottom: 0.4em" class="showSingle" target="04">select4</div>
<div style="display: inline-block; margin-bottom: 0.4em" class="showSingle" target="05">select5</div>
<div style="display: inline-block; margin-bottom: 0.4em" class="showSingle" target="06">select6</div>
<div style="display: inline-block; margin-bottom: 0.4em" class="showSingle" target="07">select7</div>
<div style="display: inline-block; margin-bottom: 0.4em" class="showSingle" target="08">select8</div>
<div style="display: inline-block; margin-bottom: 0.4em" class="showSingle" target="09">select9</div>
<div style="display: inline-block; margin-bottom: 0.4em" class="showSingle" target="10">select10</div>
<div style="display: inline-block; margin-bottom: 0.4em" class="showSingle" target="11">select11</div>
<br><br>
<select name="usp-taxonomy-vertical[]" required="required" data-required="true" multiple="multiple" class="form-control" id="sel2">
<option value="665" selected="selected">665</option>
<option value="666">666</option>
<option value="667">667</option>
<option value="668">668</option>
<option value="669">669</option>
<option value="670">670</option>
<option value="671">671</option>
<option value="672">672</option>
<option value="673">673</option>
<option value="674">674</option>
<option value="675">675</option>
<option value="676">676</option>
</select>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
You need to use attribute of your link to select right option.
I used your target attribute to do it.
// Initialize at position 1
selectElement('665');
$('.showSingle').click(function() {
selectElement($(this).attr('target'));
})
function selectElement(target) {
console.clear();
console.log(target);
// we save current element in const
const currectSelectedElementTarget = $('#sel2 option[value="' + target + '"]');
// remove attr selected for all options in select #sel2
$("#sel2 > option").removeAttr("selected");
// we add selected class and attr to the current clicked element
currectSelectedElementTarget.addClass("selected").attr('selected', 'selected');
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div style="display: inline-block; margin-bottom: 0.4em;" class="showSingle greenactive" target="665">select1</div>
<div style="display: inline-block; margin-bottom: 0.4em" class="showSingle" target="666">select2</div>
<div style="display: inline-block; margin-bottom: 0.4em" class="showSingle" target="667">select3</div>
<br><br>
<select name="usp-taxonomy-vertical[]" required="required" data-required="true" multiple="multiple" class="form-control" id="sel2">
<option value="665">665</option>
<option value="666">666</option>
<option value="667">667</option>
</select>
well, your Jquery code is a bit wrong, you need to add the select values to the <a> (maybe in data attributes), then set a listener on <a> fields that will trigger a function to change the select value
the full code will be like this :
$(".href").click(function(){
$(".select_a").val($(this).attr('data-value')).change();
});
select1</div>
select2</div>
select3</div>
<br><br>
<select name="usp-taxonomy-vertical[]" required="required" data-required="true" multiple="multiple" class="form-control select_a" id="sel2">
<option value="665" selected="selected">665</option>
<option value="666">666</option>
<option value="667">667</option>
</select>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
I am using php and MySQL. When I submit the form data is not stored in the database table 'plantation_journal_nursery_details'. I am badly stuck here. Can anyone please advice me that how can I solve this problem?? Thanks in advance guys. codes are given below :
create_journal.php
<form action="data_fetch.php" action="post">
<div class="row">
<div class="col-sm-4">
<h4 style="font-size: 16px;padding-left: 15px;"><b>Nursery Location:</b></h4><br>
<div align="right" style="padding-right: 10px;">
<label style="font-weight:300;font-size: 15px">Location:</label>
<input type="text" name="location" id="location" style="width:50%;height: 30px; margin-left: 10px; border-radius: 5px;"><br>
<label style="font-weight:300;font-size: 15px">Area:</label>
<input type="text" name="area1" id="area1" style="width:50%;height: 30px; margin-left: 10px; border-radius: 5px;"><br>
<label style="font-weight:300;font-size: 15px">type of Nursey:</label>
<select name="type_of_nursery" id="type_of_nursery" style="width:50%;height: 30px; margin-left: 10px; border-radius: 5px;">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select><br><br>
<label style="font-weight:300;font-size: 15px">Centranl Nursery Name:</label>
<select name="central_nursery_name" id="central_nursery_name" style="width:40%;height: 30px; margin-left: 10px; border-radius: 5px;">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select><br><br>
<label style="font-weight:300;font-size: 15px">State Nursery Name:</label>
<input type="text" name="state_nursery_name" id="state_nursery_name" style="width:50%;height: 30px; margin-left: 10px; border-radius: 5px;"><br>
</div>
</div>
<div class="col-sm-4">
<h4 style="font-size: 16px;padding-left: 15px;"><b>Size of Each Bed:</b></h4><br>
<div align="right" style="padding-right: 10px;">
<label style="font-weight:300;font-size: 15px">Mother Bed Size:</label>
<input type="text" name="mother_bed_size" id="mother_bed_size" style="width:50%;height: 30px; margin-left: 10px; border-radius: 5px;"><br>
<label style="font-weight:300;font-size: 15px">Quantity:</label>
<input type="text" name="quantity_m" id="quantity_m" style="width:50%;height: 30px; margin-left: 10px; border-radius: 5px;"><br><br><br>
<label style="font-weight:300;font-size: 15px">Source of Seed:</label>
<select name="source_of_seed" id="source_of_seed" style="width:50%;height: 30px; margin-left: 10px; border-radius: 5px;">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select><br><br>
</div>
</div>
<div class="col-sm-4">
<div align="right" style="padding-right: 10px; padding-top: 40px">
<label style="font-weight:300;font-size: 15px">Polypot Bed Size:</label>
<input type="text" name="polypot_bed_size" id="polypot_bed_size" style="width:42%;height: 30px; margin-left: 4px; border-radius: 5px;"><br>
<label style="font-weight:300;font-size: 15px">Quantity:</label>
<input type="text" name="quantity_p" id="quantity_p" style="width:42%;height: 30px; margin-left: 4px; border-radius: 5px;"><br><br>
<label style="font-weight:300;font-size: 15px">Hycopot Bed Size:</label>
<input type="text" name="hycopot_bed_size" id="hycopot_bed_size" style="width:42%;height: 30px; margin-left: 4px; border-radius: 5px;"><br>
<label style="font-weight:300;font-size: 15px">Quantity:</label>
<input type="text" name="quantity_h" id="quantity_h" style="width:42%;height: 30px; margin-left: 4px; border-radius: 5px;"><br>
</div>
</div>
</div>
<div class="row">
<div align="right" style="padding-right: 10px;">
<input class="btn btn-info" type="submit" name="submit16" value="Add" onclick="move7()">
</div>
</div>
</form>
data_fetch.php
<?php
$con=mysqli_connect("localhost","root","","forestdb");
if(isset($_POST['submit16'])){
$location=$_POST['location'];
$area1=$_POST['area1'];
$type_of_nursery=$_POST['type_of_nursery'];
$central_nursery_name=$_POST['central_nursery_name'];
$state_nursery_name=$_POST['state_nursery_name'];
$mother_bed_size=$_POST['mother_bed_size'];
$quantity_m=$_POST['quantity_m'];
$source_of_seed=$_POST['source_of_seed'];
$polypot_bed_size=$_POST['polypot_bed_size'];
$quantity_p=$_POST['quantity_p'];
$hycopot_bed_size=$_POST['hycopot_bed_size'];
$quantity_h=$_POST['quantity_h'];
$query="SELECT plantation_journal_no from plantation_journal_basic_details where plantation_journal_no=(select max(plantation_journal_no) from plantation_journal_basic_details);";
$res=mysqli_query($con,$query);
$row=mysqli_fetch_assoc($res);
$plantation_journal_no=$row['plantation_journal_no'];
$sql="INSERT INTO `plantation_journal_nursery_details`(`plantation_journal_no`, `location`, `area`, `type_of_nursery`, `central_nursery_name`, `state_nursery_name`, `mother_bed_size`, `quantity`, `source_of_seed`, `polypot_bed_size`, `quantity_p`, `hycopot_bed_size`, `quantity_h`) VALUES ('$plantation_journal_no','$location','$area1','$type_of_nursery','$central_nursery_name','$central_nursery_name','$mother_bed_size','$quantity_m','$source_of_seed','$polypot_bed_size','$quantity_p','$hycopot_bed_size','$quantity_h');";
$result=mysqli_query($con,$sql);
if($result){
echo "<script>alert('data submitted.');</script>";
header("Location:create_journal.php");
}
}
?>
Your insert query, before you edited your question, contained ...
...VALUES ('$plantation_journal_no',$configurarion','$slope','$water_table_in_...
Notice that your single quotes aren't matched. You should have
...VALUES ('$plantation_journal_no','$configurarion','$slope','$water_table_in_...
If you had checked for an error in your query you would have found this problem immediately. Code like this would have helped.
if($result){
echo "<script>alert('data submitted.');</script>";
header("Location:create_journal.php");
}
else {
die $mysqli->error;
}
Pro tip: Format your code so you don't have to scroll horizontally to see entire queries. It's far easier to examine your queries and find mistakes that way. You can use php's heredoc syntax for string constants to do that.
This is how it looks.
$sql= <<<INSERTQUERY
INSERT INTO `plantation_journal_nursery_details`
(`plantation_journal_no`, `location`, `area`, `type_of_nursery`,
`central_nursery_name`, `state_nursery_name`, `mother_bed_size`,
`quantity`, `source_of_seed`, `polypot_bed_size`, `quantity_p`,
`hycopot_bed_size`, `quantity_h`)
VALUES
('$plantation_journal_no','$location','$area1','$type_of_nursery',
'$central_nursery_name','$central_nursery_name','$mother_bed_size',
'$quantity_m','$source_of_seed','$polypot_bed_size','$quantity_p',
'$hycopot_bed_size','$quantity_h');
INSERTQUERY;
I am new to php.
And i am using following code to show a form
<div class="wrapperReg">
<div id="searchContainer" style="display: inline; margin-top: 20px">
<form>
<label class="ringSetName" style="font-size: 16pt;" >Firstname</label>
<input id="nameBox" style="width:250px; margin-top:10px; margin-left: 30px; height:30px;" name="q" type="text"/>
</form>
</div>
<div id="searchContainer" style="display: inline; margin-top: 20px">
<form>
<label class="ringSetName" style="font-size: 16pt;" >Lastname</label>
<input id="nameBox" style="width:250px; margin-top:10px; margin-left: 30px; height:30px;" name="q" type="text"/>
</form>
</div>
<div id="searchContainer" style="display: inline; margin-top: 20px">
<form>
<label class="ringSetName" style="font-size: 16pt;" >Email</label>
<input id="nameBox" style="width:250px; margin-top:10px; margin-left:30px; height:30px;" name="q" type="text"/>
</form>
</div>
<div id="searchContainer" style="display: inline; margin-top: 20px">
<form>
<label class="ringSetName" style="font-size: 16pt;" >Phone</label>
<input id="nameBox" style="width:250px; margin-top:10px; margin-left: 30px; height:30px;" name="q" type="text"/>
</form>
</div>
<div class="submit" style="display: inline;" style="margin-top: 10px">
<input type="button" value="Submit" class="submit-text"/>
</div>
CSS is as follow
.wrapperReg{
overflow: hidden;
width: 100%;
height: 100%;
}
It is showing stuff as below
How can i align so that all the elements are aligned horizontally inside the main div and The Text should be base aligned and also the Input fileds be vertically aligned to each.
Also Need to place the submit button aligned horizontally too.
How about using float?
label{float: left;}
label + input{float: right;}
And add overflow:hidden to your form. And wrap your form elements in one form.
label {float: left; width: 200px; clear: left}
label + input {float: left; width: 150px}
ID should be unique in whole document, use class for searchContainer.
I am having trouble with the webpage in php that I'm trying to make. The 2 divs inside the main div kept getting wrapped. I am trying to arrange it in a way that the rifleman blue is on the left and the rifleman red is on the right of the page since the user will be comparing both riflemen's stats. I am not good with CSS but will push myself if it's the only solution since my neck already hurts so bad and still couldn't find a way to do this. My target browsers are just FF and Chrome. I need a way to make 2 displayed in one line on the page and not make the 2nd div below the 1st div.
<?php
$profpic = "darkbg.jpg";
?>
<html>
<style type="text/css">
body {
background-image: url('<?php echo $profpic;?>');
}
</style>
<body>
<img src="headergiflong.gif" style="width:100%;height:30%;"><br>
<div>
<div style="display:inline;width:200;height:300;background-color:blue;">
<select id="comparea">
<option value="rifleman.php">Rifleman</option>
<option value="mortarman.php">Mortarman</option>
<option value="machinegunner.php">Machine Gunner</option>
<option value="javelin.php">Javelin</option>
</select>
<br>
<iframe id="compare1" style="background-color:black; color:white; border:0;" src="rifleman.php" width="45%" height="300"></iframe>
</div>
<br>
<div style="display:inline;width:200;height:300;background-color:red;">
<select id="compareb">
<option value="rifleman.php">Rifleman</option>
<option value="mortarman.php">Mortarman</option>
<option value="machinegunner.php">Machine Gunner</option>
<option value="javelin.php">Javelin</option>
</select>
<br>
<iframe id="compare2" style="background-color:black; color:white; border:0;" src="rifleman.php" width="45%" height="300"></iframe>
</div>
</div>
</body>
</html>
try this
<?php
$profpic = "darkbg.jpg";
?>
<html>
<style type="text/css">
body {
background-image: url('<?php echo $profpic;?>');
}
</style>
<body>
<img src="headergiflong.gif" style="width:100%;height:30%;"><br>
<div style="width: 100%; max-width: 960px;">
<div style="width: 50%; float: left; background-color:blue;">
<select id="comparea">
<option value="rifleman.php">Rifleman</option>
<option value="mortarman.php">Mortarman</option>
<option value="machinegunner.php">Machine Gunner</option>
<option value="javelin.php">Javelin</option>
</select>
<br>
<iframe id="compare1" style="background-color:black; color:white; border:0;" src="rifleman.php" width="100%" height="300"></iframe>
</div>
<div style="width: 50%; float: left; background-color:red;">
<select id="compareb">
<option value="rifleman.php">Rifleman</option>
<option value="mortarman.php">Mortarman</option>
<option value="machinegunner.php">Machine Gunner</option>
<option value="javelin.php">Javelin</option>
</select>
<br>
<iframe id="compare2" style="background-color:black; color:white; border:0;" src="rifleman.php" width="100%" height="300"></iframe>
</div>
<div style="clear: both;"></div>
</div>
</body>
</html>
Change:
<body>
<img src="headergiflong.gif" style="width:100%;height:30%;"><br>
<div>
To:
<body>
<img src="headergiflong.gif" style="width:100%;height:30%;"><br>
<div style='width:400px;overflow:hidden;'>
The basic issue is that the two items are set to display inline, with a fixed width of 200px - therefore if the available space is less than 400px, they will wrap to a new line. By setting the width of the parent container to 400px, it ensures the children will have the minimum width available in order to display on the same line.
Your alternatives would be either to float the two elements, or to use display:table
SEE THIS FIDDLE
..for the three different approaches you can use.
give iframe width as 100% for both divs...
and for left div give style as
float:left;
width:49%;
for right div give style as
float:right;
width:49%;
I have no experience with php at all. Some html, some javascript, but that is it.
All I want to do is have a drop-down list for database connections and then based on that connect to the database chosen. Simple enough but I can't seem to get the select option value. I've gone down a huge rat hole trying to figure this out. everything points me to isset($_POST['somevariable']) to get the value but I think I'm missing something key. Do i need to be using the form tag or something. no matter what I do, I can't get at the variable. Also, can I just do this all in one php script? other posts have multiple php scripts. I ended up adding a submit button to see if that is it... I just am coming up empty.. I'm missing something really dumb...
Here is my code:
<html>
<head>
<title>Liferay Utilities</title>
<style>
.label {
font-weight: bold;
margin: 10px 20px 10px 0;
float: left;
clear: left;
width: 200px;
}
.element {
margin: 10px 0;
width: 150px;
float: left;
}
</style>
</head>
<body>
<h1>Liferay Utilities</h1>
<hr style="border-bottom: #cac917 5px solid;" />
<p class="label">Choose Database:</p>
<select name="dbtype">
<option value="default">Select Database</option>
<option value="suntest">SUNTEST</option>
<option value="sundevo">SUNDEVO</option>
</select>
<input type="submit" name="submit" value="Next">
</p>
<?php
//just debugging
echo 'xx';
echo isset($_POST['submit']);
echo 'xx';
if (isset($_POST['dbtype']))
{
// I NEVER EVER GET IN HERE
echo 'in here';
}
?>
</body>
</html>
Any Help would be greatly appreciated.
HERE IS MY NEW CODE: IT WORKS NOW!!! Thank you all! Wish I had posted an hour ago... If there are any good websites out there were full examples and real-world ones, let me know.
<html>
<head>
<title>Liferay Utilities</title>
<style>
.label {
font-weight: bold;
margin: 10px 20px 10px 0;
float: left;
clear: left;
width: 200px;
}
.element {
margin: 10px 0;
width: 150px;
float: left;
}
</style>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<h1>Liferay Utilities</h1>
<hr style="border-bottom: #cac917 5px solid;" />
<p class="label">Choose Database:</p>
<select name="dbtype">
<option value="default">Select Database</option>
<option value="suntest">SUNTEST</option>
<option value="sundevo">SUNDEVO</option>
</select>
<input type="submit" name="submit" value="Next">
</p>
<?php
echo $_SERVER['PHP_SELF'];
//just debugging
echo 'xx';
echo isset($_POST['submit']);
echo 'xx';
if (isset($_POST['dbtype']))
{
// I NEVER EVER GET IN HERE
echo 'in here';
}
?>
</form>
</body>
</html>
Try:
<form action="page.php" method="post">
<select name="dbtype">
<option value="default">Select Database</option>
<option value="suntest">SUNTEST</option>
<option value="sundevo">SUNDEVO</option>
</select>
<input type="submit" name="submit" value="Next">
</form>
in your php do echo $_POST["dbtype"]; to see if you get the correct result.
Change page.php for the name of the page you are submitting the form to.
You not defining the method. At the very least you must have that in order to use $_POST. To do that you must wrap your input/select in a form
<form method="post">
<select name="dbtype">
<option value="default">Select Database</option>
<option value="suntest">SUNTEST</option>
<option value="sundevo">SUNDEVO</option>
</select>
<input type="submit" name="submit" value="Next">
</form>
Note: Without giving an action attribute, the action will become the current page.