Forum Moderators: phranque
No idea for tutorials, but it's a pretty basic concept: read the data one the edit page, then on the submit page update the data in the DB based on what the user entered.
<?php
while($rows=mysql_fetch_array($result)){ // Start looping table row
?>
<tr bgcolor="#006600">
<td><div align="center" class="style1"><? echo $rows['id']; ?></div></td>
<td><div align="center" class="style1"><? echo $rows['conpo']; ?></div></td>
<td><div align="center" class="style1"><? echo $rows['datesched']; ?></div></td>
<td><div align="center" class="style1"><? echo $rows['contractor']; ?></a><BR>
</div></td>
<td align="center"><div align="center" class="style1"><? echo $rows['containersize']; ?></div></td>
<td align="center"><div align="center" class="style1"><? echo $rows['type']; ?></div></td>
<td align="center"><div align="center" class="style1"><? echo $rows['received']; ?></div></td>
<td align="center"><div align="center" class="style1"><? echo $rows['completed']; ?></div></td>
<td align="center"><form action="editpost.htm?id=<? echo $rows['id'] ?>" method="post" name="form985687231" class="style4">
<div align="left"><input type="submit" name="PostRequest" id="PostRequest" value="Edit">
</div>
</form></td>
<td align="center"><form action="newWin.htm" method="post" name="form1211111">
<strong> <a href="newWin.htm">
<input type="button" name="PostRequest3" id="PostRequest3" value="Delete"/>
</a></strong>
</form></td>
<td align="center"><form action="delete.php?id=<? echo $rows['id']; ?>" method="post" name="form123412123421">
<strong>
<input type="submit" name="delete_this" id="delete_this" value="Perm Delete" onclick="return verify()"/>
</strong>
</form></td>
</tr>
<?php
// Exit looping and close connection
}
mysql_close();
?>
</table>
^^ I don't know how to make the tables in php.. '-.- or the if function may be easier to use..
Also, for the edit. How do I get my edit page to pull the data from the database? And then on the update page, when I update it, it makes a new post rather than updating the correct post, is that because I did not pull the id from the url? If so, how do I do this?
[edited by: criTiKAL at 1:19 am (utc) on Sep. 24, 2008]
Here's the basic logic:
- SQL for update page -
SELECT Name
FROM YourTable
WHERE ID=19
- your update page (I don't program in PHP, so it may be a little different) -
<form action="finalpage.php" method="post">
<input type="hidden" name="ID" value="19">
<input type="text" name="Name" value="<? echo $rows['Name']; ?>">
<input type="submit">
</form>
- SQL for finalpage.php -
UPDATE YourTable SET
Name=[FORM.Name]
WHERE ID=[FORM.ID]
(Like I said, I don't know PHP, so substitute whatever is in the square brackets for how you pass form parameters to your database in PHP.)
you should put the id in a hidden input parameter in the form so the script handling the edit/update can get the id from the POST request.
I made it display the array.
This is without trying to update the id #.
-----------------------------------------------
Array
(
[conpo] => 2133125
[datesched] => 123123
[unitnum] => 12314123
[Type] =>
[containersize] => 20\' 50/50
[doors] => Doors Off
[contractor] => 123123
[orderedby] => 12312312
[jobcontact] => 123123123
[phone] => 3123123
[jobname] => 12312
[address] => 231231
[city] => 2312312
[directions] => 3123123
[comments] => 123123123
[conrentalfee] =>
[delfee] => 123123
[pickupfee] => 123123123123
[relfee] => 123123
[extra] => 123123123
[datedelivered] => 2312312
[eqdel] => 3123123
[Submit_btn] => Update Request
)
Duplicate entry '0' for key 1
-----------------------------------------------
This is what I get for trying to update the id #.
-----------------------------------------------
Array
(
[id] => 31
[conpo] => 2133125
[datesched] => 123123
[unitnum] => 12314123
[Type] =>
[containersize] => 20\' 50/50
[doors] => Doors Off
[contractor] => 123123
[orderedby] => 12312312
[jobcontact] => 123123123
[phone] => 3123123
[jobname] => 12312
[address] => 231231
[city] => 2312312
[directions] => 3123123
[comments] => 123123123
[conrentalfee] =>
[delfee] => 123123
[pickupfee] => 123123123123
[relfee] => 123123
[extra] => 123123123
[datedelivered] => 2312312
[eqdel] => 3123123
[Submit_btn] => Update Request
)
Duplicate entry '31' for key 1
$conpo=$_POST['conpo'];
$datesched=$_POST['datesched'];
$unitnum=$_POST['unitnum'];
$type=$_POST['type'];
$containersize=$_POST['containersize'];
$doors=$_POST['doors'];
$cc=$_POST['cc'];
$received=$_POST['received'];
$completed=$_POST['completed'];
$other=$_POST['other'];
$contractor=$_POST['contractor'];
$orderedby=$_POST['orderedby'];
$jobcontact=$_POST['jobcontact'];
$phone=$_POST['phone'];
$jobname=$_POST['jobname'];
$address=$_POST['address'];
$city=$_POST['city'];
$directions=$_POST['directions'];
$conrentalfee=$_POST['conrentalfee'];
$delfee=$_POST['delfee'];
$pickupfee=$_POST['pickupfee'];
$relfee=$_POST['relfee'];
$extra=$_POST['extra'];
$datedelivered=$_POST['datedelivered'];
$eqdel=$_POST['eqdel'];
$comments=$_POST['comments'];
$datetime=date("d/m/y h:i:s"); //create date time
$sql="UPDATE forum_question SET id='$id', conpo='$conpo', comments='$comments', datesched='$datesched', unitnum='$unitnum', type='$type', containersize='$containersize', doors='$doors', cc='$cc', received='$received', completed='$completed', other='$other', contractor='$contractor', orderedby='$orderedby', jobcontact='$jobcontact', phone='$phone', jobname='$jobname', address='$address', city='$city', directions='$directions', conrentalfee='conrentalfee', delfee='$delfee', pickupfee='$pickupfee', relfee='$relfee', extra='$extra', datedelivered='$datedelivered', eqdel='$eqdel'";
$result=mysql_query($sql) or die(mysql_error());
if($result){
echo "Successful!<BR>";
echo "<a href=forum_main.php>Back to Container Requests</a>";
}
else {
echo "ERROR";
}
mysql_close();