sql_query

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
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

sql_query

Post 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.....
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post by SidewinderX »

how can i fix it so that it throws away the old record and adds the new one?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

use a WHERE clause in the query.
Post Reply