I wonder whether someone may be able to help me please.
Firstly, this is something I’ve never tackled before, so please bear with me if this is something which is straight forward to the more seasoned developer.
The code below is a portion of a script which correctly shows a ‘Locations List’ for each user.
$i=0;
while ($i < $num) {
$lid=mysql_result($result,$i,"locationid");
$lname=mysql_result($result,$i,"locationname");
$laddress=mysql_result($result,$i,"returnedaddress");
include("admin/link.php");
include("admin/opendb.php");
$fquery = "SELECT COUNT(*) num FROM finds WHERE locationid = '$lid'";
$fcount = mysql_query($fquery) or die('error');
$row = mysql_fetch_assoc($fcount);
$findscount = $row['num'];
mysql_close($connect);
?>
<table width="603" border="0">
<tr>
<th width="156">Location</th>
<th width="302">Address</th>
<th width="131">No. Of Finds Made</th>
</tr>
<tr>
<td><?php echo $lname;?></td>
<td><?php echo $laddress;?></td>
<td><?php echo $findscount;?></td>
</tr>
</table>
<?php
echo'<form name="locations" method="post">';
$i++;
}
if ($num == 0) {
echo"<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td colspan='3'><div align='center'><strong>No locations have been added yet. <a href='saveaddress.php'>Click here</a> to add one.</strong></div></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>";
}
echo '<input type="submit" name="submitlocation" id="submitlocation" value="View/Amend Location Details">';
echo '<input type="submit" name="submitfinds" id="submitaddfinds" value="Add Finds">';
echo '</div>'."\n";
if(isset($_POST["submitlocation"])) {
header("updatelocation.php");
}
else if(isset($_POST["submitaddfinds"])) {
header("addfinds.php");
}
?>
What I’m trying to do is add two submit buttons for each Location record, one which takes the user to a page called updatelocation.php and the second which takes the user to a page called addfinds.php. But both must be linked to the Location via the field ‘locationid’. So in other words if the user wants to Add Finds for Location 1 upon clicking on the relevant button, they are taken to the Add Finds page for Location 1.
I’ve read a number of tutorials, but I’ve obviously misunderstood somewhere along the lines because although I’ve managed to add the buttons to the record, when I click either button the ‘Locations List is refreshed, rather than the user being taken to the respective page.
I just wondered whether someone could possibly have a look at this please and let me know where I’m going wrong?
Many thanks and kind regards
You’d be better off making a seperate page (i.e., forrmaction.php) which processes the logic and sends the user to the correct page. If you do not want to do that, you can also make a seperate form for each button and simply set the
actionattribute offormto point to either updatelocation.php or addfinds.phpExample of formaction.php:
Example of form with two buttons that works with formaction.php:
However, for your question, the problem is that you are not using the correct header. To use a redirect, you must use “Location:” in the header. For example,
Be careful, because this will not work if headers have already been sent. You may want to look into output control in that case.