Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

PLEASE HELP! My php script is broken and I can't figure out whats wrong!

mysqli bind_param

  • Please log in to reply
3 replies to this topic

#1 scottkohlert

scottkohlert

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 06 August 2011 - 08:48 PM

Here is the script:

function redeem() {
        

            $case = $_POST["case"]; 
			$name = $_POST["name"]; 
			$profession = $_POST["profession"];
			$city = $_POST["city"];
			$country = $_POST["country"];
			$totalpercent = $_POST["totalpercent"];
			$pretest = $_POST["pretest"];
			$posttest = $_POST["posttest"];
			$investigationspercent = $_POST["investigationspercent"];
			$timesreset = $_POST["timesreset"];
			$creditsspent = $_POST["creditsspent"];
			$timescompleted = $_POST["timescompleted"];
			
			//Add the information to the new_card_history table that keeps track of transactions
           	$stmt = $this->db->prepare("INSERT INTO learnent_cases_leaderboard (case, name, profession, city, country, totalpercent, pretest, posttest, investigationspercent, creditsspent, timescompleted, timesreset, timestamp) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)");
			
			$stmt->bind_param("sssssiiiiiii", $case, $name, $profession, $city, $country, $totalpercent, $pretest, $posttest, $investigationspercent, $creditsspent, $timescompleted, $timesreset); //the quotations specify the type of variable;
			//See http://php.net/manual/en/mysqli-stmt.bind-param.php for more information on bind_param
            $stmt->execute();
            $stmt->close();
			
			
      
            $result = array(
                
				
            );
            sendResponse(200, json_encode($result));
            return true;

It doesn't work. When I read the log, it says my error is: PHP Fatal error: Call to a member function bind_param() on a non-object at line 105

Line 105 is this line:

$stmt->bind_param("sssssiiiiiii", $case, $name, $profession, $city, $country, $totalpercent, $pretest, $posttest, $investigationspercent, $creditsspent, $timescompleted, $timesreset); //the quotations specify the type of variable;

Please help guys! I've gone over this 30 times, it's very similar to something I have done in the past. Thanks in advance for any help!
  • 0

#2 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 07 August 2011 - 12:05 AM

That means that your call to $this->db->prepare(...) is returning some sort of null value. Compare it against FALSE and do something like:

if( $stmt == FALSE )
    die "Yeah, the database query just failed. Or whatever.";

Moderator's Note: I moved this to the PHP development thread. The tutorial forum is for teaching, not asking for help. :)
  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#3 scottkohlert

scottkohlert

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 07 August 2011 - 07:18 AM

@dargueta

Thanks for your help.

It was late and I realized that I made a couple of mistakes. I was also using "case", which is also a keyword in MySQL. So I changed both "case" and "timestamp" to something more specific, as well as adding the comparison that you suggested. It now works great!

Thanks a million!

ps: sorry for posting in the wrong place, I was having troubles figuring out how to use the forum properly. I'll make sure it's filed correctly the next time!
  • 0

#4 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 07 August 2011 - 09:22 AM

No problem, glad I could kinda help. :)
  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'






Also tagged with one or more of these keywords: mysqli, bind_param

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download