Jump to content


Photo

mysql help needed


  • Please log in to reply
4 replies to this topic

#1 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 04 August 2006 - 01:42 PM

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:

<?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);
?>


Thanks for help
I don't need your script, I'll try to write it myself

#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 04 August 2006 - 01:47 PM

If you want to overwrite, then you want to UPDATE the table

UPDATE tablename SET fieldname = 'data' WHERE fieldname = 'something'
Tell me the problem, I will try tell you the solution

#3 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 04 August 2006 - 01:53 PM

I don't get it....sorry. Think I'am not doing it correctly
I don't need your script, I'll try to write it myself

#4 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 04 August 2006 - 02:00 PM

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


Tell me the problem, I will try tell you the solution

#5 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 04 August 2006 - 02:19 PM

ok, thanks, I'll try:)
I don't need your script, I'll try to write it myself




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users