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.
Related
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 4 years ago.
Improve this question
I am using Laravel and just trying to assign one element to an array. But I can't do this, cause I am getting "Undefined offset: 0" error. But here is the thing. I can dump the desired element and clearly see a value. But I can't assign it to an array. What a heck?
Here is my code:
$string = $response->getItems()[0]->snippet->thumbnails->medium->url;
$blogger['img'] = $string;
Dumping $string gives a string.
"https://yt3.ggpht.com/a-/AJLlDp0ZDDmzdlnX9fxhDJgVuoY0T779ITk2-dKxNA=s240-mo-c-c0xffffffff-rj-k-no"
But assigning this $string to an array gives this:
"Undefined offset: 0"
There no value in $response->getItems()[0]
Do a var_dump on $response->getItems and you will see it is an empty array. Presumably it is an array.
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();
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 am facing some problem in my PHP function.
function pagename($id){
$query=mysql_query("select * from tbl_pages where recid='$id' and langid='$LangID'")
$rs=mysql_fetch_array($query);
$page_name=$rsp['pgname'];
print $page_name;
}
i am not getting any resutl
I saw some problems in your code
First, there is no connection string to your database, I hope you do the connection before to do the request.
Then, in your request, you try to use a variable $LangID not declared in your function, maybe you forgot to put it in your function declaration.
You put the result of your request in the $rs variable and then you try to read the $rsp variable.
You are using mysql in your code, actually it's very unsafe to use it, it's very recommended to use mysqli or PDO instead.
Finally, you don't return anything with your function, you are missing the return statement or maybe you just want to display the result ?
EDIT : I suggest you to write your SQL requests with uppercase, it's more readable for you and other people who read your code.
SELECT * FROM tbl_pages WHERE recid='$id' AND langid='$LangID'
There's no $LangID parameter.
$rs and $rsp are different variables in your code, you should use only one of them.
This function does not return anything, even if you get something in your print.
Check if mysql connection is already established.
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'];
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 11 months ago.
Improve this question
I'm new to SQL and am trying to get this query to work:
function loadArrayFromQuery($query) {
$result = $this->executeQuery($query);
$return = array();
while ($rows = mysqli_fetch_assoc($result)) {
$return[] = $rows;
mysql_error();
}
return $return;
}
However i get the following error:
ERROR: Unknown Punctuation String # 56
STR: ->
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'function loadArrayFromQuery($query) {
$result = $this->executeQuery($query)' at line 1
Thanks
You are currently trying to execute PHP code as an SQL query.
Unfortunately:
PHP is not SQL;
SQL is not PHP.
In case this was an accident rather than a misunderstanding, check for missing ' or " characters at the end of some string higher up your PHP code, as you may accidentally be incorporating code into a query built as a string.
You don't really give enough information in the question to say anything further; except to request, that is, that if you are asking a SQL question please post an SQL query, not PHP code. You ought to spend some time extracting the crux of the problem from the three or four technologies that you're using in your project, so that you are asking us about only one.