First Form not displayed being in loop while others display - php

I am working on an existing application. I am encountering a strang issue. Here is my loop.
<tbody>
<?php if($results->num_rows > 0 ): ?>
<?php foreach ($results->result() as $row1): ?>
<tr>
<td class="td_data"><?php echo $row1->customer_name; ?></td>
<td class="td_data"><?php echo $row1->postcode; ?> </td>
<td class="td_data"><?php echo $row1->company; ?></td>
<td class="td_data"><?php echo $row1->enquiry_status; ?></td>
<td class="td_data"><?php echo $row1->form_source; ?></td>
<td class="td_data"><?php echo anchor('customer/edit/' . $row1->customer_id, 'Edit'); ?></td>
<td class="td_data">
Login
<?php $action = $this->config->item('front_site_url').'members/login';?>
<form id="member_login<?php echo $row1->customer_id?>" action="<?php echo $action;?>" method="post" >
<input type="hidden" name="username" value="<?php echo $row1->username?>"/>
<input type="hidden" name="password" value="<?php echo $row1->password?>"/>
<input type="hidden" name="submitted" value="yes" />
</form>
<script type="text/javascript">
$('#member_login_link<?php echo $row1->customer_id?>').click(function(){
$('#member_login<?php echo $row1->customer_id?>').submit();
});
</script>
</td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td class="td_data">No Record Found</td>
</tr>
<?php endif; ?>
</tbody>
This creates a list. And inspecting element displays this.
Here is the result of firebug which is fine on all the elements except the first.
And here is the first row result
I am unable to understand why this is happening. I have checked on different browsers and all have same issue.
EDITS:
This list that is being generate has form in each row. clicking on Login opens a tabs and asks for username and password. But the first row does not have form tags so it is not opening tag.

I have found the issue. A form closing tag was not written in header for Search functionality. so it was picking the first form closing tag and the form opening tag in the list was left to be hanged so it was not working.

Use empty form tag before main form tag inside foreach loop, then first empty form tag will be removed by foreach loop and functionality will work fine.
For example:
<div>
<form></form>
<form id="member_login<?php echo $row1->customer_id?>" action="<?php echo $action;?>" method="post" >
<input type="hidden" name="username" value="<?php echo $row1->username?>"/>
<input type="hidden" name="password" value="<?php echo $row1->password?>"/>
<input type="hidden" name="submitted" value="yes" />
</form>
</div>

Related

How to add identifier to table row submit button

I am currently trying to build a booking system for a theatre. I have 5 different productions which are found from my database with a query in php.
I have a table showing the productions and their associated ticket price. Each row states the production, ticket price and a submit button (using $_POST) to choose that production.
I am trying to send the title of the selected production as production_'production title'. e.g. if hamlet was selected I would retrieve the selection using $_POST['production_hamlet'].
However I do not know how to replace the title of each production found in the query when retrieving the POST.
e.g. on the next page when echoing out to see if it's submitted I don't know what to write after echo $POST['production.....'].
Here is my code:
<form method="post" action="choose_performance.php">
<table name="choose_performance">
<thead id="td">
<tr>
<td>Production</td>
<td>Basic Ticket Price</td>
<td>Select</td>
</tr>
<thead>
<tbody>
<?php
$production_set = find_productions();
while($row = mysqli_fetch_assoc($production_set)){?>
<tr>
<td><?php echo $row['Title']?>
<input type="hidden" name="<?php echo "production_".$row['Title']?>" value="<?php echo $row['Title']?>" />
</td>
<td><?php echo $row['BasicTicketPrice'];?>
<input type="hidden" name="<?php echo "price_".$row['Title']?>" value="<?php echo $row['BasicTicketPrice']?>" />
</td>
<td>
<input type="submit" name="submit" value="Submit"
onclick='alert("Thank you for your selection. Please choose your preferred performance time and date on the next page.");'>
</td>
</tr>
<?php
}
?>
</form>
Any advice on how to retrieve the POST would be amazing.
Thanks.
Just put the <form> tag inside your while loop so that each row has its own form for submission. This way, when the form is submitted, you only have 2 posted params (production & price). See below:
<tr>
<td>
<?php echo $row[ 'Title']?>
</td>
<td>
<?php echo $row[ 'BasicTicketPrice'];?>
</td>
<td>
<form method="post" action="choose_performance.php">
<input type="hidden" name="production" value="<?php echo $row['Title'] ?>" />
<input type="hidden" name="price" value="<?php echo $row['BasicTicketPrice'] ?>" />
<input type="submit" name="submit" value="Submit" onclick='alert("Thank you for your selection. Please choose your preferred performance time and date on the next page.");'>
</form>
</td>
</tr>

Update MYSQL with PHP, deletes value instead

