PHP echo ID and Pop Up form - php

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?

Related

How to pull id to the database with select option

Indeed my question is easy. when i changed "option", i must pull its id. Maybe it can work javascript. But i don't know javascript.
<h4><u> Upload Image </u></h4>
<form action="a.php" method="post" enctype="multipart/form-data">
<label style="font-size:16px;" for="selectalbum">Select Album</label>
<select style="margin-left:10px;" name="selectalbum">
<?php
$imagequery=$db->prepare("SELECT * FROM imagealbum");
$imagequery->execute(array());
$imgquery=$imagequery->fetchAll(PDO::FETCH_ASSOC);
foreach($imgquery as $imagealbum) {
?>
<option value="<?php echo $imagealbum['imagealbum_id']; ?>"><?php echo $imagealbum['imagealbum_name']; ?></option>
<?php } ?>
</select>
<br>
<input type="text" name="aaa" style="text-align:center;">
<br><br>
<input type="text" style="text-align:center;" value="<?php echo $imagealbum['imagealbum_id']; ?>">
<br><br>
<input type="file" name="files[]" value="Upload Image" />
<br>
<button style="margin-top:7px; width:90px; height:30px; background-color:green; color:#fff; border-radius:7px;" name="submit">Submit</button>
</form>
Try adding onchange event with a funcion that getId like this:
const getId = () => {
const album = document.querySelector('#albums');
const log = document.querySelector('#log');
log.innerHTML = ` Id: ${album.value}`;
}
window.onload = function() {
getId();
};
<label for="albums">Select Album:</label>
<select name="albums" id="albums" onchange="getId()">
<option value="123">Album 1</option>
<option value="321">Album 2</option>
<option value="159">Album 3</option>
</select>
<div id="log">
</div>

PHP Form Drop Down menu stills blank after I select an item

I am executing an form based on PHP on Windows, however after I select an item in the drop down menu, the text does not show up (even though it was selected properly, as I can verify in the database after clicking the insert button).
The form code:
<div id="janela_formulario">
<form action="inserir_transportadoras.php" method="post">
<input type="text" name="nometransportadora" placeholder="Nome da Transportadora">
<input type="text" name="endereco" placeholder="Endereço">
<input type="text" name="telefone" placeholder="Telefone">
<input type="text" name="cidade" placeholder="Cidade">
<select name="estados">
<?php
while($linha = mysqli_fetch_assoc($lista_estados)) {
?>
<option value="<?php echo $linha["estadoID"]; ?>">
<?php echo utf8_encode($linha["nome"]); ?>
</option>
<?php
}
?>
</select>
<input type="text" name="cep" placeholder="CEP">
<input type="text" name="cnpj" placeholder="CNPJ">
<input type="submit" value="inserir">
</form>
</div>
The dropdown menu PHP code:
<input type="text" name="cidade" placeholder="Cidade">
<select name="estados">
<?php
while($linha = mysqli_fetch_assoc($lista_estados)) {
?>
<option value="<?php echo $linha["estadoID"]; ?>">
<?php echo utf8_encode($linha["nome"]); ?>
</option>
<?php
}
?>
</select>
How can I solve it?
while($linha = mysqli_fetch_assoc($lista_estados)) {
echo '<option value="'. $linha["estadoID"] .'"> '.utf8_encode($linha["nome"]).' </option>';
}
Use above code instead of while loop
test by inspect HTML code. is this estadoID are printing properly if yes then test you are catching (estados) data properly

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.

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>

How to make multiple-form with single submit button and action with php

Rather inputing one by one for a class/lessen for a day, I'd like to input 10 forms at once.
The HTML is something like this.
All the form do the same thing, add start_time, finish_time and instructor in a database.
However I am not sure how to do this. And I am not sure if this HTML is correct or not.
Any inputs will be appreciated.
Thanks in advance.
HTML
<?php
$date = "2010-10-08";
?>
<form name="form1" method="post" action="inputform.php">
<!-- form 1 -->
<label for='start_time'>1. Start Time</label>
<input type="text" name="start_time" />
<label for='finish_time'>Finish Time</label>
<input type="text" name="finish_time" />
<label for='instructor'>Instructor</label>
<select name="instructor">
<option value="john">John</option>
<option value="mary">Mary</option>
<option value="jim">Jim</option>
</select>
<input type="hidden" name="date" value="<?php echo $date; ?>"/>
<div style="clear: both;"> </div>
<!-- form 2 -->
<label for='start_time'>2. Start Time</label>
<input type="text" name="start_time" />
<label for='finish_time'>Finish Time</label>
<input type="text" name="finish_time" />
<label for='instructor'>Instructor</label>
<select name="instructor">
<option value="john">John</option>
<option value="mary">Mary</option>
<option value="jim">Jim</option>
</select>
<input type="hidden" name="date" value="<?php echo $date; ?>"/>
<div style="clear: both;"> </div>
<!-- form 3 -->
<label for='start_time'>3. Start Time</label>
<input type="text" name="start_time" />
<label for='finish_time'>Finish Time</label>
<input type="text" name="finish_time" />
<label for='instructor'>Instructor</label>
<select name="instructor">
<option value="john">John</option>
<option value="mary">Mary</option>
<option value="jim">Jim</option>
</select>
<input type="hidden" name="date" value="<?php echo $date; ?>"/>
<div style="clear: both;"> </div>
<!-- form 4,5,6,7,8,9,10 -->
<input type="submit" name="submit" value="Submit" />
</form>
you cannot submit multiple forms at once.
only one form with the form specific method/action.
however what probably need are arrays.
you can do something like
<form ...>
<select name="instructor[]">
...
</select>
<select name="instructor[]">
...
</select>
then you will get an array posted which you can loop through.
just look at the structure by printing out $_POST like print_r($_POST); then you'll see

Categories