Jump to content

mysql help needed


Gruzin

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
Link to comment
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.