This question already has answers here:
PHP error: "Cannot pass parameter 2 by reference"
(2 answers)
How to resolve 'cannot pass parameter by reference' error in PHP? [duplicate]
(2 answers)
Closed 5 years ago.
When I run this code for updating my likedOne column and making it empty ("")....
$sql11 = $conn->prepare("UPDATE UserData SET likedOne=? WHERE username=?");
$sql11->bind_param('ss',"",$Username);
$Username = "netsgets";
$sql11->execute();
I get this error....
1 Fatal error: Cannot pass parameter 2 by reference in /xxx/xxx/xxx/test.php on line 36.
The line is....
$sql11->bind_param('ss',"",$Username);
What's wrong?
You need to use a variable , bind_param takes only variable not values directly.
$likedone ="";
$sql11->bind_param('ss',$likedone,$Username);
bind_param(...) expects its param parameters as references. See. That means it might change them (e.g. when they refer to a result of the query). Whenever you pass something as a reference you have to give it a name (sloppy rule of thumb, but makes it easier to explain). In a way this just tells PHP that you care about the potential modification (again simplified). You can use $emptyString = ""; $sql11->bind_param('ss',$emptyString ,$Username);
sorry for my previous answers
you could fix it up by changing
$sql11->bind_param('ss',"",$Username);
to
$variable ="";
$sql11->bind_param('ss',$variable,$Username);
because bind_param works better with variables
Related
This question already has answers here:
What is the proper way to declare variables in php?
(5 answers)
Closed 9 months ago.
The first appearance to this variable $totpro in my code is this way
$totpro = $totpro + $row['profitloss'];
I want to use it to sum all profits, however, I receive this warning message on running
Warning: Undefined variable $totpro
but if I put this code before the previous code it runs with no problems
$totpro = "0";
I don't like using that code to declare the function, it tried
String $totpro
but unexpectedly it didn't work. Now tell me how to define $totpro without to have to use $totpro = "0";
If you are summing numbers, the initial declaration should set the value to 0 (i.e. a number):
$totpro = 0;
You tried "0", which is a string. Technically this will work, but it is not the best way.
This question already has answers here:
Only Variables can be passed by reference error
(2 answers)
Closed 5 years ago.
I have a function yaz_wait() which looks like this
mixed yaz_wait ([ array &$options ] ) and as parameters, it has options as you can see in the linked documentation.
One of the options is timeout value which I want to use and edit from its default 15 seconds to some other value.
I have tried
yaz_wait(array("timeout" => 30));
but I get Fatal error: Only variables can be passed by reference...
I am not sure how exactly should I insert this parameter into this function since I have never met with such parameter type (haven't been working with php a lot).
When you have a function with & parameter in a function this means it will return a reference to the variable instead of the value.
In other words, you need to pass a variable that the function will attempt to change(or do whatever with it). Since you aren't passing a variable, you get a fatal error.
Try changing your code to:
$some_arr = array("timeout" => 30);
yaz_wait($some_arr);
This question already has answers here:
PHP: "... variables can be passed by reference" in str_replace()?
(3 answers)
Closed 7 years ago.
What is causing this error?
Fatal error: Only variables can be passed by reference in /var/www/application
/lib/testing/imageMaker/imageMaker.php on line 24
$x=str_replace ($s1,'',$s2);
$y=str_replace ($s1,'',$s2, 1 ); //Line 24
As described here: PHP Manual: str_replace
count
If passed, this will be set to the number of replacements performed.
You cannot pass the literals and rather pass the reference:
$x=str_replace ($s1,'',$s2);
$y=str_replace ($s1,'',$s2, $count);
echo $count;
This question already has an answer here:
Notice: Unknown: Skipping numeric key 1 in Unknown on line 0
(1 answer)
Closed 7 years ago.
example:
$_SESSION['10'] = 'testing';
echo $_SESSION['10'];
The above will not print out anything...i found out(after a long time of frustration) that you cannot use a string numeral as a index for the $_SESSION variable. Anyone know why?
Quote from here:
The PHP session storage mechanism was originally built around
"registering" variables, so the keys in $_SESSION must be names that
could be treated as variables in their own right.
This means that $_SESSION[10] is invalid, because $10 wouldn't be
a valid variable name, and since $foo[10] and $foo['10'] refer to
the same thing, $_SESSION['10'] is invalid as well.
This question already has answers here:
Check if url contains parameters [duplicate]
(3 answers)
How to verify if $_GET exists?
(7 answers)
Closed 9 years ago.
I have lots of PHP statements along the lines of:
$getvalue = $_GET['valueiwant'];
In some scenarios not all variables are available. So, let's say 'valueiwant' doesn't exist in the URL string, how can I return a value based on the fact it doesn't exist?
For example if 'valueiwant' can't be found set $getvalue to -1
Currently it appears the value defaults to 0 and I need to be equal less than 0 if it doesn't exist.
Any ideas?
thanks
I always use
$getvalue=isset($_GET['valueiwant'])?$_GET['valueiwant']:-1;
Use of the isset() function checks if the offset exists, and returns a boolean value indicating it's existence.
This means that you can structure an if statement around the output.