Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
simple rank script not working
Old 12-28-2010, 06:24 AM simple rank script not working
Skilled Talker

Posts: 77
Name: adam
Location: UK
Trades: 0
Hi I am working on a ranking script where users can rank each other by using 2 forms. one for voting up, one for voting down.

HTML Code:
                  <form id="form1" name="form1" method="post" action="userprofile.php?up=true">
                    <label>
                    <input type="hidden" name="up" value="1">
                      <input type="submit" name="button" id="button" value="Vote Up" />
                    </label>
                  </form>
                  <form id="form2" name="form2" method="post" action="userprofile.php?down=true">
                    <label>
                    <input type="hidden" name="down" value="1">
                      <input type="submit" name="button3" id="button3" value="Vote Down" />
                    </label>
                  </form>
But I am getting alot of errors, which arent normally there if the ranking script wasnt here. such as

Notice: Undefined variable: name in C:\wamp\www\prototype4\userprofile.php on line 111

Notice: Undefined variable: location in C:\wamp\www\prototype4\userprofile.php on line 117

I have these on various different lines

The actual ranking script ( its not fully complete ) but I was expecting the create numbers to be shown when echoed and no errors.

the GET["id"] is used because on a previous page all id's are drawn into a url then a user can click a user and will display the profile, this is where the ranking script is.

PHP Code:
$useridvar $_GET["id"];

if (
$_GET["up"]=="true")
                {
                    
$sql="SELECT * FROM `numbers` WHERE `id` = '".$useridvar."'";
                    
$result=mysql_query($sql);
                    if (!
$result) die('Invalid query: ' mysql_error());
                        while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
                        {
                            
$karma $row["rank"];
                        }
                    
                    
$karma $karma $_POST['up'];
                    echo 
$karma;
                    
                    
$_GET["up"]="false";    
                }
if (
$_GET["down"]=="true")
                {
                    
                    
$_GET["down"]="false";
                } 
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
mintuz is offline
Reply With Quote
View Public Profile Visit mintuz's homepage!
 
 
Register now for full access!
Old 12-28-2010, 06:56 AM Re: simple rank script not working
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Notices are not errors. A script can function perfectly well while still generating notices (and to a lesser degree warnings). That being said, undefined variable notices are caused when you reference a variable that hasn't been set.

I'm not seeing either of the variables (name and location) in the notices in your code so I can't give you a specific reason why this is occurring.

A couple of things not related to your question:
1. You are wide open for sql injections.
2. Should you be using get instead of post on this line?:
PHP Code:
$karma $karma $_POST['up']; 
3. Why are you setting values in the $_GET array? There is no reason why you can't do this, and maybe it's because I'm looking at it out of context, but it seems like an odd thing to do. $_GET should only contain user input and I normally try not to modify it directly.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 12-28-2010, 10:28 AM Re: simple rank script not working
Skilled Talker

Posts: 77
Name: adam
Location: UK
Trades: 0
I cant see why I am open for SQL injection, there isnt actually any user input and I was using GET because I wanted one page called userprofile.php but could be used for many users. so userprofile.php?id=1 would be like 1 user and id=2 would be another user. but I then wanted the id to be used to allow other users viewing that profile to vote for that user. if that makes sense.

Also the errors only occur once the form has been submitted. then like 12 errors are displayed all about nonindexed var etc.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by mintuz; 12-28-2010 at 10:29 AM..
mintuz is offline
Reply With Quote
View Public Profile Visit mintuz's homepage!
 
Old 12-28-2010, 10:37 AM Re: simple rank script not working
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
I cant see why I am open for SQL injection,
You obviously don't understand what SQL injection is then.

Quote:
there isnt actually any user input
People can easily edit the URL to include a different query
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-28-2010, 10:42 AM Re: simple rank script not working
Skilled Talker

Posts: 77
Name: adam
Location: UK
Trades: 0
figured out why the SQL injection was an issue had to do mysql_real_escape_string on the useridvar because could change in URL bar. but what can I do to sort the ranking script out.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
mintuz is offline
Reply With Quote
View Public Profile Visit mintuz's homepage!
 
Reply     « Reply to simple rank script not working
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.26784 seconds with 12 queries