Function bind_param() on a non-object | PHP MySQL [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I edited my code with prepared statments(I didn't used them before). I get an error
"Call to a member function bind_param() on a non-object". I googled that error and I found cause - error is caused if query has syntax error. I'm looking last 10 minutes in query and I can't find syntax error. Can somebody help me? Thanks!
// QUERY BEFORE
$_hsync_statment->bind_param("sisssss", $_hsync_ime, $_hsync_id, $_hsync_nista, $_hsync_nista, $_hsync_mail, $_hsync_datum, $_hsync_vrijeme);
if(!$_hsync_statment->execute()) $_hsync_reg_status = -1;
// POVEČAVA BROJ REGISTRIRANIH RAČUNA
$_hsync_statment = $_hsync_konekcija->prepare("UPDATE $_hsync_srv SET Clanova = ?");
$_hsync_statment->bind_param("i", $_hsync_id + 1); // THIS LINE
if(!$_hsync_statment->execute()) $_hsync_reg_status = -1;
I tried to close every statment after it gets executed. That doesn't help.

So what's wrong with
$_hsync_statment->bind_param("i", $_hsync_id + 1); // THIS LINE
The fact that $_hsync_id is a variable that holds an int. when you add 1 to int. It produces an int that's not acceptable to bind_param. bind_param expects an object. Try this:
$_hsplus = $_hsync_id + 1;
$_hsync_statment->bind_param("i", $_hsplus); // THIS LINE
So now why did I get two downvotes when the manual clealy says:
Note that mysqli_stmt_bind_param() requires parameters to be passed by
reference, whereas

The error message Call to a member function bind_param() on a non-object... means that you haven't properly instantiated the object $_hsync_statment before calling bind_params() on it.
have intiated the db connection to the $_hsync_statment
$_hsync_statment = $db->stmt_init();

Related

PHP throwing "Use of Undefined Constant" Despite Quotes in String [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I have a PHP file wherein I'm trying to set a cookie; here is the code:
<?php
ini_set('display_errors', 1);
error_reporting(~0);
$coname = ‘logged’;
$coval = ‘false’;
setcookie($coname,$coval);
?>
Logged is the name of the cookie, false is the value. Right off the bat it's throwing:
Notice: Use of undefined constant ‘logged’ - assumed '‘logged’' in (path) on line 4
Notice: Use of undefined constant ‘false’ - assumed '‘false’' in (path) on line 5
It appears to be reading these strings as constants, then. Every resource I can find recommends solving this by enclosing the string in quotes, which I've tried with both single and double quotes to no avail. If anyone knows why the error persists, it would be a huge help. Thanks!
You're using back- and forward-ticks instead of single quotation marks, so PHP is trying to interpret ‘logged’ and ‘false’ as constants, which aren't defined.
Try this instead:
<?php
ini_set('display_errors', 1);
error_reporting(~0);
$coname = 'logged';
$coval = 'false';
setcookie($coname,$coval);
?>

Fatal error: Function name must be a string whilst it shouldn't [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have stumbled over the following error in PHP:
"Fatal error: Function name must be a string in
F:\Applications\xampp\htdocs\BTB_Sandbox\uploads.php on line 15"
and I don't know what the real problem is. Here is line 15 that the error is pointing at:
$error = $_FILES(['file_upload']['error']);
I hope you could help me, because I am kind of stuck now.
You are using $_FILES as a function because of ().
That way, PHP tries to call a function named as var $_FILES value, but this value it not a string (that's the error reported), it is an array.
Obviously, in your code line you are failing to use $_FILES, the right way is:
$error = $_FILES['file_upload']['error'];

Weird PHP "Fatal error: Cannot redeclare" Error [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
My script is returning the following error...
Fatal error: Cannot redeclare connecttodatabase() (previously declared in /var/www/api/connecttodatabase.php:4) in /var/www/api/connecttodatabase.php on line 6
And the following is the connecttodatabase.php file...
<?php
function connecttodatabase()
{
$con = #mysqli_connect("localhost", "name", "password", "database");
return $con;
}
?>
I don't really understand this error because line 6 is just the closed curly bracket (})
I think the error means that it thinks I declared the function connecttodatabase() in to different spots but clearly I didn't.
As others have said in the comments, this is most likely because you have included connecttodatabase.php twice in your code, and you are certainly defining the function twice. Don't get hung up why it's line 6; line 2 would be more helpful, but line 6 is where the function definition ends, and so arguably is when the function is defined. You could have a "one a day" whole year calendar on the idiosyncrasies of PHP and have enough left over for a sequel. As others have also hinted, some basic debugging would confirm whether you are including the file more than once and also from where.
Make sure that your code uses include_once or require_once.

Undefined index Error and query not running? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am getting this error
Notice: Undefined index: maxvalid in C:\wamp\www\myproj\includes\func.php on line 26
and my code is
require("common.php");
$incquery = "select max($TabFld) as maxvalid from $TabName";
$stmt = $db->prepare($incquery);
$incresult = $stmt->execute();
$row=$stmt->fetchAll();
$maxvalid = $row['maxvalid'];
if($maxvalid <> NULL)
{
$incvalid=$row['maxvalid']+1;
}
return $incvalid;
I am using PDO to connect mysql and I never used it before. I always use mysql_connect to connect database and I cannot understand why I am getting this error.
I also debug the code and see that value is not coming in $maxvalid variable but it came when I use mysql_connect.
fetchAll returns an array of rows. Try just fetch
For future reference, if in doubt, var_dump it.

"Call to a member function .. on a non-object" [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Hi, I am following this guide and copying exactly what is posted (except the author forgot some curly brackets, and I changed passwords etc). My problem is in the register.inc.php file.
Here is the following error I receive when a user tries to register
Call to a member function prepare() on a non-object in /home/ / /includes/register.inc.php on line 48
Line 48 of the file is
$stmt = $members_mysqli->prepare($prep_stmt);
Here is the entire register.inc.php file:
http://pastebin.com/YcQ7unb0 (It's not being properly formatted on this site)
$members_mysqli is probably a typo. It was never created. You use another variable named $mysqli. Maybe that's the one you meant to use. Check your include files and make sure you actually instantiated $members_mysqli.
The "call to member function on non-object" error is thrown when you try to use an uncreated/uninstantiated variable as an object.
For example:
// create an object
$blah = new Blah();
// call a function on it
$blah->doSomething();
// no error, because $blah exists. however, if my next line is:
$blue->doSomething();
// I'd get an error because $blue was never created

Categories