Log in

View Full Version : editing mysql info



auriaks
11-25-2009, 10:49 PM
hello,
I wonder if it is possible to edit info from mysql.
I know how to update info... But if I want to edit it, i have to call it, then show in editor or something else :confused: idk how i can do this...
Thanks... (btw, if you need more info, ask)

james438
11-26-2009, 12:12 AM
Sure you do. You know how to call the info and update the info. Basically, just call the info, assign it to a variable, place it into a textarea with a submit button at the bottom of the page and you know what to do after that.

First page:

<?php include 'dbinfo.php';
$topic = "select summary, date from tablename where ID = 4";
$topic_res = mysql_query($verify_topic, $conn) or die(mysql_error());
$add_info = mysql_fetch_array($get_addresses_res)) {
$ID = $add_info['ID'];
$date = $add_info['date'];
$summary = $add_info['summary'];
}?><form action="/submitdata.php" method="post" name="editform">
<textarea name="summary" cols=75 rows=25><?php print htmlentities($summary) ; ?></textarea>
<p><input type="submit" name="newbutton" value="Submit Review">
and then in submitdata.php:

<?php
include '../include/dbstuff.php';
$newbutton=$_POST['newbutton'];
$ID = $_POST['ID'];
$date = $_POST['date'];
$summary = $_POST['summary'];
$query = "UPDATE tablename SET ID='$ID',date='$date',summary='$summary',image='$image' WHERE ID='$ID'";
$result = mysql_query($query) or die ("Couldn't execute query.");
?>

You have all of the info you need to do this from earlier questions you asked, but sometimes putting it all together is not always immediately understood. You should take a little more time to put what you know together before giving up and seeking help.

PS Make sure you use cookies or sessions so that only the people you allow to use the page can do so. Also process your data to keep malicious (bad) data from being submitted.

auriaks
11-26-2009, 09:38 AM
Thanks... Hope this will work. :)

auriaks
11-27-2009, 12:33 AM
It works, but one thing left...
I get text, but it is shown like this:

J 63;s 71;  3;kelti darbai atliekami per 6-24h.<br>Ta 69;iau  3;vykus ir netik 79;toms priežastims, gali užsit&# 281;sti ir ilgiau.<br>B 63;kite kantr&# 363;s :D

I entered some spaces to show code for lithuanian letters.
As you can see I use Lithuanian language :)
and all br's are seen... how I can get nice output?
Thanks.

james438
11-27-2009, 06:32 AM
I need more information. When you are gather the information and you want it to be shown without the line breaks (br) are you submitting the the content with line breaks or are they appearing out of nowhere?

What I do with my content editing programs is I submit the data to the database with newlines as opposed to line breaks then when the content is retrieved the code looks nice. It looks like


This is some text.
more text.

A few more lines.
as opposed to this which uses linebreaks:

This is some text.<br>more text.<br><br>A few more lines.
If I want to echo or print the data from my database for general viewing as opposed to viewing it in a textarea like this program does I retrieve the content and reformat it and then display the formatted text. It looks something like
$content=str_replace("\r\n","<br>",$content);
I also like to use
$content=str_replace(" ","&nbsp;&nbsp;",$content); because when browsers display data they tend to condense two or more consecutive spaces. This will display them again.