Jump to content

Need help for php and mysql :)

- - - - -

  • Please log in to reply
9 replies to this topic

#1
portosbg

portosbg

    Newbie

  • Members
  • PipPip
  • 12 posts
Hello,
I'm new in the forum and in php .I have started to do experiments with PHP. Now i have a problem that I can not figure out how to slove it.On my webpage I have login form and i wanna make page ​​for each user- where they will have avatar, name and link with their names.This link will gives points- when someone click on it the user will recive 1 point. This page must be visible to all because the user will recive point after each click.
If you could give me the finished code will grateful to you.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
What do you have so far?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
Hello portosbg, before learning how to actually write the code you can visualize what is needed.

The database for example can contain the following fields:
id, username, password, avatar, points
id could be automatically assigned to new users by MySQL, loginname (or just username if you wish) could hold their displayed name, avatar can hold a link to their avatar image (i.e. /images/avatar2043.png) and however you wish to make this.

Assuming you have made the signup form to put their information in the database, and that the table was already created before that to hold the data you could pull their data out of the actual address. Imagine the address is this:

page.php?user=john (or id=2)
You could access their ID from $_GET['user'] or $_GET['id'].

if( is_int($_GET['id']) ) {
  $id = $_GET['id'];
  ...
}
And run the appropriate queries, i.e.
SELECT id, username, avatar, points FROM users WHERE id = $id
You can then extract the data with mysql_fetch_assoc and display the unique information based on their database record (or error if not exists)

You could also run a query after that to update their points if the user exists, simply something such as:
UPDATE users SET points = points + 1 WHERE id = $id

Feel free to read appropriate tutorials on how to connect with the database, and see what you can come up with.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#4
portosbg

portosbg

    Newbie

  • Members
  • PipPip
  • 12 posts
10X man .Can you tell me how to make url link with $_GET value ?

Edited by portosbg, 19 June 2011 - 04:59 AM.


#5
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
Each parameter will automatically populate the $_GET superglobal array. For example, foo=2&baz=a will populate both $_GET['foo'] and $_GET['baz'] in your code. You must check if they exist however and throw an error if they do not, so that you do not accidentally run the code if they are not supplied.

You must also verify the data within is correct, you would not want the user manually changing the parameters to something malicious if you were to rely on them for database actions.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#6
portosbg

portosbg

    Newbie

  • Members
  • PipPip
  • 12 posts
Hi again .I made what i wanna 10x. Now appear new problem -how can make to vote once a day from ip

#7
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#
mark a vote in a table with voting user, voted item and timestamp. if it's 24 hours later than the timestamp, let them vote again and update the timestamp, otherwise don't let them vote.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#8
portosbg

portosbg

    Newbie

  • Members
  • PipPip
  • 12 posts
Can you give code pls

#9
liamzebedee

liamzebedee

    Programmer

  • Members
  • PipPipPipPip
  • 129 posts
Also you could make use of a .HTACCESS rewrite to make the URL's more user friendly. For example you could rewrite the URL http://site.com/user/steve to http://site.com/user.php?name=steve using this code in your .HTACCESS file-
Options +FollowSymlinks

RewriteEngine On

RewriteRule ^user/(.*) user.php?name=$1


#10
portosbg

portosbg

    Newbie

  • Members
  • PipPip
  • 12 posts
10x :cool:




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users