PHP - MySQL Problem.

Discussion in 'PHP' started by Blackmirth, Sep 30, 2007.

  1. #1
    Hello.
    I have been trying to create a script that, if a correct answer is posted to the page, points are added to a user's profile. Also, it should add a number to a field, and does a strstr on the feild, so that the user cannot just re-post the answer and gain more points.
    I know that this code adds points properly, but the rest I am stuck with.
    Could you check out the syntax for me? And help me to see what the problem is.


    <?php
    
            if (isset($_POST['answer'])){
    
                if ($_POST['answer'] == 'answer to question'){
    	
    			$con = mysql_connect("XXXXXXXXXXXXXXXXX");
    					if (!$con){
    						die('Could not connect: ' . mysql_error());
      						}
    
    
    			mysql_select_db("b13_980789_db", $con);
    
    			$username = $_SESSION['username'];
    
    			$isitdone = mysql_query("SELECT * FROM basic WHERE username = '$username'");
    
    				if((strstr($isitdone, '1')) === FALSE){			
    
    					mysql_query("UPDATE `b13_980789_db`.`users` SET `points` = points+3 WHERE `users`.`username` = '$username';
    
    					UPDATE `b13_980789_db`.`users` SET `basic` = basic + '1' WHERE `users`.`username` = '$username'");
    
    					echo "Congratulations.";
    
    					}
    
    				else{
    
    					}
    
    		mysql_close($con);
    
                        }
    
    
            }
    
    ?>
    Code (markup):

     
    Blackmirth, Sep 30, 2007 IP
  2. infernaliuns

    infernaliuns Active Member

    Messages:
    121
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #2
    Maybe missing a session_start() on begin of page!!!
     
    infernaliuns, Sep 30, 2007 IP
  3. nvm3media

    nvm3media Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Did you fix this?
     
    nvm3media, Oct 1, 2007 IP
  4. Blackmirth

    Blackmirth Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I have a seesion start on the page, yes.
    And no, I have not fixed this yet.

    I think perhaps that it is a problem with the fact that $isitdone is a MySQL query, not a string?

    Thanks for your help, but I'm still not sure.
     
    Blackmirth, Oct 1, 2007 IP
  5. kendo1979

    kendo1979 Peon

    Messages:
    208
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    since i don't know what your table layout

    the should be a column / inidividual table which record the questions that have been answered corectly.

    query that table / column, compare the result of the query with the posted answer then log it up if it is different.

    you are on the right direction, isitdone is a mysql query. you should compare to the query result and not the query.
     
    kendo1979, Oct 2, 2007 IP