Php > Phpmyadmin

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Wackie
Forum Newbie
Posts: 14
Joined: Sat Mar 15, 2008 6:21 am

Php > Phpmyadmin

Post 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();
?>
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

Re: Php > Phpmyadmin

Post 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'";
User avatar
Wackie
Forum Newbie
Posts: 14
Joined: Sat Mar 15, 2008 6:21 am

Re: Php > Phpmyadmin

Post by Wackie »

Thank you, that worked :D
Post Reply