Jump to content

I need a little help with an edit page **PLEASE


Recommended Posts

Well basically I have a schedule page.  With Date, Event, Location, and Finish...  I have it setup right now to where I can just delete the hole line...  well I want to add an edit feature so I don't have to delete the entire line I can just edit each line to put a finishing place in or just edit the line in general incase I miss spell something or a date gets changed for an event... also is there a way to order the entries by date?  right now I have to order them backwards to make the most recen events show up on top... but if a date changes I have to re-do the entire schedule... 

here is what I have... I'm really new to php and the whole database stuff...  also what is the difference with php and asp? (that might be a little off subject but incase someone out there wants to give me some insight that would be great)


this is my editevent page code:
[code]<? include("../secure.php");?>
<?if (isset($delete)) @mysql_query ("DELETE FROM events WHERE id = '$delete'"); ?>
<center>
<table width=728 align=center border=0 cellspacing=1 cellpadding=3>
<tr align=center>
<td width="140" bgcolor=silver><B><font size=1 face="verdana">DATE</b></td>
<td width="133" bgcolor=silver><B><font size=1 face="verdana">EVENT</b></td>
<td width="139" bgcolor=silver><B><font size=1 face="verdana">LOCATION</b></td>
<td width="140" bgcolor=silver><B><font size=1 face="verdana">QUALIFIED</b></td>
<td width="140" bgcolor=silver><B><font size=1 face="verdana">FINISH</b></td>
</tr>

<? 
$result = @mysql_query("SELECT * FROM events ORDER BY id DESC LIMIT 20");
while ( $row = mysql_fetch_array($result) ) {
echo ( "

<tr align=center>
<td><B><font size=1 face=verdana>" . $row["date2"] . "</b></td>
<td><B><font size=1 face=verdana>" . $row["event"] . "</b></td>
<td><B><font size=1 face=verdana>" . $row["location"] . "</b></td>
<td><B><font size=1 face=verdana>" . $row["qualified"] . "</b></td>
<td><B><font size=1 face=verdana>" . $row["finish"] . "</b></td>
<td><B><font size=1 face=verdana>
<a href='$PHP_SELF?delete=$row[id]'>Delete</a></b></td>
</tr>
" );
}
?>

</TD>
</TR>
</TABLE>[/code]

this is my addevent page code:
[code]<? include("../secure.php");?>
<? if (!isset($submitok)): ?>
<br>
<form method=post action="<?=$PHP_SELF?>">
<table align=center border=0 cellspacing=0 cellpadding=3>
<tr valign=top>
<td colspan=2 align=middle bgcolor=silver width=100% height=10>
<b><font face="verdana" color=black size=1>Add Event</font></b> </td>
<tr valign=top>
        <td align=right>
        <font size=1 face="verdana"><b>Date:</b></font>        </td>
        <td> <input name="date2" maxlength=100 size=25>        </td>
    </tr>   
<tr valign=top>
        <td align=right>
        <font size=1 face="verdana"><b>Event:</b></font>        </td>
        <td><input name="event" maxlength=100 size=25>        </td>
    </tr>
<tr valign=top>
        <td align=right>
        <font size=1 face="verdana"><b>Location:</b></font>        </td>
        <td><input name="location" maxlength=100 size=25>        </td>
</tr>
<tr valign=top>
  <td align=right><font size="1" face="verdana"><b>Qualified:</b></font></td>
  <td><input name="qualified" maxlength="100" size="25" /></td>
</tr>
<tr valign=top>
  <td align=right><font size="1" face="verdana"><b>Finish:</b></font></td>
  <td><input name="finish" maxlength="100" size="25" /></td>
</tr>   
<tr>
        <td colspan=2 align=middle>
        <input type=submit name="submitok" value="  Add Event  ">        </td>
</tr>
</table>
</form>
<BR><BR>

<?
else:
$sql="INSERT INTO events SET date2='$date2', event='$event', location='$location' , qualified='$qualified' , finish='$finish'";

?>
 
<table width=350 align=center border=0 cellspacing=0 cellpadding=3>
<tr valign=top>
<td colspan=2 align=middle bgcolor=silver width=100% height=10>
<b><font face="verdana" color=black size=1>Success</font></b>
</td>
<tr valign=top>
        <td><BR><center>
        <font size=1 face="verdana">Event Added successfully</font></center><BR>
        </td>
    </tr>   
<tr>
        <td colspan=2 align=middle>
        <form action=main.php><input type=submit value="   Thank You   "></form>
        </td>
</tr>
</table>[/code]

Thanks in advance,
I'd say on your page that displays the event, add two buttons to the right of it, one to update the data and one to delete it, these call editevent.php with the id field.

Then you have your editevent.php check which button was pressed, if it's delete then it it sends DELETE sql to the database and deletes the record based on id, if it's edit then it sends SELECT sql to the database based on id and selects the information from that record into a form.  Once submitted, the form uses the UPDATE sql to change the record.

As for the displaying your records by date, it's as simple as including ORDER BY date DESC in your display code.

Regards
Huggie
thanks for the response...  I'm really green (noobie as my user title says) when it comes to php coding...  I have tried so many different ways and it just doesn't seem to be working for me at all... could you possible give me an example?  I'm a little confused... okay maybe a lot confused!  LOL  =) 

Thanks,
KW
Is there a way I can just put an update button next to my delete button?  My delete button works and it deletes all the fields for each event... but I just want to add the update button on there so I can update a finish ect.  I have the update button showing and everything but when I type in something different in the field and hit update it doesn't update... but If I hit the delete button that works fine?  so am I just missing something for the update so it will save the update to the row?  does that make any sense?

My updated editevent.php page code:
[code]
<? include("../secure.php");?>
<?if (isset($delete)) @mysql_query ("DELETE FROM events WHERE id = '$delete'"); ?>
<?if (isset($update)) @mysql_query ("UPDATE FROM events WHERE id = '$update'"); ?>
<center>
<table width=809 align=center border=0 cellspacing=1 cellpadding=3>
<tr align=center>
<td width="177" bgcolor=silver><B><font size=1 face="verdana">DATE</b></td>
<td width="216" bgcolor=silver><B><font size=1 face="verdana">EVENT</b></td>
<td width="242" bgcolor=silver><B><font size=1 face="verdana">LOCATION</b></td>
<td width="64" bgcolor=silver><B><font size=1 face="verdana">FINISH</b></td>
</tr>

<? 
$result = @mysql_query("SELECT * FROM events ORDER BY id DESC LIMIT 20");
while ( $row = mysql_fetch_array($result) ) {
echo ( "

<tr align=center>
<td><input name=newsubject type=text maxlength=100 size=25 value='" . $row["date2"] . "'></td>
<td><input name=newsubject type=text maxlength=100 size=25 value='" . $row["event"] . "'></td>
<td><input name=newsubject type=text maxlength=100 size=25 value='" . $row["location"] . "'></td>
<td><input name=newsubject type=text maxlength=100 size=25 value='" . $row["finish"] . "'></td>
<td><B><font size=1 face=verdana>
<a href='$PHP_SELF?delete=$row[id]'>Delete</a>&nbsp;<a href='$PHP_SELF?update=$row[id]'>Update</a></b></td>
</tr>
" );
}
?>

</TD>
</TR>
</TABLE>[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.