So, I have the following problem:
I have a table which I fill with the data from my MySQL database and then display on a site. I want to make it so you can change e.g. the description afterwards. Instead what I get right now is that I empty the value.
I can't see where my code goes wrong, so I'd appreciate some help. :)
HTML
<tbody>
<?php
foreach($records as $r) {
?>
<tr><?php
echo "<td>" . "<div class=table-image>" . "<img src=Assets/Images/" . escape($r->name) . " </td>". "</div>";
?>
<td><div class="data"><?php echo escape($r->name); ?></div></td>
<td><div class="data"><?php echo escape($r->location); ?></div></td>
<td><div class="data"><?php echo escape($r->partners); ?></div></td>
<td>◈ Google Maps</td>
<td class="tDesc">
<div class="desc">
<input class="form-control" value="<? echo escape($r->description); ?>" name="description" type="text">
</div>
</td>
<td>
<?php echo escape($r->date); ?>
</td>
<td>
<form method="post" action="" enctype="multipart/form-data">
<input type="submit" value="<? echo escape($r->id); ?>" name="delete">
</form>
</td>
<td>
<form method="post" action="" enctype="multipart/form-data">
<input type="submit" value="<? echo escape($r->id); ?>" name="update">
</form>
</td>
</tr>
<?php
}
?>
</tbody>
PHP
if(isset($_POST['update']) ){
$des = $_POST['description'];
$UpdateQuery = "UPDATE repo SET description = '$des', date = NOW() WHERE id ='$_POST[update]' ";
mysql_query($UpdateQuery);
};
Your fields are outside the form, only fields inside the form will be send.
<input name="i_will_not_be_send" />
<form>
<input name="i_will_be_send" />
</form>
Always escape values you put into your query string, see mysql_real_escape_string
Also read the comments about using the correct mysql library

Display current value of item in the form input field

I am looking to display the current value of the NumberedEntered value in the input box.
Currently it will only display the current value when I click submit then refresh. Does anyone know how I can echo it back as soon as I click submit?
Thanks.
<?php foreach($users as $user) : ?>
<tr>
<form action "index.php" method "post" name='form1'>
<td align="center" width="40%" ><?php echo $user['FullName']; ?><input type="hidden" Name="FullName" value="<?php echo $user['FullName']; ?>" /></td>
<td width="30%"><input type="number" name="NumberedEntered" value="<?php echo $user['NumberedEntered']; ?>" /></td>
<td><input type="submit" value="submit"></td>
</form>
</tr>
<?php endforeach; ?>

How can i use GET METHOD on wordpress plugin admin page

I am building a custom plugin which i plan to sell, but i am having problem storing my get request values in the plugin URL.
I have this URL:
/wp-admin/admin.php?page=step-one&filename=Styles_For_Less-Styles_For_Less_Product_Catalog.txt
and when the submit button on that page is clicked it should go to page with this URL:
/wp-admin/admin.php?page=step-two&filename=Styles_For_Less-Styles_For_Less_Product_Catalog.txt&header=0&delimiter=%7C&quoted=&step2=Step+2+%3E%3E
But i doesn't instead it goes here:
/wp-admin/admin.php?header=1&delimiter=%2C&quoted=&step2=Step+2+%3E%3E
<form method="GET" action="<?php echo admin_url( "admin.php?page=step-two&filename=$filename&", "http" ); ?>">
<table border="1" cellpadding="4">
<tr>
<td>Header Row:</td>
<td><?php echo $header; ?> </td>
</tr>
<tr>
<td>Delimiter:</td>
<td><?php echo $delimiter; ?> </td>
</tr>
<tr>
<td>Quoted:</td>
<td><?php echo $quoted; ?> </td>
</tr>
</table>
<p><input type="submit" value="Step 2 >>" name="step2">
<input type="reset" value="Reset" name="B2"></p>
</form>
Any help greatly appreciated.
Instead of appending data in the action url, try creating hidden form inputs.
<form method="GET" action="<?php echo admin_url( 'admin.php'); ?>">
<input type="hidden" name="page" value="step-two" />
<input type="hidden" name="filename" value="<?php echo $filename; ?>" />
<table border="1" cellpadding="4">
// ... rest of the form

pass relevant hidden field values from the form to the controller

Im having a page that shows monthly subscriptions of a user which is created using codeigniter. what i want to do is when a the user clicks on make payment pass the values in the hidden files to the controller.
<?php echo form_open('options/done');?>
<table class="tables">
<thead>
<tr>
<th>Ref Code</th>
<th>Month</th>
<th>Year</th>
<th>action/th>
</tr>
</thead>
<tbody>
<?php foreach ($payments as $s =>$payment):?>
<?php $month = $payment['month'];?>
<input type="hidden" value="<?php echo $month;?>" name="month_<?php echo $s;?>" />
<input type="hidden" value="<?php echo $payment['ref_code'];?>" name="ref_<?php echo $s;?>" />
<tr>
<td><?php echo $payment['ref_code'];?></td>
<td><?php echo $month;?></td>
<td><?php echo $payment['year'];?></td>
<td><input type="submit" value="MAKE PAYMENT" class="red" /></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php echo form_close();?>
so when someone hits the submit button how can i pass only the hidden values which are relevant to that table row?
add form just inside the <tr> elements inside your loop (see below with your code)
<?php foreach ($payments as $s =>$payment):?>
<?php $month = $payment['month'];
?>
<tr>
<form action="target.php" method="post" name="formName_<?php echo $s;?>" >
<input type="hidden" value="<?php echo $month;?>" name="month_<?php echo $s;?>" />
<input type="hidden" value="<?php echo $payment['ref_code'];?>" name="ref_<?php echo $s;?>" />
<td><?php echo $payment['ref_code'];?></td>
<td><?php echo $month;?></td>
<td><?php echo $payment['year'];?></td>
<td><input type="submit" value="MAKE PAYMENT" class="red" /></td>
</form>
</tr>
<?php endforeach; ?>

Categories