martinjamesroberts Posted February 4, 2011 Share Posted February 4, 2011 Hello there, I have some code here which sends a number of variables from flash to SQL... I would simply like to add the functionality to overwrite records which have the same 'name' or 'pseudo'... can anyone help me please ? Thanks in advance Martin <?php $pseudo=$_POST['var1']; $score=$_POST['var2']; $table = $_POST['tab']; $dategame = $_POST['tempjoueur']; //$micro = microtime(); //$dategame = time()."".substr($micro, 2, 6); $_COOKIE['User'] = $_SERVER['REMOTE_ADDR']; $envoie = InsertDatas($table, "name, score, dategame", "'".$pseudo."','".$score."','".$dategame."'"); if ($envoie) { print_r("OK, $pseudo, $score, $dategame,$ipclient"); } else { echo "BAD, $pseudo, $score, $dategame,$ipclient"; } ?> Link to comment https://forums.phpfreaks.com/topic/226666-overwrite-sql-entry/ Share on other sites More sharing options...
litebearer Posted February 4, 2011 Share Posted February 4, 2011 To 'overwrite' a specific record use UPDATE and WHERE somedatabasefield = '$somevariable' Link to comment https://forums.phpfreaks.com/topic/226666-overwrite-sql-entry/#findComment-1169783 Share on other sites More sharing options...
martinjamesroberts Posted February 4, 2011 Author Share Posted February 4, 2011 Yes like this ? $query = "UPDATE entries SET entry_name=`$entry` WHERE name=$pseudo"; Thing is, I know next to nothing about php, how do I call $query ? or can I put it into $envoie ? Link to comment https://forums.phpfreaks.com/topic/226666-overwrite-sql-entry/#findComment-1169786 Share on other sites More sharing options...
litebearer Posted February 4, 2011 Share Posted February 4, 2011 1. yes 2. yes it is a query and you then need to 'execute' the query Link to comment https://forums.phpfreaks.com/topic/226666-overwrite-sql-entry/#findComment-1169789 Share on other sites More sharing options...
martinjamesroberts Posted February 4, 2011 Author Share Posted February 4, 2011 Thanks, how do I do that ? Is it like actionscript and I just run $query or do I have to feed it variables ? Link to comment https://forums.phpfreaks.com/topic/226666-overwrite-sql-entry/#findComment-1169790 Share on other sites More sharing options...
martinjamesroberts Posted February 4, 2011 Author Share Posted February 4, 2011 or is it like this mysql_query($query); Link to comment https://forums.phpfreaks.com/topic/226666-overwrite-sql-entry/#findComment-1169791 Share on other sites More sharing options...
martinjamesroberts Posted February 4, 2011 Author Share Posted February 4, 2011 <?php $pseudo=$_POST['var1']; $score=$_POST['var2']; $table = $_POST['tab']; $dategame = $_POST['tempjoueur']; $query = "UPDATE entries SET score=`$score` WHERE name=$pseudo"; mysql_query($query); $_COOKIE['User'] = $_SERVER['REMOTE_ADDR']; $envoie = InsertDatas($table, "name, score, dategame", "'".$pseudo."','".$score."','".$dategame."'"); if ($envoie) { print_r("OK, $pseudo, $score, $dategame,$ipclient"); } else { echo "BAD, $pseudo, $score, $dategame,$ipclient"; } ?> Link to comment https://forums.phpfreaks.com/topic/226666-overwrite-sql-entry/#findComment-1169799 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.