oliverj777 Posted June 12, 2011 Share Posted June 12, 2011 Hello, I have an SQL table called 'highscores' and I want to find a field called 'player' which matches - $PlayerToChangeScore, and then to replace 'score' that is associated with the player, an replace it with - $ChangeScore. $ChangeScore = $_POST["PHPnewScoreChange"]; $PlayerToChangeScore = $_POST["PHPcurrentPlayerChange"]; Hope that makes sense, thanks Link to comment https://forums.phpfreaks.com/topic/239145-replacing-data-in-sql/ Share on other sites More sharing options...
TOA Posted June 12, 2011 Share Posted June 12, 2011 If I understand you correctly, I think this is what you need UPDATE highscores SET score='$ChangeScore' WHERE player='$PlayerToChangeScore' Luck Link to comment https://forums.phpfreaks.com/topic/239145-replacing-data-in-sql/#findComment-1228685 Share on other sites More sharing options...
xyph Posted June 12, 2011 Share Posted June 12, 2011 <?php $sql = new mysqli( 'localhost', 'root', '', 'db' ); if( isset($_POST['PHPnewScoreChange']) && isset($_POST['PHPcurrentPlayerChange']) ) { $query = 'UPDATE `table` SET `highscores` = \'' . $sql->escape_string( $_POST['PHPnewScoreChange'] ) . '\' WHERE `player` = \'' . $sql->escape_string( $_POST['PHPcurrentPlayerChange'] ) . '\''; if( $sql->query( $query ) ) echo 'Score updated successfully.'; else echo 'Could not update score.'; } ?> Link to comment https://forums.phpfreaks.com/topic/239145-replacing-data-in-sql/#findComment-1228692 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.