I have try to fix this simple web pages.
I make a table from this file :
*$SY100 $L01$F001$T001$B00000010$I001$G00101$R00000000$O01$NPATCH KABEL ORA 2M $
*$SY101 $L01$F001$T001$B00000018$I001$G00101$R00000000$O01$NLASTBARARE SVART $
*$SY102 $L01$F001$T003$B00000012$I001$G00101$R00000000$O01$NPATH KABEL GRA 1M $
*$SY103 $L01$F001$T004$B00000006$I001$G00101$R00000000$O01$NATERSTALL KNAPP $
and want to use a text field to get a "quantity" how how do I get it this rows in the post command?
<?php
echo "<form action='' method='post'>";
echo "<table>
<tr>
<th scope='col' >Art No</th>
<th scope='col' >Avalible Quantity</th>
<th scope='col' >Quantity</th>
</tr>";
$file1 = "/srv/ftp/inBox/amdbackup.amd";
$lines = file($file1);
foreach($lines as $line_num => $line){
$rows = explode("\$",$line);
$article_no = substr ($rows['1'],1);
$avalible_quantity = ltrim (substr ($rows['5'],1),0);
echo "<tr>";
echo "<td>" . $article_no . "</td>";
echo "<td>" . $avalible_quantity . "</td>";
echo "<td>" . "<input size='2' type='text'></input>" . "</td>";
echo "</tr>";
}
echo "</table>";
echo "<input name='add' type='submit'><br>";
echo "</form>";
if (IsSet($_POST['add'])) {
$art_no=$_POST['id'];
$quantity=$_POST['q'];
echo "art_no" . $art_no;
echo "</br>";
echo "quantity" . $quantity;
echo "</br>";
Well, i think my previous answer was incorrect. Also, I don't see any fields named id or q in your form.
You might want to replace
<input size='2' type='text'></input>
with
<input size='2' type='text' name='q' />
Though you will have to add another field for id
Related
I need to get the data of the database to an HTML table.
There were similar questions asked before but none of them were similar to my requirement.
I need to get the first row of the database to the first row of the table.
So I did this.
echo "<table id='main-table' border='1px solid'> <thead> ";
echo "<tr>";
echo "<th>Board No</th>";
echo "<th>Number</th>";
echo "</tr></thead><tbody>";
while($query->fetch()){
echo "<form action='' class='' method='post'><tr>";
line 55 --> echo "<td>" . Board Code:".$row["board_code"] . Number:".$row["status"] . "</td>";
echo "</tr> </form>";
}//End of While
echo "</tbody></table>";
There is a syntax error in line 55 as mentioned above in the code.
Check this code:
echo "<table id='main-table' border='1px solid'> <thead> ";
echo "<tr>";
echo "<th>Board No</th>";
echo "<th>Number</th>";
echo "</tr></thead><tbody>";
while($query->fetch()){
echo "<form action='' class='' method='post'><tr>";
echo "<td> Board Code:".$row["board_code"]. "</td>";
echo "<td>Number:".$row["status"]. "</td>";
echo "</tr> </form>";
}
echo "</tbody></table>";
"<td>" . Board Code:".$row["board_code"] ." Number:".$row["status"] . "</td>";
edit your code like if it does not work please share your whole code will help you for sure
Check with this code
echo "<form action='' class='' method='post'><tr>";
line 55 --> echo "<td>" . Board Code:".$row["board_code"] ." Number:".$row["status"] . "</td>";
echo "</tr> </form>";
I have a form which displays stock levels and I want the user to be able to delete multiple products so have provided checkboxes. the code is below:
echo "<form method='get'>
<input type='submit' name='removestock' value= 'Remove'>
<table class='display' border='0'>
<tr>
<th>Select</th>
<th>Name</th>
<th>Description</th>
<th>Price (£)</th>
<th>Quantity</th>
<th>Size</th>
</tr>";
echo "<tr>";
require ('connection.php');
$query = mysql_query("SELECT * FROM items")or die(mysql_error());
while($results = mysql_fetch_array($query)){
echo "<td> <input type='checkbox' name='item' value='".$results['item_id']."'></td>";
echo "<td>" . $results['name'] . "</td>";
echo "<td>" . $results['description'] . "</td>";
echo "<td>" . $results['price'] . "</td>";
echo "<td>" . $results['quantity'] . "</td>";
echo "<td>" . $results['size_id'] . "</td>";
echo "</tr>";
}
echo "</table></form>";
And my parsing code is...
if(isset($_GET['removestock']) === true){
$errors = array();
$items = $_GET['item'];
echo $items;
}
But for some reason it only displays the last item_id selected. Your help will be much appreciated!
PS. I tried changing the checkbox name to name="items[]" and implemented a foreach loop to parse the data but it still did not work.
The name of the checkbox should be
<input type='checkbox' name='item[]' value='".$results['item_id']."'>
This wil give you an array which you can read with a foreach
Use name=item [] for the checkboxes. This will give you the array.
Then use var_export ($ items)
Change this line:
"<td> <input type='checkbox' name='item' value='".$results['item_id']."'></td>";
To read:
"<td> <input type='checkbox' name='item[" . $results['item_id'] . "]'></td>";
And you will get your desired array in the variable.
This always works for me:
$i =0;
while($results = mysql_fetch_array($query)){
echo "<td> <input type='checkbox' name='item[".$i."]' value='".$results['item_id']."'></td>";
echo "<td>" . $results['name'] . "</td>";
echo "<td>" . $results['description'] . "</td>";
echo "<td>" . $results['price'] . "</td>";
echo "<td>" . $results['quantity'] . "</td>";
echo "<td>" . $results['size_id'] . "</td>";
echo "</tr>";
$i++;
}
Once posted, the item[] element will be an array.
t
I have data shown about a band that matches a id selected, im then using the band_id and getting it to use it else where.
I would like to do the same with Name field but I am having a few problems, its just getting the word array in to the var $name.
code
<?php
require 'core/init.php';
$Band_id = $_GET['id'];
$name = ['Name']; // trying to get the band name
$result = mysql_query("SELECT * FROM bands WHERE Band_id = $Band_id");
echo "<table border = '1'>
<tr>
<th>Band Name</th>
<th>Venue</th>
<th>Category</th>
<th>Stock</th>
<th>Buy Ticket</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr><form name=\"myform\" action=\" order.php\" method=\"post\">";
echo " <input name=\"band\" type=\"hidden\" value=\"". $Band_id."\" >";
echo " <input name=\"bandn\" type=\"hidden\" value=\"". $name."\" >";
echo "<td>" .$row['Name']. "</td>";
echo "<td>" .$row['Venue']. "</td>";
echo "<td>" .$row['Category']. "</td>";
echo "<td>" .$row['Stock']. "</td>";
echo "<td><button>Buy Ticket</button></td>";
echo "</tr> </form>";
}
echo "</table>";
?>
$name = ['Name'] wont work above the query, and generally wont work at all as its invalid syntax for what you're trying to do. Where you have used $name use $row['Name']
I am generating radio buttons dynamically by PHP but it is not working .I am not able to uncheck a radio button once checked and once I select the other radio button with same name other is not automaticaly unchecked .
echo "<form action="."".">";
echo "<table border='1'>
<tr>
<th>Reg Num</th>
<th>Select</th>
<th>Reject</th>
</tr>";
/* <th>Name</th>
<th>State</th>
<th>Constituency</th> */
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
// echo "<td>" . $row['voter_id'] . "</td>";
// echo "<td>" . $row['name'] . "</td>";
// echo "<td>" . $row['state'] . "</td>";
// echo "<td>" . $row['constituency'] . "</td>";
echo "<td>" . $row['numreg'] . "</td>";
echo "<td><input type="."radio"." name=".$row['voter_id']. "value="."1"."></td>";
echo "<td><input type="."radio"." name=".$row['voter_id'] ."value="."2"."></td>";
echo "</tr>";
}
echo "</table>";
echo "</form>";
try following
echo "<form action=''>";
echo "<table border='1'>
<tr>
<th>Reg Num</th>
<th>Select</th>
<th>Reject</th>
</tr>";
/* <th>Name</th>
<th>State</th>
<th>Constituency</th> */
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
// echo "<td> $row['voter_id']</td>";
// echo "<td>" . $row['name'] . "</td>";
// echo "<td>" . $row['state'] . "</td>";
// echo "<td>" . $row['constituency'] . "</td>";
echo "<td>" . $row['numreg'] . "</td>";
echo "<td><input type='radio' name='voter_id' value='$row[voter_id]'></td>";
echo "<td><input type='radio' name='voter_id' value='$row[voter_id]'></td>";
echo "</tr>";
}
echo "</table>";
echo "</form>";
For that the name of your radio button must be same.Change your code like the following inside the while loop where you are creating the radio buttons
echo '<td><input type="radio" name="voter_id" id="'.$row["voter_id"]. '"value="1"></td>';
echo '<td><input type="radio" name="voter_id" id="'.$row["voter_id"] .'"value="2"></td>';
We dont need double quotes for the type.Try like
echo "<td><input type='radio' name='".$row['voter_id']. "' value='1' "></td>";
Finally I did this and it worked
echo '<td><input type="radio" name="'.$row["voter_id"]. '"value="1"></td>';
echo '<td><input type="radio" name="'.$row["voter_id"] .'"value="2"></td>';
I am trying to retrieve records from db and put them into a table. I want to have an update button which can do some processing. Here is the code. It outputs properly. However the update button (image) doesn't work. Please help
<?php
echo "</br>";
echo "<table border='1'>
<tr>
<th>Order ID</th>
<th>Customer Number</th>
<th>Order Items</th>
<th>Transaction Time</th>
<th>Amount</th>
</tr>";
$con = mysql_connect('localhost', 'root', '');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("kaka", $con);
$sql="SELECT * FROM orders WHERE status = 'NRDY'";
$result2 = mysql_query($sql);
while($row1 = mysql_fetch_array($result2))
{
echo "<div class=\"update\"><form method='post' action=\"test.php\">\n";
echo "<tr>";
echo "<td><input type='hidden' name='order_id' value='".$row1['order_id']."'>" .$row1['order_id']. "</td>";
echo "<td><input type='hidden' name='cust_num' value='".$row1['cust_num']."'>" .$row1['cust_num']. "</td>";
echo "<td><input type='hidden' name='items' value='".$row1['items']."'>" .$row1['items']. "</td>";
echo "<td><input type='hidden' name='order_time' value='".$row1['order_time']."'>" .$row1['order_time']. "</td>";
echo "<td><input type='hidden' name='order_id' value='".$row1['amount']."'>" .$row1['amount']. "</td>";
//echo "<td>" . $row1['order_id'] . "</td>";
//echo "<td>" . $row1['cust_num'] . "</td>";
//echo "<td>" . $row1['items'] . "</td>";
//echo "<td>" . $row1['order_time'] . "</td>";
//echo "<td>" . $row1['amount'] . "</td>";
echo "<td>" . "<input type=\"image\" src=\"images/update.png\" alt=\"Update Row\" class=\"update\" title=\"Update Row\">\n" . "</td>";
echo "</tr>";
echo "</form></div>";
}
echo "</table>";
?>
Here is test.php
<?php
echo $_POST['order_id'];
?>
Use a validator. You aren't allowed to wrap divs or forms around table rows. Some browsers recover from this error by moving the div/form so it is outside the table (leaving the content behind). Your inputs are therefore not inside a form so shouldn't be expected to do anything.