I'm generating this table from data passed back from my controller the issue I'm having is that in general the first record returned [ in this case Sephen C. Cox], the "add employee" button does not redirect me but for the rest of the records it works. Does anyone know the problem?
<fieldset id= "results">
<?php if (isset($results ) And count($results)) : ?>
<table id="box-table-a" summary="Employee Sheet">
<thead>
<tr>
<th scope="col">Employee</th>
<th scope="col">Salary</th>
<th scope="col">Bonus</th>
<th scope="col">Supervisor</th>
<th scope="col">Action</th>
</tr>
<?php foreach ($results as $result) : ?>
<tr>
//Primary key <?php echo $result['Employee_ID!'];?>
<td><span class="Employee_name"><?php echo $result['Employee']; ?> </span></td>
<td><span class="Salary"><?php echo $result['Salary']; ?> </span> </td>
<td><span class="Bonus"><?php echo $result['Bonus']; ?> </span> </td>
<td><span class="Supervisor_name"><?php echo $result['Supervisor']; ?> </span></td>
<form action="welcome.php" method="post"> <td><input type="submit" value="Add employee" name="submit[<?php echo $result['Employee_ID'] ?>]" > </td></form>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</thead>
<tbody>
</fieldset>
<form action="welcome.php" method="post">
<td>
<input type="submit" value="Add employee"
name="submit[<?php echo $result['Employee_ID'] ?>]" >
</td></form>
change to
<td>
<form action="welcome.php" method="post">
<input type="submit" value="Add employee"
name="submit[<?php echo $result['Employee_ID'] ?>]" >
</form>
Or even wrap the whole table into one form instead of putting new form into each row. See no any reason in your code why that could be needed
Edit:
Also, take a look at tools like Firebug (FF), Inspector in Chrome and Safary, Developer Tools, or how it is called, in IE. It was completely enough to open you page with one of those tools and notice that browser parsed your code not like you expected.
Related
I'm trying to send multiples values to a PHP form.
This is the form that I use to send values:
<form id="form1" name="form1" method="POST" action="../WSweb/Factura.php">
<table width="561" height="79" border="1">
<tr>
<td width="30%" height="32">ProductID</td>
<td width="30%" height="32">SKU</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_test1['ProductID']; ?>
<input
type="hidden"
name="Product[id][ProductID]"
value="<?php echo $row_test1['ProductID']; ?>"
/>
</td>
<td><?php echo $row_test1['SKU']; ?>
<input
type="hidden"
name="Product[id][SKU]"
value="<?php echo $row_test1['SKU']; ?>"
/>
</td>
</tr>
<?php } while ($row_test1 = mysqli_fetch_assoc($test1)); ?>
</table>
<input type="submit" value="Update" name="Facturar">
</form>
And this is the action file:
if(isset($_POST['Update']))
{
$ProductID=$_POST['Product'];
print_r(json_encode($ProductID));
}
The problem that I have is when I send multiple values, for example the below table:
ProductID SKU
103 WH004BI
137 VO007BI
I alway get this result:
{"id":{"ProductID":"137","SKU":"VO007BI"}}
When I actually want to get a result like this:
{"id":[{"ProductID":"103","SKU":"WH004BI"},{"ProductID":"137","SKU":"VO007BI"}]}
You're going to want to do something like this:
<form id="form1" name="form1" method="POST" action="../WSweb/Factura.php">
<table width="561" height="79" border="1">
<tr>
<td width="30%" height="32">ProductID</td>
<td width="30%" height="32">SKU</td>
</tr>
<?php $i = 0; ?>
<?php while ($row_test1 = mysqli_fetch_assoc($test1) { ?>
<tr>
<td>
<?php echo $row_test1['ProductID']; ?>
<input
type="hidden"
name="Product[id][<?= $i; ?>][ProductID]"
value="<?php echo $row_test1['ProductID']; ?>"
/>
</td>
<td>
<?php echo $row_test1['SKU']; ?>
<input
type="hidden"
name="Product[id][<?= $i; ?>][SKU]"
value="<?php echo $row_test1['SKU']; ?>"
/>
</td>
</tr>
<?php $i++; ?>
<?php } ?>
</table>
<input type="submit" value="Update" name="Facturar">
</form>
Note that I have put a $i = 0 at the start of the loop, and $i++ at the end of the loop.
Additionally, I have changed the names to the following:
name="Product[id][<?= $i; ?>][SKU]"
Which will prevent the issue you were having in the comment section regarding an ill-formed array.
here is only part of my code, the action does not well ...action. when i view in the google javascript tools i have an id in the action line
when i hit the submit button, nothing happens, its suppose to go to php/form.php with ID 28 in this instance
......
if (mysqli_num_rows($result))
{
while ($row = mysqli_fetch_assoc($result))
{
?>
<form name="form-list" method="post" action='php/form.php?id=<?php echo $row["id"]; ?>' >
<table>
<tr>
<td valign="top">
<label for="surname">Surname</label>
</td>
<td valign="top">
<?php echo $row["title"]; ?>
</td>
</tr>
<tr>
<td valign="top">
<label for="name">Id</label>
</td>
<td valign="top">
<input type="text" value='<?php echo $row["id"]; ?>' name="name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<input type="button" value="Submit" />
</td>
</tr>
<?php } } ?>
</table>
</form> .....
<input type="submit" value="Submit" />
The input type is not button it is submit.
The value attribute just changes the written text on the button but does not change it's behavior.
Note to the other answers:
Using POST is fine if he handles the request in the right way. In the given code example everything except the submit button works and is fine.
In this case the id is transmitted as a GET and all other values are submitted via POST. You can mix them.
Later you do have to use $_GET["id"] and $_POST["name"].. or you can even use $_REQUEST["..."] for all of them.
I have retrieved data from my table and displayed them using the code below.
<?php require_once('../Connections/bidco.php'); ?>
<body>
<table width="671" height="43" border="1" align="center">
<table width="781" height="190" align="center">
<tr>
<td height="61" colspan="4"><div align="center"><strong> Inventory </strong></div></td>
</tr>
<tr>
<td width="77" height="68"><strong>ID</strong></td>
<td width="152"><strong>Item name.</strong> </td>
<td width="253"><strong>unit price</strong> </td>
<td width="253"><strong>Update price</strong></td>
</tr>
<?php
$query=mysql_query("SELECT *FROM manuf ") or die (mysql_error());
while($row=mysql_fetch_array($query))
{
$id=$row['id'];
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['itemname']; ?></td>
<td><?php echo $row['unitprice']; ?></td>
<td>change</td>
</tr>
<?php
}
?>
</table>
</body>
</html>
Now this PHP code is supposed to allow me to edit individual rows that have been displayed when i click on 'change' but it it not selecting the row. Any ideas how to solve this?
<?php require_once('../Connections/bidco.php'); ?>
<?php
$id = isset($_GET['id']) ? $_GET['id'] : null;
$query=mysql_query("SELECT * FROM manuf where id='$id' ")or die(mysql_error());
$row=mysql_fetch_array($query);
?>
<form action="updateprice.php" method="post" enctype="multipart/form-data">
<table align="center">
<tr>
<td> <label><strong>Item Name</strong></label></td>
<td> <input type='text' name='itemname' value=" <?php echo $row['itemname']; ?>" />
<input type="hidden" name="id" value="<?php echo $id; ?> " /> <br /></td>
</tr>
<tr>
<td><label><strong>Unit price </strong></label></td>
<td> <input type="text" name="unitprice" value="<?php echo $row['unitprice']; ?> " /><br /></td>
</tr>
<tr>
<td>
<input type="reset" name="Reset" value="CANCEL" />
<br></td>
<td>
<input type="submit" name="Submit2" value="Update" /> </td>
</tr>
</table>
</form>
</body>
</html>
Thank you in advance
Your forget to add you id to your link
<td>change</td>
I think you need
<a href="change.php?id=$row['id']">
Edit - use Arif_suhail_123's answer - I did not notice you have PHP mixed in with HTML
You need to pass rowid to href of Edit Link.
<td>change</td>
You are looking for id in change.php, but you are not sending that in the header. You must change change with
change
Also, I suggest you STOP using mysql_* commands, since the are Depreceted, and will no longer be supported. Use mysqli_* commands instead.
i am facing problem i am developing school system in php.
i want use checkbox dynamic for attendance but checkbox value i cant use in another file please help me
first file attendacne.php
<form name="abc" method="post" action="attendance-con.php">
<p>Date:
<input name="dat" type="text" class="tcal"/>
<input name="Save" type="submit" style="float:right 20ox;" value="Save Attendace" />
<input name="class_id" type="hidden" value="<?php echo $_REQUEST['class_id']; ?> " />
<?php
$a=0;
$qry=("SELECT DISTINCT
s.rollnum as rollnum,
s.std_name as name
FROM student s WHERE s.std_class=".$_REQUEST['class_id']."");
$result=mysql_query($qry);
while($row=mysql_fetch_array($result))
{
?>
<table width="100%" border="1" align="center" cellpadding="4" cellspacing="4" style="text-align:left;" id="stname">
<?php
if($a==0)
{ ?>
<tr>
<th width="117" height="39" bgcolor="#FFE1CC">Student RollNo</th>
<th bgcolor="#FFE1CC">Student Name</th>
<th width="100" bgcolor="#ECFAFF">Present</th>
</tr>
<?php
}?>
<?php
if($a==1)
{ ?>
<tr>
<th width="117" height="-5" bgcolor="#FFE1CC"></th>
<th bgcolor="#FFE1CC"></th>
<th width="100" bgcolor="#ECFAFF"></th>
</tr>
<?php
}
?>
<?php $a=1; ?>
<input type="hidden" name="rollnum[]" value="<?php echo $row['rollnum'];?>"/><tr>
<td>
<?php echo $row['rollnum'];?>
</td>
<td>
<?php echo $row['name'];?>
</td>
<td>
<input type="checkbox" name="stid[]" value="1">
</td>
</tr>
<?php }?>
</table>
</form>
second file attendance-con.php
<?php
include_once("include/config.php");
$i=0;
$Dat=$_POST['dat'];
$cid=$_POST['class_id'];
$sid=$_POST['stid'];
foreach($_POST['rollnum'] as $x)
{
if($sid[$i]=='1')
{
$query=mysql_query("INSERT INTO attendance (sid,cid,Date,status)
values('$x','$cid','$Dat','1')");
}
if($sid[$i]!='1')
{
$query=mysql_query("INSERT INTO attendance (sid,cid,Date,status)
values('$x','$cid','$Dat','0')");
}
$i=$i+1;
}
?>
<input type="checkbox" name="stid" value="1">
not
<input type="checkbox" name="stid[]" value="1">
Ok so im making a login system and for some reason when typed like this im getting issues with it posting without an echo or print and the following script the displays itself help anyone.
<?PHP $form = '
<form method="POST" action="login.php">
<table>
<tr>
<td>Username:<td>
<td><input type="text" name="user"><td>
</tr>
<tr>
<td>Password:<td>
<td><input type="password" name="password"><td>
</tr>
<tr>
<td><td>
<td><input type="submit" name="loginbtn" value="Login"><td>
</tr>
<tr>
<td>Register<td>
<td>Forgoten Password<td>
</tr>
</table>
</form>'
;
?>
<?php //Some PHP Code if necessary
if(true) { //Any html between this brace and the next brace will be included
?>
<form method="POST" action="login.php">
<table>
<tr>
<td>Username:<td><td>
<input type="text" name="user">
<td>
</tr>
<tr>
<td>Password:<td><td>
<input type="password" name="password">
<td>
</tr>
<tr>
<td><td><td>
<input type="submit" name="loginbtn" value="Login">
<td>
</tr>
<tr>
<td>Register<td><td>Forgoten Password<td>
</tr>
</table>
</form>
<?php
} //End of if statement.
else { //This won't be shown, because the if statement is always true
?>
<div>
This is not displayed
</div>
<?php
}
?>