/    Sign up×
Community /Pin to ProfileBookmark

Quiz high score table

Hi everyone,

I trying to create a high score table at the end of the quiz.

I want it so it will go from high to low

I have created a database.

This is the script that i have used so far but i guess that there is alot missing.

?php

$dbhost = “localhost”;
$dbname = “********“;
$dbuser = “*
**
*****“;
$dbpass = “*
**
*****”;

mysql_connect ($gbhost,$dbuser,$dbpass)or die(“Could not connect:”.mysql_error());
mysql_select_db($dbname)or die(mysql_error());

$username = $_POST[‘name’];
$score = $_
POST[‘score’];

$result=mysql_query(‘SELECT * FROM `adults easy` ORDER BY `score`‘);
?>

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@MrNobodyFeb 19.2008 — The first step is to change this:

$result=mysql_query('SELECT * FROM adults easy ORDER BY score');

to this:

$result=mysql_query('SELECT * FROM adults easy ORDER BY score DESC;');
Copy linkTweet thisAlerts:
@tecmeisterauthorFeb 19.2008 — What would i do next?

I would like it so that it saves the score on that page.

Is the script that i have done wrong.
Copy linkTweet thisAlerts:
@MrNobodyFeb 19.2008 — I would like it so that it saves the score on that page.[/QUOTE]
The simplistic answer:
[code=php]$username = $_POST['name'];
$score = $_POST['score'];

if (!$result=mysql_query("SELECT * FROM adults easy WHERE user = '{$username}';")){
$result=mysql_query("INSERT into adults easy Values ('{$username}', {$score});");
}else{
$result=mysql_query("UPDATE adults easy SET score = {$score} WHERE user = '{$username}';");
}[/code]

But there are all kinds of questions not answered here. Most important:

Do you know how to protect yourself from SQL injection?

http://www.webdeveloper.com/forum/showthread.php?t=173919
Copy linkTweet thisAlerts:
@tecmeisterauthorFeb 19.2008 — Thanks for the help.

On the database it is displaying nothing.

What would be the full code so it would send me the info to the database and display the score table on the page.

tecmeister
Copy linkTweet thisAlerts:
@MrNobodyFeb 19.2008 — If you want full code, perhaps you should hire someone to do that.
Copy linkTweet thisAlerts:
@tecmeisterauthorFeb 19.2008 — I want to learn how to do it.

If i have the full code then i will be able to learn it.
Copy linkTweet thisAlerts:
@MrNobodyFeb 19.2008 — Sites like this one are for visitors to help visitors with the problems they run into as they are developing their own code. Generally, such visitors don't like writing a bunch of free code for someone else. You could do what I did (five years ago) to learn PHP. Just read the PHP Manual from beginning to end and keep experimenting until you get it right. Then, if I hit a particular problem I couldn't solve, I'd ask that question on a site like this one. Other visitors don't mind debugging your code for you and/or making small suggestions for new code. They just don't like to do it all for you up front.
×

Success!

Help @tecmeister spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...