smoreno Posted July 28, 2006 Share Posted July 28, 2006 Ok basically I know little to nothing about php, but I am helping make this website. I've read a couple of tutorials but I just can’t seem to get it for some reason. Basically the site needs to have an announcements page. People are able to post announcements and then they show up, I got this part figured out. Now though, I need a page where I can see the announcements data in a form that it can be edited by a user on the website. Page where data is displayed:[code] <?php $link = mysql_connect("mysql", "name", "pwrd"); mysql_select_db("announcements"); /* Performing SQL query */ $query = "SELECT * FROM announce"; $result = mysql_query($query) or die("Query failed"); /* Printing results in HTML */ print "<table>\n"; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { print "\t<tr>\n"; foreach ($line as $col_value) { print "\t\t<td>$col_value</td>\n"; } print "\t</tr>\n"; } print "</table>\n"; /* Free resultset */ mysql_free_result($result); /* Closing connection */ mysql_close($link); ?>[/code]Page where data is submitted:[code]<form name="form1" method="post" action="insert_it.php"> <table width="100%" border="0" cellpadding="5" cellspacing="0"> <tr> <td valign="top"> Announcement</td> <td> <textarea name="announce" cols="40" rows="10"></textarea> </td></tr><tr><table width="50%" border="0" cellpadding="5" cellspacing="0"><tr><td width="25%">Show Annoucement?</td><td width="25%"> <input type="radio" name="display" value="Y">Yes </td><td> <input type="radio" name="display" value="N">No </td></tr></table> </tr> <tr><td><input type="submit" name="Submit" value="Submit"></td></tr> </table> </form>[/code]Page you are brought to after you hit submit:[code]<?php $link = mysql_connect("mysql", "user", "pwrd"); mysql_select_db("announcements"); $query = "INSERT INTO announce (text, display) VALUES ('$announce', '$display')"; $results = mysql_query($query) or die(mysql_error());echo $result;echo $query;mysql_close();print "<html><body><center>";print "<p>You have just entered this record<p>";print "Name : $announce<br>";print "</body></html>";?>[/code]I just need a page where the data that has been entered can be edited.If anyone could help it would be greatly appreciated. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/15889-editing-data-probably-simple-but-im-new/ Share on other sites More sharing options...
ober Posted July 28, 2006 Share Posted July 28, 2006 I'm going to give you a high level overview since you have the tools to do the work.You basically take the form that you have to create a new annoucement and fill it with values from the database. I'm not sure how you provide the edit feature (button on the annoucement based on who is logged in?) but you'd end up going to (I'm going to assume some things) newannounce.php?postid=1234 from the link on the post to edit the post.Once you get to that page, you run a SQL query with that ID in a WHERE clause. You grab all the data in the record (mysql_fetch_assoc or mysql_fetch_array), and then in your form you have something like this:[code]<td><?php if(isset($row['announce'])) { echo '<textarea name="announce" cols="40" rows="10">' . $row['announce'] . '</textarea>'; } else { echo '<textarea name="announce" cols="40" rows="10"></textarea>'; }?></td></tr>[/code]And you do that for all the elements in the form that have a value in the database.Hope that helps.EDIT: And don't forget to use the ID value in the UPDATE statement! Quote Link to comment https://forums.phpfreaks.com/topic/15889-editing-data-probably-simple-but-im-new/#findComment-65171 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.