boogiewoogie Posted February 8, 2011 Share Posted February 8, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/227045-help-making-a-simple-editing-form/ Share on other sites More sharing options...
Muddy_Funster Posted February 10, 2011 Share Posted February 10, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/227045-help-making-a-simple-editing-form/#findComment-1172290 Share on other sites More sharing options...
boogiewoogie Posted February 16, 2011 Author Share Posted February 16, 2011 Thanks! I have managed to figure it out. Quote Link to comment https://forums.phpfreaks.com/topic/227045-help-making-a-simple-editing-form/#findComment-1174994 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.