PHP MySL Database- select row to REPLACE?

  • Thread starter Thread starter sparkyreich
  • Start date Start date
S

sparkyreich

Guest
I have a database and php script that accesses it. I need to be able to tell the php script which row of the database's table to REPLACE. What I have now is:
<?php
require_once('config.php');

$username=$DBUSERNAME;
$password=$DBPASSWORD;
$database="#############";
$DB_HOST="################";

$link = mysql_connect($DB_HOST,$username,$password) or die('Connect failed: ' . mysql_error());

$name = mysql_real_escape_string($_GET['name']);
$comment = mysql_real_escape_string($_GET['comment']);


$query = "REPLACE dream (name, comment) values('$name', '$comment')";

$db_selected = mysql_select_db($database, $link) or die('select_db failed: ' . mysql_error());

$result = mysql_query($query) or die('Query failed: ' . mysql_error());
mysql_close();
?>


This code makes one table and replaces it every time the script is run. I want lets say one of 10 rows to be replaced (rows have an id), how would I do this? Thanks!
 
Use the update mysql function. Example:
<?php
$update = mysql_query("UPDATE dream SET name='$name', comment='$comment' WHERE ID='$wherever'");
if ($update)
{
echo 'update successful!';
}
?>
 
Back
Top