eRott Posted November 25, 2006 Share Posted November 25, 2006 Ok, I have completed a simple news editor using php and SQL, however I have just realized i forgot to add an option to modify a news article. Now, these news articles appear on the homepage so its necessary to have a way to fix spelling mistakes etc if necessary. Ok, so basically, heres the scoop.The news article are comprised of 5 parts:1) the articles id number (auto increment)2) the title3) the actual content itself4) the date the article was written5) and the user who submitted itNow, each of these 5 parts are entered by the user themselves. Now, I also have a page where it lists the new articles and their id's. So, lets say the user wants to modify an article he wrote. So he views all the articles, and sees that his article is lets say id number "7".Now, this is the part I dont know how to do. I am looking to have a simple page where it shows nothing more then an ID box and a button. So, the user enters the ID number and clicks "next". I then want, depending on the id number, that article to be called and displayed in the appropriate text boxes.So, if you still dont get what I mean, there will be a page with a text box and the user will enter the id number and click next. So, on that SAME page (doesnt have to be on the same page, but would be nice), new stuff will pop up. Now, that new stuff is all the articles informtion mentioned above, the title, content, date, and the user who submitted it. So it would have like 3 text boxes and one text area which, like i said, depending on the id number, will be filled in with the appropriate information.So, for example, I mean, if the user chooses article id, say "7" so then that articles stuff would show up. Something along the lines of..[code]<b>Title:</b><br><input name="mod_title" type="text" id="mod_title" value='$title'><b>Content:</b><br><textarea name="mod_content" id="mod_content" type="text" rows="15" cols="50" style="width: 100%; margin-left: 0px; padding: 0px;">$content</textarea><b>Date:</b><br><input name="mod_date" type="text" id="mod_date" value='$date'><b>Submitted By:</b><br><input name="mod_submitted" type="text" id="mod_submitted" value='$mod_submitted'>[/code]Now that variable '$title' is calling the information from the database. So for example, there is a database named 'news' and in there there are 5 tables 'id', 'title', 'content', 'date', 'submitted'. ($submitted is the value for the user who submitted the article)So once the user enters the id, and all that information appears/is called. He or she then proceeds to edit the necessary parts. Once thats done, they then click 'update article' and everything is done. Using something along the lines of this:[code]<?if(isset($_POST['update'])){include 'lib/config.php';include 'lib/db_open.php';$mod_id = $_POST['mod_id'];$mod_title = $_POST['mod_title'];$mod_content = $_POST['mod_content'];$mod_date = $_POST['mod_date'];$mod_submitted = $_POST['mod_submitted'];$query = "UPDATE $tbl_content SET title = '$mod_title', content = '$mod_content', date = '$mod_date', submitted = '$mod_submitted' WHERE id = '$mod_id'";mysql_query($query) or die('Error, insert query failed');include 'lib/db_close.php';echo "<meta http-equiv='refresh' content='1;url=index2.php'>Article successfully updated!";}else{?>[/code]Hope I've made sense. If anyone could help me out with this that would be EXCELLENT. Would really help me out a lot. Thank you very much.Best RegardseRott Link to comment https://forums.phpfreaks.com/topic/28458-solved-news-editor/ Share on other sites More sharing options...
fert Posted November 25, 2006 Share Posted November 25, 2006 UPDATE is the sql keyword that will do what you want Link to comment https://forums.phpfreaks.com/topic/28458-solved-news-editor/#findComment-130215 Share on other sites More sharing options...
eRott Posted November 25, 2006 Author Share Posted November 25, 2006 I am aware of that, just read that second bit of code. Although, that doesn't really answer my question. I guess Ill try to simplify it some more. Basically I am looking for an answer on how to display something after a user does something.So I am basically looking to do this:There is a page with a text box and next button.User enters an id number into the text box, and on that same page or a different one, that article with the id of whatever number was entered will show up.Ok, look at this code below. I am looking to do this basically:Page 1-------$id = 'id_chosen'ID:<input name="id_chosen" type="text" id="id_chosen">(button "NEXT")Page 2-------On the button click,IF $id = '7'display the information from the database where the id is '7'Title:<br><input name="mod_title" type="text" id="mod_title" value='$title'>Content:<br><textarea name="mod_content" id="mod_content" type="text">$content</textarea>Date:<br><input name="mod_date" type="text" id="mod_date" value='$date'>By:<br><input name="mod_submitted" type="text" id="mod_submitted" value='$mod_submitted'>although, i would prefer if it could all be done on the exact same page. Link to comment https://forums.phpfreaks.com/topic/28458-solved-news-editor/#findComment-130228 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.