[Resolved] [HELP] Inserting data into a MySQL table - Checking for duplicates

SpaceshipSpaceship
SpaceshipSpaceship
SpaceshipSpaceship
Watch

Swefx

Established Member
Impact
2
[HELP]Inserting data into a MySQL table - Checking for duplicates

Hi,

I've made a flash game with a highscore table. I used PHP and MySQL for this. The only thing is that if you refresh a certain page it makes another entry in the database. I want it to check to see whether there is already a entry with that name and score. Here's my code:

<?php
// set your infomation.
$dbhost='I bet';
$dbusername='you would';
$dbuserpass='like to know';
$dbname='this you hacker!';

// connect to the mysql database server.
mysql_connect ($dbhost, $dbusername, $dbuserpass);

if (!mysql_select_db($dbname)) die(mysql_error());

$score = secretinfo;
$name = notforyoureyes;

$query = "INSERT INTO highscore (gameid, name, score) VALUES('$gameid','$name','$score')";
mysql_query($query) or die(mysql_error());
echo "Highscore inserted successfully, view highscore table <a href='highscore.php?game=$gameid' target'_self'>here.</a>";
?>

Rep will be given to person modifies this code for me :]
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
the simplest solution: Do not even offer them to click here or there , just forward them to the score page,
PHP:
header("Location: http://www.example.com/"); /* Redirect browser */

/* Make sure that code below does not get executed when we redirect. */
exit;
from php.net/header
 
0
Close
It works! Cheers! B-)
 
0
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back