Why can't I store a boolean in an array? I get an error when I attempt to run it. (On line line 3)
The columns being retrieved with the exception of stamp are booleans. Here's a snippet of my code.
$BoolQ = "SELECT stamp, active, latvian, russianSpeaker FROM tasktable WHERE taskID=usrid;";
$Boolr = mysqli_query($connection,$BoolQ);
$Boolrow = mysqli_fetch_array($Boolr);
Error:
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given
In the 3rd line of the code: $Boolrow = mysqli_fetch_array($BoolQ); , shouldn't you be using $Boolr as the parameter instead of $BoolQ? If that's a typo, which most probably it is, the result of mysqli_query is false, probably an issue with connection or the query.
Related
I am trying to get only one column of data from database and here is my code in php (Please take note that $prno is unique in pr table)
$prid = array_values(mysqli_fetch_array($conn->query("SELECT id from pr where pr_no = '$prno'")))[0];
However, I always get this warning below:
Warning: array_values() expects parameter 1 to be array, null given in C:\xampp\htdocs\test\listframe.php on line 28
Can anyone please help me remove the warning or could anyone have a better workaround for this?
I'm almost afraid to post this, as the top 20 questions that the auto search returns are all downvoted to oblivion. I have read through each of the questions that have already been asked, and my question seems to be different.
My query is working fine, in that, it is giving me the correct data as a response. However, I am still getting this error and I can't figure out why. Here's the code:
$acOneLowestCostQuery = "SELECT * FROM $acSupplierOne where quotePartNumber = '$acPartNumberOne' ORDER BY quoteCost ASC LIMIT 1" ;
$acOneLowestCost = mysqli_query($con, $acOneLowestCostQuery);
while ($row = mysqli_fetch_array($acOneLowestCost)) {
$acOnePartNumber = $row['quotePartNumber'];
$acOneLowestCost = $row['quoteCost'];
?>
My table outputs the correct information, but above the table is:
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, string given in ... on line 199
line 199 is
while ($row = mysqli_fetch_array($acOneLowestCost)) {
What I don't understand is that:
I copied this entire code (and just changed the variable names) from another page where's it working perfectly, (without any errors)
The code executes just fine AND returns the right data into my table
I don't understand why it's telling me I'm passing it a string - unless it's because the result of the query only gives back a SINGLE line (from the ASC LIMIT 1), and maybe you need two lines to make an array???
Would someone help me understand why this error is occurring? I'd rather fix the problem then use error reporting to not show it.
Problem is in variable naming:
$acOneLowestCost = mysqli_query($con, $acOneLowestCostQuery);
// here $acOneLowestCost is mysqli_result
while ($row = mysqli_fetch_array($acOneLowestCost)) {
$acOnePartNumber = $row['quotePartNumber'];
// and here it becomes a string which then passed to mysqli_fetch_array
$acOneLowestCost = $row['quoteCost'];
Having a strange problem with my php code when i try and insert a record into my database.
$db=sqlite_open("Architect.db");
$CustomerNo = sqlite_query($db, "SELECT MAX(CustomerNo) FROM Customer");
$row=sqlite_fetch_array($CustomerNo);
$CustomerNumber= "$row[0]";
echo "CustomerNo: " . $CustomerNumber . "<br>";
$CustomerNumberup= ($CustomerNumber + 1);
echo "CustomerNo: " . $CustomerNumberup . "<br>";
//This is the function that actually adds things to the database.
function Store($Name,$Company,$PhoneNo,$Address1,$Address2,$County,$PostCode,$CustomerNumberup){
}
//this calls the function and passes it the variables
Store($Name,$Company,$PhoneNo,$Address1,$Address2,$County,$PostCode,$CustomerNumberup)
Basically i am getting the highest customer number, adding 1 to it and then using it as the customer number for the new entry.
On the output page i have asked for it to output the customer number at several stages.
It Shows CustomerNumber as 1
It Shows CustomerNumberUp as 2
it then gives me the exact error
Warning: sqlite_query() expects parameter 1 to be resource, string given in I:\wwwroot\Year 3\Project Stuff\IP40 Website\addCustomer.php on line 52
Where linee 52 is the insert query.
I have tried allsorts to fix this, any suggestions are welcome.
Parameter 1 looks like the name to me. Customer number comes at the end.
By the way, if your app ever gets busy, you will get duplicate customer numbers with your approach. Does sqllite not have autoincrement fields?
The issue is your database name
$db=sqlite_open("Architect.db");
Does it work as intended if .db is removed?
$agent_query=mysql_query("
SELECT name FROM users WHERE id='$agent_id'
");
$get_agent_name=mysql_fetch_assoc($agent_query);
$this->session->agent=$get_agent_name['name'];
I know the mysql_fetch_assoc() expects parameter 1 to be resource, but is there a way I can get just the name without running any loop in Zend?
The php function mysql_result can be used to return a single field for a query by specifying the row and column you want returned. As there is only 1 row and column for your query (I assume), they will always be 0 and 0.
$name = mysql_result($agent_query, 0, 0);
I have a stored proc that does a geospatial query. The proc issues two sql statements but only the 2nd one does a query but unfortunately both statements produce a result set. I need the second result set which contains the results of the actual query.
The first statement sets a bounding box:
SET #bbox = 'POLYGON(($polygon))'; \n
SELECT * , AsText( location )
FROM users
WHERE Intersects( location, GeomFromText( #bbox ) ) [snipped for brevity]
If I run the above in phpMyAdmin, it works but I get the following message AFTER the SET command is issued and I want to throw this away:
# MySQL returned an empty result set (i.e. zero rows).
On the php side, I build the query string, calling the stored proc and on return the first thing I do is throw away the empty result set.
$query = "CALL usp_queryByPolygon('$polygon', $msg_id, $user_type)";
$result = mysqli_query($cxn, $query) or die("GEOCODE: queryPolygon - " .sql_error());
sql_free_result($result);
After throwing away the result set I now need the results of the query and this is what I have done:
$result = sql_next_result();
The problem is when I try to use this second result set as in:
if(mysqli_num_rows($result) > 0)
I get errors:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given
in /blah/blah/module.php on line 96
To complicate things, all of the above is in a loop and there could be dozens or 100's of polygons to search.
So the question is this: what is the proper way to get that 2nd result set?
You'd better be accurate of what functions you execute. sql_next_result() is no standard PHP function, nor is it in MySQLi which you seem to use. If it's some kind of database class, please just show the methods that class uses. Nobody here can but quess what sql_next_result() does.
Assuming you're talking about mysqli_next_result(), that indeed returns a boolean, you need to call mysqli_use_result() after that in order to retreive the next result set.
Found out the two statements: SET #bbox and SELECT can be executed sequentially so mysqli and the two results are just fodder that don't need to be dealt with.