Jump to content

Archived

This topic is now archived and is closed to further replies.

Gruzin

mysql help needed

Recommended Posts

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

Share this post


Link to post
Share on other sites
If you want to overwrite, then you want to UPDATE the table

UPDATE tablename SET fieldname = 'data' WHERE fieldname = 'something'

Share this post


Link to post
Share on other sites
I don't get it....sorry. Think I'am not doing it correctly

Share this post


Link to post
Share on other sites
ok
Say you have a row in your database
FIELDS: ID | name
DATA:  1  | Jamie

If You run a query
INSERT INTO table (name) VALUES ('John')
a new Row will be added
If you run a query
UPDATE table SET name = 'john' WHERE id = 1;
THEN the name JAMIE would be changed to JOHN

INSERT = Insert a NEW row
UPDATE = Update a percific row or table

If 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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.