Jump to content


editing data (probably simple, but I'm new)

  • Please log in to reply
1 reply to this topic

#1 smoreno

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 28 July 2006 - 02:07 PM

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:
   $link = mysql_connect("mysql", "name", "pwrd");
   /* 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 */

    /* Closing connection */

Page where data is submitted:
<form name="form1" method="post" action="insert_it.php">
   <table width="100%" border="0" cellpadding="5" cellspacing="0">
    	<td valign="top"> Announcement</td>
			<textarea name="announce" cols="40" rows="10"></textarea>
<table width="50%" border="0" cellpadding="5" cellspacing="0">
<td width="25%">Show Annoucement?</td>
<td width="25%"> 		
			<input type="radio" name="display" value="Y">Yes
			<input type="radio" name="display" value="N">No

	<tr><td><input type="submit" name="Submit" value="Submit"></td></tr>

Page you are brought to after you hit submit:
 $link = mysql_connect("mysql", "user", "pwrd");
   $query = "INSERT INTO announce (text, display) VALUES ('$announce', '$display')";

$results = mysql_query($query) or die(mysql_error());
echo $result;
echo $query;


print "<html><body><center>";
print "<p>You have just entered this record<p>";
print "Name : $announce<br>";
print "</body></html>";


I just need a page where the data that has been entered can be edited.
If anyone could help it would be greatly appreciated.


#2 ober

  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 28 July 2006 - 02:23 PM

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:
        echo '<textarea name="announce" cols="40" rows="10">' . $row['announce'] . '</textarea>';
        echo '<textarea name="announce" cols="40" rows="10"></textarea>';

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!

Info: PHP Manual

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users