Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 3 123 LastLast
Results 1 to 15 of 31
  1. #1
    Regular Coder
    Join Date
    Jun 2010
    Posts
    163
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Getting error when everything looks right.

    For some reason, the following code is giving this error:
    Parse error: syntax error, unexpected '}' in /home/content/s/m/u/smudlys/html/ratestest.php on line 21

    This is the line after the first if statement.


    MySql version: 5.0.19

    Here is my code:
    PHP Code:
    <?php
    /// Include Admin Page Here ///
    include('inc/connect.php');

    $user $_SESSION['username'];
    $getmember mysql_query("SELECT * FROM users WHERE username='$user'");
    while (
    $row mysql_fetch_assoc($getmember))
    {
    $member $row['member'];
    }
    $getlevel mysql_query("SELECT * FROM userstats WHERE username='$user'");
    while (
    $row mysql_fetch_assoc($getlevel))
    {
    $level $row['level'];
    }

    $addrate .005;

    if(
    $member==0){
        
    $rate = ($level*$addrate+.50)
    }
    if(
    $member==1){
        
    $rate = ($level*$addrate+1)
    }

    ?>
    Last edited by Smudly; 06-17-2010 at 01:02 AM.

  • #2
    Regular Coder
    Join Date
    Jul 2009
    Posts
    187
    Thanks
    16
    Thanked 8 Times in 8 Posts
    <?php
    /// Include Admin Page Here ///
    include('inc/connect.php');

    $user = $_SESSION['username'];
    $getmember = mysql_query("SELECT * FROM users WHERE username='$user'");
    while ($row = mysql_fetch_assoc($getmember))
    {
    $member = $row['member'];
    }
    $getlevel = mysql_query("SELECT * FROM userstats WHERE username='$user'");
    while ($row = mysql_fetch_assoc($getlevel))
    {
    $level = $row['level'];
    }

    $addrate = .005;

    if($member==0){
    $rate = ($level*$addrate+.50);
    }
    if($member==1){
    $rate = ($level*$addrate+1);
    }

    ?>
    Silly mistake ^_^

  • #3
    Regular Coder
    Join Date
    Jun 2010
    Posts
    163
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Silly me

    Thanks alot.

    Just one more thing if you don't mind.

    When I try echoing out $rate, it says it is .5

    When in reality, it should be .505
    (user's level is 1, and member=0)

    How do I make it include all the decimal places?

    Thanks!

  • #4
    Regular Coder
    Join Date
    Jul 2009
    Posts
    187
    Thanks
    16
    Thanked 8 Times in 8 Posts
    Have a look at number_format() May do what you want

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    What you are getting as values for $level? I think the scope might local to just the while loops. In this case though the while loops aren't necessary.
    PHP Code:
    <?php
    /// Include Admin Page Here ///
    include('inc/connect.php');
    $user $_SESSION['username'];
    $getmember mysql_query("SELECT * FROM users WHERE username='$user'");
    $row mysql_fetch_assoc($getmember);
    $member $row['member'];
    $getlevel mysql_query("SELECT * FROM userstats WHERE username='$user'");
    $row2 mysql_fetch_assoc($getlevel);
    $level $row2['level'];

    $addrate .005;

    if(
    $member==0){
    $rate = ($level*$addrate+.50);
    }
    if(
    $member==1){
    $rate = ($level*$addrate+1);
    }
    Try that.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #6
    Regular Coder
    Join Date
    Jun 2010
    Posts
    163
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Great thanks!

    I looked over some of the stuff there, and have tried various methods but to no avail.

    Currently this is what I'm working with.

    PHP Code:
    $addrate 0.005;
    $free 0.50;
    $paying 1;


    // Free Member
    if($member==0){
        
    $rate = ($level*$addrate+$free);
        
    $rate number_format($rate3'.''');
        echo 
    $rate;

    Once it is echoed out, it shows a result of 0.500

    For some reason it isn't 0.505 as expected.

    Anyone have another method of fixing this?

  • #7
    Regular Coder
    Join Date
    Jul 2009
    Posts
    187
    Thanks
    16
    Thanked 8 Times in 8 Posts
    When you get 0.500 what value is $level? Try doing this:

    PHP Code:
    <?php  echo 'Rate:'$rate.'<br> Level:'$level?>
    where you currently have
    PHP Code:
    <?php echo $rate?>

  • Users who have thanked Jazz914 for this post:

    Smudly (06-17-2010)

  • #8
    Regular Coder
    Join Date
    Jun 2010
    Posts
    163
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Typing that in gives the following result:

    Rate:0.500
    . Level:

    EDIT:

    I saw that you re-edited your post, so I double checked and placed it where you wanted me to.

    here is the result:

    Rate:0.500
    . Level:

    Here is what my table looks like:
    Code:
    id  	int(11)   	No   	    	 
    username 	varchar(25) 	No  	  	 
    level 	int(2) 	No  	  	 
    exp 	int(6) 	No  	  	 
    credits 	decimal(9,3) 	No  	  	 
    todaysurfed 	int(4) 	No  	  	 
    totalsurfed 	int(11) 	No  	  	 
    timesurfed 	time 	No  	  	 
    lastsurfed 	date 	No
    Last edited by Smudly; 06-17-2010 at 01:52 AM.

  • #9
    Regular Coder
    Join Date
    Jul 2009
    Posts
    187
    Thanks
    16
    Thanked 8 Times in 8 Posts
    This shows level isn't being defined properly, or has no value being assigned to it

    Check what value the user has in the mysql table.

  • #10
    Regular Coder
    Join Date
    Jun 2010
    Posts
    163
    Thanks
    10
    Thanked 0 Times in 0 Posts
    The value for level for the current user is "1".

  • #11
    Regular Coder
    Join Date
    Jul 2009
    Posts
    187
    Thanks
    16
    Thanked 8 Times in 8 Posts
    OOOH Lol, My mistake sorry.
    I just noticed you are whiling through a mysql fetch which isn't needed. Try doing this instead:

    PHP Code:
    <?php
    /// Include Admin Page Here ///
    include('inc/connect.php');

    $user $_SESSION['username'];
    $sql mysql_query("SELECT * FROM `userstats` WHERE `username` ='".$user."'");
    $row mysql_fetch_assoc($sql);

    $member $row['member'];
    $level  $row['level'];

    $addrate .005;

    if (
    $member == 0) {
        
    $rate = ($level*$addrate+.50);
    }

    if (
    $member==1) {
        
    $rate = ($level*$addrate+1);
    }

    echo 
    'Rate:'$rate.'<br> Level:'$level;
    ?>
    That should work.
    Last edited by Jazz914; 06-17-2010 at 02:16 AM.

  • #12
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Level is still not getting assigned a value which could mean that your query is failing. Post your current code please.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #13
    Regular Coder
    Join Date
    Jun 2010
    Posts
    163
    Thanks
    10
    Thanked 0 Times in 0 Posts
    I'm still getting the same output as before:
    Rate:0.500
    . Level:

    Here is my updated code.

    PHP Code:
    <?php

    // Include Admin Page Here ///
    include('inc/connect.php');

    $user $_SESSION['username'];

    $getmember mysql_query("SELECT * FROM users WHERE username='$user'");
    $row mysql_fetch_assoc($getmember);
    $member $row['member'];
    $getlevel mysql_query("SELECT * FROM userstats WHERE username='$user'");
    $row2 mysql_fetch_assoc($getlevel);
    $level $row2['level'];

    $addrate 0.005;
    $free 0.50;
    $paying 1;

    // Free Member
    if($member==0){
        
    $rate = ($level*$addrate+$free);
        
    $rate number_format($rate3'.''');
        echo 
    'Rate:'$rate.'<br> Level:'$level.'<br />';
    }
    // Paying Member
    if($member==1){
        
    $rate = ($level*$addrate+$paying);
        echo 
    $rate;
    }

    ?>
    Thanks

  • #14
    Regular Coder
    Join Date
    Jul 2009
    Posts
    187
    Thanks
    16
    Thanked 8 Times in 8 Posts
    Can you try the code I posted? Here ^_^

    If this doesn't work I have another theory

  • #15
    Regular Coder
    Join Date
    Jun 2010
    Posts
    163
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Ahh sorry

    K i tried it as is, but same thing as before.

    Also, something I failed to mention earlier.

    I am using two separate tables for this script.

    The first called 'users':
    Code:
    id  	int(11)   	No   	    	 
    username 	varchar(25) 	No  	  	 
    email 	varchar(64) 	No  	  	 
    fname 	varchar(25) 	No  	  	 
    lname 	varchar(25) 	No  	  	 
    member 	tinyint(1) 	No  	  	 
    referrer 	varchar(25) 	No  	  	 
    joindate 	date 	No  	  	 
    password 	varchar(32) 	No  	  	 
    ip 	varchar(15) 	No
    The second called 'userstats':
    Code:
    id  	int(11)   	No   	    	 
    username 	varchar(25) 	No  	  	 
    level 	tinyint(2) 	No  	  	 
    exp 	int(6) 	No  	  	 
    credits 	decimal(9,3) 	No  	  	 
    todaysurfed 	int(4) 	No  	  	 
    totalsurfed 	int(11) 	No  	  	 
    timesurfed 	time 	No  	  	 
    lastsurfed 	date 	No
    Thanks again

    EDIT: I tried editting the following code:
    PHP Code:
    $sql mysql_query("SELECT * FROM `userstats` WHERE `username` ='".$user."'");
    $row mysql_fetch_assoc($sql);

    $member $row['member'];
    $level  $row['level']; 
    Changed it to this:
    PHP Code:
    $sql mysql_query("SELECT * FROM `userstats` WHERE `username`='".$user."'");
    $row mysql_fetch_assoc($sql);
    $level  $row['level'];

    $sql1 mysql_query("SELECT * FROM `users` WHERE `username`='".$user."'");
    $row1 mysql_fetch_assoc($sql1);
    $member $row['member']; 
    Only difference is it echoed out like:
    Rate:0.5
    Level:
    Last edited by Smudly; 06-17-2010 at 02:25 AM.


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •