Page 1 of 1

sql_query

Posted: Mon Jan 17, 2005 10:39 am
by SidewinderX
ok i have a script that i built that, works on windows but not linux :?:

in the file index.php i have

Code: Select all

echo"<form method='POST' action='update.php'>";
echo"<b>Update Stats: for $player</b><br>";
echo"<input type='hidden' name='player' size='30' value='$player'>";
echo"<input type='hidden' name='person' size='30' value='$person'>";
echo"<input type='hidden' name='base_targets_destroyed' size='30' value='$base_targets_destroyed'>";
echo"<input type='hidden' name='op' value='savegame'><input type='submit' value='Update' name='B1'></form>";
then in the file update.php

Code: Select all

$player = $_POST&#1111;'player'];
$person = $_POST&#1111;'person'];
$base_targets_destroyed = $_POST&#1111;'base_targets_destroyed'];

$db = mysql_connect("localhost", "", ""); 
mysql_select_db("top50",$db);

$sql = mysql_query("UPDATE toplevels SET player='$player', person='$person', base_targets_destroyed='$base_targets_destroyed'") or die("Error: ".mysql_error());
echo"<center><b><i>Stats Updated...</i></b></center><br>";
Basically what the script does is in index.php it gets some stats and stores them as a veriable, and it has a bunch of hidden text boxes. Once the form is submited, it sends the information to update.php which receives all of the data and is suppose to update the database. But when i try tp update it gives me an error

Error: Duplicate entry '$player' for key 1
but to my knowledge i am not suppose to receive this error becuse i am UPDATING the database which replaces the old key with the new one.

And the interesting thing is that it works on windows and not linux.....

Posted: Mon Jan 17, 2005 10:46 am
by feyd
you're attempting to set multiple records to the same player, since the player column has a "unique" type attribute, it won't allow it.

Posted: Mon Jan 17, 2005 10:55 am
by SidewinderX
how can i fix it so that it throws away the old record and adds the new one?

Posted: Mon Jan 17, 2005 10:55 am
by feyd
use a WHERE clause in the query.