Jump to content

Help making a simple editing form


boogiewoogie

Recommended Posts

I have a simple page which displays "news". I made a page to add news, but I would like one that loads the existing data and shows it in the form, and I could edit the entry and save it. Could someone help out.

 

Here is the code for the add form

echo "<form action='insertnews.php'' method='post'>";
echo "News Subject";
echo "<br></br>";
echo "<input type='text' name='subject' size='40'>";
echo "<br></br>";
echo "<br></br>";
//echo "<input type='text' name='text' size='30'>";
echo "News Text";
echo "<br></br>";
echo"<textarea name='text' rows='20' cols='50'>";
//echo "Enter news here";
echo"</textarea>";
echo "<br></br>";
echo "<input type='submit' value ='Submit News'>";
echo "</form>";

 

and here is the add code

$subject = $POST['subject'];
$text = $POST['text'];
$db = connect_db() or error_message();

$sql="INSERT INTO news (publishtime, newstitle, newstext, hide)
VALUES
(NOW(), '$_POST[subject]','$_POST[text]','no')";

if (!mysql_query($sql,$db))
  {
  die('Error: ' . mysql_error());
  }
echo "Entry added to database";
echo "<br><br>";
echo "<br><br>";
echo "<a href=../news.php>BACK to News</a>";

 

And here is the mysql table

--
-- Table structure for table `news`
--

CREATE TABLE IF NOT EXISTS `news` (
  `publishtime` varchar(31) COLLATE utf8_unicode_ci DEFAULT NULL,
  `updatetime` varchar(31) COLLATE utf8_unicode_ci DEFAULT NULL,
  `newstitle` varchar(75) COLLATE utf8_unicode_ci DEFAULT NULL,
  `newstext` longtext COLLATE utf8_unicode_ci,
  `hide` set('yes','no') COLLATE utf8_unicode_ci NOT NULL,
  `newsid` mediumint(6) NOT NULL AUTO_INCREMENT,
  `youtube` text COLLATE utf8_unicode_ci NOT NULL,
  `youtube2` text COLLATE utf8_unicode_ci NOT NULL,
  KEY `newsid` (`newsid`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=3 ;

 

The "youtube" rows are for adding youtube embed code

 

Could someone give the necessary code making an "editor" form? This is all just a local database for now, so no security in the code, that will be added later. I just need the plain basic functions for it.

 

Thanks!

Link to comment
Share on other sites

Basicly you just want to merge what you have already got into a third page.  Run your select against the database, including the newsid field, and then produce your form using variables populated for the select to fill in the "value=" section of your text inputs.  Add a hidden field that you can stuff the newsid into and then have your action page run an UPDATE rather than an INSERT INTO and you should be good to go.

Link to comment
Share on other sites

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.