Gruzin Posted August 4, 2006 Share Posted August 4, 2006 hi,I want to insert some text in db, but I want the old text to be replaced with new one. how can I do that?here is the code, but it adds more text:[color=red]<?php$link = "http://www.3d.caucasus.net";$linkShow = "Your info is saved in db";$con = mysql_connect("localhost","3d","password");if(!$con) { die('Couldn"t connect'.mysql_error());}mysql_select_db("3d",$con); $insert = "INSERT INTO data(text)VALUES('$_POST[text]')"; if(!mysql_query($insert,$con)) { die('Error'.mysql_error());}echo "<table width='400' border='0' cellspacing='0' cellpadding='0' align='center'> <tr> <td align='center'><a href='$link'>$linkShow</a></td> </tr></table>"; mysql_close($con);?>[/color]Thanks for help Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 4, 2006 Share Posted August 4, 2006 If you want to overwrite, then you want to UPDATE the tableUPDATE tablename SET fieldname = 'data' WHERE fieldname = 'something' Quote Link to comment Share on other sites More sharing options...
Gruzin Posted August 4, 2006 Author Share Posted August 4, 2006 I don't get it....sorry. Think I'am not doing it correctly Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 4, 2006 Share Posted August 4, 2006 okSay you have a row in your databaseFIELDS: ID | nameDATA: 1 | JamieIf You run a queryINSERT INTO table (name) VALUES ('John')a new Row will be addedIf you run a queryUPDATE table SET name = 'john' WHERE id = 1;THEN the name JAMIE would be changed to JOHNINSERT = Insert a NEW rowUPDATE = Update a percific row or tableIf you use UPDATE without a where clause then all fields will be updated, I done this once, I updated the storys on my website with my story, forgetting the WHERE clause, and lost all the stories, thank god I had back ups Quote Link to comment Share on other sites More sharing options...
Gruzin Posted August 4, 2006 Author Share Posted August 4, 2006 ok, thanks, I'll try:) Quote Link to comment 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.