Note Saving Form
#1
Posted 24 November 2005 - 04:11 PM
#2
Posted 24 November 2005 - 05:20 PM
<?php $retained = $_POST['textarea']; ?> <form method="post"> <textarea name="textarea"><?php echo (isset($retained)) ? $retained : 'Enter something here!'; ?></textarea><br /> <input type="submit" /> </form>$retained is POST data grabbed from the form.
In the textarea we echo our $retained if it is set, otherwise we echo "Enter something here"
More information on predefined variables here: http://us2.php.net/reserved.variables
Edited by HaloprO, 24 November 2005 - 05:22 PM.
#3
Posted 24 November 2005 - 05:50 PM
#4
Posted 24 November 2005 - 06:20 PM
#5
Posted 24 November 2005 - 06:26 PM
Thanks.
EDIT: Wouldn't it be fixed if there was a form action, so it knew what to do?
Edited by c.designs, 24 November 2005 - 06:46 PM.
#6
Posted 24 November 2005 - 08:06 PM
#7
Posted 25 November 2005 - 01:01 AM
<form method="post"> <textarea name="textarea"><? echo (isset($_POST['textarea']) ? $_POST['textarea'] : 'Enter something here!'); ?></textarea><br /> <input type="submit" /> </form>^ The way i'd recommend doing that... less variables...
But as for saving it, MySQL does constitute a "simple php script", and would be the most relyable way of keeping your note in there.
Cookies would work as well, you'll just have to make sure you set the time it expires to something far enough in the future that you'll update your not before you lose it (and could make things complicated, because most php beginners have problems getting them to work due to header problems, mysql doesn't have that).
Sessions would work while the browser is open, like halopr0 said.
http://php.net/manua...mysql-query.php
http://www.pixel2life.com/tutorials/PHP_Co...1&d=1&ss=insert
^ Should provide all the info needed on how you would store the note in a database.
#8
Posted 25 November 2005 - 08:32 PM
#9
Posted 25 November 2005 - 09:15 PM
Note could be a varchar of 255, or LONGTEXT or TEXT, either will work.
#10
Posted 25 November 2005 - 10:01 PM
CREATE TABLE `notes` (
id NOT NULL auto_increment,
note text varchar (255),
PRIMARY KEY (id)
)
Edited by c.designs, 25 November 2005 - 10:02 PM.
#11
Posted 26 November 2005 - 12:36 AM
#12
Posted 26 November 2005 - 10:47 AM
Heres what I've been trying to use:
CREATE TABLE `notes` (
`id` NOT NULL AUTO_INCREMENT ,
`notes` VARCHAR( 255 ) NOT NULL ,
`id` NOT NULL ,
PRIMARY KEY ( `id` ) ,
UNIQUE (
`id`
)
) TYPE = MYISAM
Edited by c.designs, 26 November 2005 - 10:49 AM.
#13
Posted 26 November 2005 - 12:00 PM
CREATE TABLE `notes` ( `notes` TEXT NOT NULL );
Personally, I see no reason to have an id row. Since there is going to be ONE box, storing the same note. Having an extra row which is only going to only be used once is just a waste in my opinion.
Just use these queries to update the form....
mysql_query("UPDATE notes SET notes = '" . $_POST['notes'] . "' LIMIT 1") or die(mysql_error());
But that is how I would do it. If you still want the structure with the id field, here you go:
CREATE TABLE `notes` ( `id` INT( 10 ) NOT NULL AUTO_INCREMENT , `notes` TEXT NOT NULL , PRIMARY KEY ( `id` ) );
#14
Posted 26 November 2005 - 12:28 PM
#16
Posted 26 November 2005 - 02:43 PM
<? $dbh=mysql_connect ("localhost", "cdesigns_count", "pass") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("cdesigns_notes"); ?>
<form method="post">
<textarea name="notes" id="textarea"><? mysql_query("UPDATE notes SET notes = '" . $_POST['notes'] . "' LIMIT 1") or die(mysql_error()); ?></textarea><br />
<input type="submit" value="Save" id="button" />
</form>
Edited by c.designs, 26 November 2005 - 02:43 PM.
#17
Posted 26 November 2005 - 03:04 PM
<?php
$connect = mysql_connect(); //you know this part
if (isset($_POST['notes'])) {
$sql = 'UPDATE `notes` SET notes = \''.$_POST['notes'].'\' WHERE id = '.$id.'';
$q = mysql_query($sql) or $error = mysql_error();
echo (isset($error)) ? $error : null;
}
?>
<form method="post">
<textarea name="notes"></textarea><br />
<input type="submit" />
</form>
I didn't bother to test this, but it should work
#18
Posted 26 November 2005 - 04:18 PM
CREATE TABLE `notes` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT ,
`notes` TEXT NOT NULL ,
PRIMARY KEY ( `id` )
);
I get this error after submitting:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
#19
Posted 26 November 2005 - 05:04 PM
#20
Posted 26 November 2005 - 06:40 PM
mysql_connect(); //you know this part
if (isset($_POST['notes'])) {
$q = mysql_query("UPDATE `notes` SET notes = '".$_POST['notes']."' LIMIT 1") or mysql_error();
echo is_resource($q) ? 'Note updated successfully.<br>' : $q;
}
$sql = mysql_query("SELECT * FROM notes LIMIT 1");
$r = mysql_fetch_assoc($sql);
?>
<form method="post">
<textarea name="notes"><?= $r['notes']; ?></textarea><br />
<input type="submit" />
</form>
If you get an error relating to a WHERE statement, then just find some way to add it in. The ID is not necessary if you only want 1 note stored, but if you want multiple notes, then you'll need to find a way to work it in.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
