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 Link to comment https://forums.phpfreaks.com/topic/16541-mysql-help-needed/ 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' Link to comment https://forums.phpfreaks.com/topic/16541-mysql-help-needed/#findComment-69151 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 Link to comment https://forums.phpfreaks.com/topic/16541-mysql-help-needed/#findComment-69154 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 Link to comment https://forums.phpfreaks.com/topic/16541-mysql-help-needed/#findComment-69159 Share on other sites More sharing options...
Gruzin Posted August 4, 2006 Author Share Posted August 4, 2006 ok, thanks, I'll try:) Link to comment https://forums.phpfreaks.com/topic/16541-mysql-help-needed/#findComment-69172 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.