replace when submit
Posted: Mon Mar 26, 2007 11:14 am
feyd | Please use
DATABASE:
POST FILE:
It working but adding another records to database. I tried replace INSERT by UPDATE but I'm getting error. Could someone help me create working code, please?
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I need to put on my site form which would allow add some content to database. It have to be like simple guestbook but I want to it not add new records to database but replace those which already exist. In other words: I want to in database could be only 1 record (last submitted).
Those are my codes:
SUBMIT FORM:Code: Select all
<form id="form1" name="form1" method="post" action="postfile.php">
<input name="myTEXT" type="text" id="myTEXT" size="40" />
<input type="submit" name="Submit" value="Submit" /></td>
</form>Code: Select all
CREATE TABLE `test_db` (
`myTEXT` varchar(65) NOT NULL default '',
PRIMARY KEY (`myTEXT`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ;Code: Select all
$host="bla bla bla";
$username="bla bla bla";
$password="bla bla bla";
$db_name="bla bla bla";
$tbl_name="test_db";
mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="INSERT INTO $tbl_name(myTEXT)VALUES('$myTEXT')";
$result=mysql_query($sql);
if($result){
echo "Successful";
}
else {
echo "ERROR";
}
mysql_close();feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]