Jump to content

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

- - - - -

  • Please log in to reply
3 replies to this topic

#1
scottkohlert

scottkohlert

    Newbie

  • Members
  • Pip
  • 2 posts
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!

#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,722 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
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. :)
sudo rm -rf /

#3
scottkohlert

scottkohlert

    Newbie

  • Members
  • Pip
  • 2 posts
@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!

#4
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,722 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
No problem, glad I could kinda help. :)
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users