Page 1 of 1

Php > Phpmyadmin

Posted: Sat Mar 15, 2008 8:47 am
by Wackie
Hi all.

Here is a question about Phpmyadmin: When I send more data to my table it just make more rows, what I want is to make the data overwrite each other, so there only is one row with the newest data. I hope you can help me.

Code: Select all

<?php
$DBhost = "localhost";
$DBuser = "root";
$DBpass = "****************";
$DBName = "example";
$table = "details";
$_x =  $_POST['Positionx'];
$_y =  $_POST['Positiony'];
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
 
@mysql_select_db("$DBName") or die("Unable to select database $DBName");
 
$sqlquery = "INSERT INTO $table VALUES('$id','$_x','$_y')";
 
$results = mysql_query($sqlquery);
 
mysql_close();
?>

Re: Php > Phpmyadmin

Posted: Sat Mar 15, 2008 9:07 am
by Chalks
Wackie wrote:Here is a question about Phpmyadmin: When I send more data to my table it just make more rows, what I want is to make the data overwrite each other, so there only is one row with the newest data. I hope you can help me.
Use UPDATE instead of INSERT:

Code: Select all

$sqlquery = "UPDATE $table SET Positionx=$_x, Positiony=$_y WHERE id = '$id'";

Re: Php > Phpmyadmin

Posted: Sun Mar 16, 2008 3:45 am
by Wackie
Thank you, that worked :D