Jump to content


Photo

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


  • Please log in to reply
6 replies to this topic

#1 kdub718

kdub718
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 19 September 2006 - 11:33 PM

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:
<? 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>

this is my addevent page 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>

Thanks in advance,

#2 kdub718

kdub718
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 20 September 2006 - 02:31 AM

any more information needed?  that I may be missing?  Anyone that can help me out?  Thanks

#3 kdub718

kdub718
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 20 September 2006 - 05:02 PM

please?  anyone?

#4 kdub718

kdub718
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 21 September 2006 - 06:16 AM

well since nobody here wants to help me can someone suggest a site where I can get some help? 

#5 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 21 September 2006 - 11:21 AM

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
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#6 kdub718

kdub718
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 21 September 2006 - 06:33 PM

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

#7 kdub718

kdub718
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 22 September 2006 - 09:52 PM

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:
<? 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>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users